what's the error in nonlinear solution code?

2 ビュー (過去 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 Center および File ExchangeVerification, Validation, and Test についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by