Clear Filters
Clear Filters

what's the error in nonlinear solution code?

1 view (last 30 days)
Jo
Jo on 21 Oct 2013
Edited: Jo on 21 Oct 2013
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

Answers (0)

Categories

Find more on Fortran with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!