I am using MATLAB to solve the problem. I need help to add the estimate error an
ID: 3416778 • Letter: I
Question
I am using MATLAB to solve the problem.
I need help to add the estimate error and absolute error to my code.
My code is:
clear all
clc;
f=@(x) x^3 + x^2 - 3*x - 3;
a=1;b=2;TOL=10^-6;Nmax=100;
old = b;
fa = f(a);
fb = f(b);
disp (' iter (a,b) p')
for i = 1 : Nmax
p = b - fb * ( b - a ) / ( fb - fa );
fp = f(p);
if ( nargout == 0 )
end
fprintf('%2i (%2.4f,%2.4f) %2.10f ', i, [a, b], p);
if ( abs(p-old) < TOL )
if ( nargout == 1 )
y = p;
end
return
elseif ( fa * fp < 0 )
b = p;
fb = fp;
else
a = p;
fa = fp;
end
old = p;
end
Thank you
1. Consider the function f(x)-z? + r2-3-3 on the interval (1,2) that has a zero p-Va (c) The Method of False Position (2.2.4) Perform the first five iterations of the method of false position and verify that the absolute error in the third, fourth and fifth approximations satisfies the error estimate Pn-Pn-1.Explanation / Answer
Here is the modified code that prints the estimate error and absolute error :
clear all
clc;
f=@(x) x^3 + x^2 - 3*x - 3;
a=1;b=2;TOL=10^-6;Nmax=100;
old = b;
fa = f(a);
fb = f(b);
disp (' iter (a,b) p est_error abs_error')
for i = 1 : Nmax
p = b - fb * ( b - a ) / ( fb - fa );
fp = f(p);
error = p - sqrt(3);
if ( nargout == 0 )
end
fprintf('%2i (%2.4f,%2.4f) %2.10f %2.10f %2.10f ', i, [a, b], p, error, abs(error));
if ( abs(p-old) < TOL )
if ( nargout == 1 )
y = p;
end
return
elseif ( fa * fp < 0 )
b = p;
fb = fp;
else
a = p;
fa = fp;
end
old = p;
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.