how to tabulate this results using fprintf?
Show older comments
clc
clear all
close all
f=@(x) ((x^3)-x-3)
Ea=100
i=0
xl=0
xu=3
fl=f(xl);
fu=f(xu);
display('i xl xu f(xl) f(xu) xr f(xr) Ea')
while Ea > 10^-3
xr=(xl+xu)/2
fr=f(xr)
if fl*fr>0
Ea=abs((xl-xr)/xl*100);
xl=xr
fprintf('%2.0f %12.5f %12.5f %12.5f %12.5f\n' ...
, i + 1, xl, xu, fl, fu, xr, fr, Ea);
else
Ea=abs((xu-xr)/xu*100);
xu=xr
end
i=i+1
fxr(i) = fr;
Eav(i) = Ea;
iv(i) = i;
end
figure
plot(iv,Eav,'-o')
xlabel('i');
ylabel('|Ea|');
title('|Ea| versus i');
figure
plot(iv,fxr,'-o')
xlabel('i');
ylabel('fxr');
title('fxr versus i');
Accepted Answer
More Answers (0)
Categories
Find more on Scripts 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!