what's the error in nonlinear solution code?

조회 수: 8 (최근 30일)
Jo
Jo 2013년 10월 21일
편집: Jo 2013년 10월 21일
In false position method
-
fx=inline('exp(-2*x)-0.5')
a=input('a=');<<0
b=input('b=');<<1
fa=fx(a);
fb=fx(b);
if fa*fb>0.0
fprintf('not value in rangement');
return
elseif fa==0.0
fprintf('a is true value');
return
elseif fb==0.0
fprintf('b is true value');
return
end
epsilon=0.0001;
imax=1000;
for iter=1:imax
xc=b-fb*(a-b)/(fa-fb);
fc=fx(xc);
fprintf('\n xc f(xc) : %f , %f', 'xc', 'fc');
if abs(fc) <= epsilon
fprintf('\n value xc= %f','xc');
return
end
test = fa*fc;
if test <0.0
b=xc;
fb=fc;
elseif test > 0.0
a=xc;
fa=fc;
end
end
xc f(xc) : 120.000000 , 99.000000
xc f(xc) : 102.000000 , 99.000000
xc f(xc) : 120.000000 , 99.000000
xc f(xc) : 102.000000 , 99.000000
value xc= 120.000000
value xc= 99.000000>>
i don't understand why the result show '120' repeatedly. which means what??
thanks for you help

답변 (0개)

카테고리

Help CenterFile Exchange에서 Guidance, Navigation, and Control (GNC)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by