f = @cos ; % funzione f F = @sin ; % funzione integrale F, analitica x0 = 0 ; x_max = 2*pi ; err = @(x,y) sqrt( mean( (x-y) .^ 2 ) ) ; % MATLAB integral n = 100 ; x = linspace(x0, x_max, n) ; F_int = F_integrale( f , x0 , x ) ; err_int = err( F_int , F(x) ) ; fprintf( 'MATLAB integral, n = %-8d, errore = %.2e\n' , n , err_int ) ; % Metodo Simpson n = 1000 ; [ x , F_Simpson ] = F_integrale_Simpson( f , x0 , x_max , n ) ; err_Simpson = err( F_Simpson , F(x) ) ; fprintf( 'Metodo Simpson, n = %-8d, errore = %.2e\n' , n , err_Simpson ) ; % Metodo trapezi n = 1000 ; x = linspace(x0, x_max, n) ; F_trapz = cumtrapz( x , f(x) ) ; err_trapz = err( F_trapz , F(x) ) ; fprintf( 'Metodo trapezi, n = %-8d, errore = %.2e\n' , n , err_trapz ) ;