Solving a nonlinear equation
3 次查看(过去 30 天)
显示 更早的评论
Hi. I have to solve a nonlinear equation over a range of values of a given parameter.
clc; clear;close all;
f = 0.35+0.1;
x0=f^2
r = 0.3:0.3:1.5;
zeta = 0.25;
eps = 1/6;
eqn= @(A)(r.^4.*A.^2)-(2.*r.^2.*A.^2)-(2.*r.^2.*((3.*eps.*A.^4)./4))+(3.*((3.*eps.*A.^4)./4))+(((9.*eps.^2.*A.^6)./16))+(4.*zeta.*r.^2.*A.^2);
Ans=fzero(eqn,x0);
I want the answer to give me a vector for A at the given value for r, but I can't get the code to work.
0 个评论
采纳的回答
Abolfazl Chaman Motlagh
2021-12-8
the eqn as you defined is a vector-value multi-variable function. fzero takes a scalar-value single-variable function.
so maybe you have a Writing error for eqn that make it vector value.
f = 0.35+0.1;
x0=f^2;
r = 0.3:0.3:1.5;
zeta = 0.25;
eps = 1/6;
eqn= @(A)(r.^4.*A.^2)-(2.*r.^2.*A.^2)-(2.*r.^2.*((3.*eps.*A.^4)./4))+(3.*((3.*eps.*A.^4)./4))+(((9.*eps.^2.*A.^6)./16))+(4.*zeta.*r.^2.*A.^2);
eqn(rand(1,5))
if you really want to solve the above system of equations you can use minimization functions like fminunc. or use solve for algebraic equations. ( you should change eqn for both of them)
for using fminunc the cost function should be a scalar value function. one easy method to change your eqn is taking norm from function:
eqn_= @(A)norm((r.^4.*A.^2)-(2.*r.^2.*A.^2)-(2.*r.^2.*((3.*eps.*A.^4)./4))+(3.*((3.*eps.*A.^4)./4))+(((9.*eps.^2.*A.^6)./16))+(4.*zeta.*r.^2.*A.^2));
x = fminunc(eqn_,ones(1,5));
x
Y=eqn(x)
norm(eqn(x))
1 个评论
John D'Errico
2021-12-8
编辑:John D'Errico
2021-12-8
Is there a valid reason why you posted the same answer twice? My guess is the site was moving slow, so you reposted it. I deleted the first of your identical answers.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!