I am trying to solve this
fun1=@(x)(x-0.25).^2+((1628.1/6.08.*(720-720*x))-0.79).^2
using fzero but my answer is NaN
is there anyway to get a real value answer for this equation
?

댓글 수: 1

Torsten
Torsten 2019년 4월 15일
Your function is always positive - thus has no zero.

댓글을 달려면 로그인하십시오.

 채택된 답변

John D'Errico
John D'Errico 2019년 4월 15일
편집: John D'Errico 2019년 4월 15일

1 개 추천

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.
fplot(fun1,[0.999,1.001])
But is it?
syms x
y = (x-0.25).^2+((1628.1/6.08.*(720-720*x))-0.79).^2;
vpa(solve(y),5)
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.
vpa(expand(y),5)
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 =
NaN
>> 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 =
1.2578
fval =
6.1035e-05
It did not do a great job, as problems with double roots are more difficult to solve exactly in floating point arithmetic.

추가 답변 (0개)

카테고리

제품

릴리스

R2018b

태그

질문:

2019년 4월 15일

댓글:

2019년 4월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by