fzero error ( complex function encountered)
14 views (last 30 days)
Show older comments
Xiaolu Zhu
on 4 Feb 2019
Commented: Walter Roberson
on 4 Feb 2019
Hi experts,
I am using fzero command to solve a nonlinear equation. The function part is as the following, where x is the variable to be solved, e is a variable value that passed to the function (e is a vector, I have a loop outside the nonlinear function for that), and others are parameters:
function F = solvex(x,e)
global alpha eta delta w r mu chi
F= x - w^(-alpha/(1-eta)).*(r+mu*(1-chi*exp(x))).^((alpha*eta-1)/(1-eta)).*exp(e);
end
I got the following error message under some parameter values and e values:
Exiting fzero: aborting search for an interval containing a sign change because complex function value encountered during search.
I checked some answers in mathworks and it seems that because the A^B operator in matlab.
I am looking forward to figuring out the solution. Thank you very much
0 Comments
Accepted Answer
Walter Roberson
on 4 Feb 2019
if chi is positive then 1-chi*exp(x) can become negative .Multiply by mu and the result can overwhelm r. You get a negative being raised to a power .
You need to pass fzero a range of values to search over.
6 Comments
Walter Roberson
on 4 Feb 2019
The point about the symbolic toolbox is that you can take your existing function, and pass it in a symbolic x, and the expression you get out would already incorporate all of the various values, giving you something simpler to evaluate. You could matlabFunction() the resulting symbolic expression to get a function that fzero() could work with.
You could also potentially use the symbolic toolbox to find a zero, using vpasolve(). Or you could do some analytic work to find valid ranges for the solution that you could then later process numerically.
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!