fzero returns complex result
2 views (last 30 days)
Show older comments
Hi,
I am running this code
f4=@(x) 0.1*0.4*(0.1*x+100)^(-0.8)-0.1*0.5*(-0.1*x+100)^(-0.8)+0.5*0.1*(0.5*x+100)^(-0.8);
fzero(f4,3)
and it only returns my NaN
Exiting fzero: aborting search for an interval containing a sign change because complex function value encountered during search. (Function value at -230.705 is -0.0043742-0.0033056i.) Check function or try again with a different starting value.
ans =
NaN
But if I change that the start poin to 200 I can get the result I want which is 225.3938. My question is how can I get the real root in general case? Before I get the solution I can't tell where is it so I can't choose a proper start point. I can't just randomly try different start points every time when I solve a function like this...
0 Comments
Answers (1)
Walter Roberson
on 26 Mar 2013
Analyze the parts of your expression. You have
(-0.1*x+100)^(-0.8)
That is going to go complex if (-0.1*x+100) < 0, which is x > 1000. Likewise analyze the other subexpressions. You will be able to establish an upper and a lower bound on when the function goes complex. Then use the interval x0 form of fzero
fzero(f4, [-31415926, 2718285]) %for example
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!