the error"The function values at the interval endpoints must differ in sign" + fzero
Afficher commentaires plus anciens
Hello. I want to solve the beneath nonlinear eqn(there is only one variable) as the code below. When using fzero, I get the error as"The function values at the interval endpoints must differ in sign.". I know there is a correct root at x=3.47 (which i am looking for).... Is my coding for fzero correct?
c=0
while Error>tol
c=c+1
syms x positive
for i=1:n+1
if i==1
EE(1,1)=0;
else
EE(i,1)=(((C*l(i-1)*x)+(((tan(phi*pi/180))*x)*((rho*9.81*A(i-1)*(cos(beta(i-1))))+(EE(i-1)*(sin(beta(i-1)-(te))))))-(rho*9.81*A(i-1)*(sin(beta(i-1))))+(EE(i-1)*(cos(beta(i-1)-(te)))))/((cos(beta(i-1)-(te)))+((sin(beta(i-1)-(te)))*(tan(phi*pi/180))*x)));
end
end
eqn = (simplify((EE(n+1,1))));
fh = @(x) (eqn);% you should use matlabFunction's 'vars' option to convert the variables into a vector.
if c==1
x0=[0 5];
else
x0=k
end
[x,fval,exitflag] =fzero(fh,x0),
4 commentaires
madhan ravi
le 9 Juil 2020
x0 = 5
Pooneh Shah Malekpoor
le 9 Juil 2020
madhan ravi
le 9 Juil 2020
Or 3?
Pooneh Shah Malekpoor
le 9 Juil 2020
Réponses (1)
madhan ravi
le 9 Juil 2020
fh = @(x) matlabFunction(eqn)
5 commentaires
Pooneh Shah Malekpoor
le 9 Juil 2020
Modifié(e) : Pooneh Shah Malekpoor
le 9 Juil 2020
madhan ravi
le 9 Juil 2020
{x0} -> x0 why do you complicate things ? XD
Pooneh Shah Malekpoor
le 9 Juil 2020
madhan ravi
le 9 Juil 2020
What’s value of c?
Pooneh Shah Malekpoor
le 10 Juil 2020
Catégories
En savoir plus sur Optimization dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!