MATLAB Answers


non linear equation with single root

Asked by Raman Dadwal on 15 Apr 2019
Latest activity Commented on by Raman Dadwal on 18 Apr 2019
I am trying to solve this
using fzero but my answer is NaN
is there anyway to get a real value answer for this equation

  1 Comment

on 15 Apr 2019
Your function is always positive - thus has no zero.

Sign in to comment.





1 Answer

Answer by John D'Errico
on 15 Apr 2019
Edited by John D'Errico
on 15 Apr 2019
 Accepted Answer

fzero does not find a root, cannot find it, because it has no zero crossing. That is a requirement for fzero. Effectively, there is not single root, but what looks like it might be a double root.
But is it?
syms x
y = (x-0.25).^2+((1628.1/6.08.*(720-720*x))-0.79).^2;
ans =
1.0 - 3.89e-6i
1.0 + 3.89e-6i
So no real root at all. In fact, this is just a quadratic polynomial with two complex roots.
ans =
3.7172e+10*x^2 - 7.4344e+10*x + 3.7172e+10
In general, for a function that actually had a real double root at some point, fzero is not a good choice of solver. For example, consider this function where a real root is known to exist.
fun2 = @(x) (x - 1.25).^2;
>> fzero(fun2,2)
Exiting fzero: aborting search for an interval containing a sign change
because NaN or Inf function value encountered during search.
(Function value at -1.7162e+154 is Inf.)
Check function or try again with a different starting value.
ans =
>> fzero(fun2,[0,2])
Error using fzero (line 290)
The function values at the interval endpoints must differ in sign.
As you see, fzero cannot survive here, even on this simple problem, because the function never crosses zero.
Yet fsolve works with no problem, finding a root that is within its tolerances.
[xsol,fval] = fsolve(fun2,1.5)
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
xsol =
fval =
It did not do a great job, as problems with double roots are more difficult to solve exactly in floating point arithmetic.

  1 Comment

thanks a lot !

Sign in to comment.