TPmatlab2 En
TPmatlab2 En
Write also a script that calls the function “bisectionall” and sketches on the same figure the
curve of f and the points (ck , f (ck )) for all k.
clear all;
clc;
f = @(x) x.^2+x.*exp(-x);
df = @(x) 2*x+exp(-x)-x.*exp(-x);
a = -2;
b = 2;
fplot(f,[a b]);
Nmax = 20;
tol = 1e-5;
r1 = lagrange(f,a,b,tol,Nmax);
r2 = bisectionall(f,a,b,tol,Nmax);
r3 = newton(f,df,x0,tol,Nmax);
r4 = secant(f,x0,x1,tol,Nmax);
disp([r1,r2(end),r3,r4]);