Su uno script Esercizio1 scrivere:
1 % Esercizio1
2 % Definire la funzione 3 close all
4 clear all 5 clc
6 f = @(x) (x−1).^3.*exp(x);
7 % Definire la molteplicita' 8 m = 3; z = 1;
9 % plot della funzione 10 xx = linspace(0.5,2)';
11 figure 12 hold on 13 grid on 14 axis square
15 plot(xx,f(xx),'−')
16 % Scegliere condizione iniziale 17 x0 = 1.4;
18 % Definire la derivata
19 fp = @(x) 3*(x−1).^2.*exp(x)+(x−1).^3.*exp(x);
20 % Applicare Newton
21 tol = 10^(−7); maxiter = 100;
22 [x1,iter1] = Newton(f,fp,x0,tol,maxiter);
23 % Applicare Newton modificato
24 [x2,iter2] = NewtonMod(f,fp,x0,tol,maxiter,m);
25 % Usre bisezione
26 [x3,iter3] = bisection(f,0.5,2,tol,maxiter);
27 % Stampare a video i risultati 28 table(iter1,iter2,iter3)
29 table(x1,x2,x3) 30 ErNew = abs(z−x1);
31 ErNewMod = abs(z−x2);
32 ErBis = abs(z−x3);
33 format short e
34 table(ErNew,ErNewMod,ErBis)
1