what's the error in nonlinear solution code?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Guidance, Navigation, and Control (GNC) finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!