what's the error in nonlinear solution code?

1 次查看(过去 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 中查找有关 Verification, Validation, and Test 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by