fzero returns complex result

7 次查看(过去 30 天)
xueqi
xueqi 2013-3-26
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...

回答(1 个)

Walter Roberson
Walter Roberson 2013-3-26
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
  2 个评论
xueqi
xueqi 2013-3-26
I need to pass different parameters to functions I want to solve so I can't do these analysis. Is there any routine can solve it automatically? I tried to use Maple. And if I use 'solve' it gives me the same complex result while 'fsolve' gives me the solution which is real. So I think in matlab there must be the same alternative routine.
xueqi
xueqi 2013-3-28
Any other suggestion please?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by