Fzero Exit Inf Value NaN

13 views (last 30 days)
James
James on 21 Jun 2013
I am using the fzero function and at some points get the error:
Exiting fzero: aborting search for an interval containing a sign change because NaN or Inf function value encountered during search.
(Function value at -1.3492 is Inf.)
Check function or try again with a different starting value.
ans = NaN
Which looking at the matrix of values seems to be caused by where the function goes off to infinity so cannot find f=0 value as there is not one.
How can I resolve this problem? There is a little bit of code I can add in to get around this? At the moment those points on the contour plot are just white but expect to have something there.
  3 Comments
James
James on 24 Jun 2013
update:
If I use the fzero command I get the above error that ans=NaN however if I just plot the function against the variable I can see that there is apparently a value of the variable for which the equation is zero. These two things contradict each other :s
Matt J
Matt J on 24 Jun 2013
Edited: Matt J on 24 Jun 2013
These two things contradict each other
No, not really. For example, the function
sin(x)/x-1
goes to zero as x-->0, and the plot will appear to have a root at x=0. However, MATLAB behaves as follows,
>> sin(0)/0-1
ans =
NaN

Sign in to comment.

Answers (1)

Matt J
Matt J on 21 Jun 2013
Edited: Matt J on 21 Jun 2013
as there is not one.
You seem to be saying here that the function has no root. If so, why is it a problem if the search fails? It is correctly telling you that no solution exists.
On the other hand, if you think FZERO is just searching in the wrong region, then the syntax
fzero(fun,[lb,ub])
will limit the search to the interval [lb,ub]

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!