Please help to remove the error

조회 수: 12 (최근 30일)
Deleena Rebello
Deleena Rebello 2022년 1월 26일
답변: Cris LaPierre 2022년 1월 26일
format long
x=0:pi/100:pi/2;
y1=sin(x);
y2=x.^2-1;
plot(x,y1,'--',x,y2,'-')
fzero(inline('sin(x)-x.^2-1'),1)
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
After running this program it is showing error. I want to obtain the intersection point upto 8 decimal points using fzero function.
Error is given below.
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.

답변 (1개)

Cris LaPierre
Cris LaPierre 2022년 1월 26일
There are 2 zeros, so consider limiting the search range to your desired x range.
y1=@(x) sin(x);
y2=@(x) x.^2-1;
fplot(y1)
hold on
fplot(y2)
hold off
z = fzero(@(x) y1(x)-y2(x),[0 pi/2])
z = 1.4096

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by