% Aufgabe 14 close all clear all % Funktionen definieren f1 = @(x) x.^20; f2 = @(x) exp(-x.^2); f3 = @(x) 1./(1+16*x.^2); f4 = @(x) abs(x).^3; % Exakte Integrale von \int_{-1}^1 f(x) dx int_f1 = 2/21; int_f2 = sqrt(pi)*erf(1); int_f3 = atan(4)/2; int_f4 = 1/2; % Genauigkeit N =30; errGauss = zeros(4,N); errCC = zeros(4,N); % for k = 1:N errGauss(1,k) =abs(int_f1 - gauss(f1,k)); errGauss(2,k) =abs(int_f2 - gauss(f2,k)); errGauss(3,k) =abs(int_f3 - gauss(f3,k)); errGauss(4,k) =abs(int_f4 - gauss(f4,k)); errCC(1,k) =abs(int_f1 - clenshaw_curtis(f1,k)); errCC(2,k) =abs(int_f2 - clenshaw_curtis(f2,k)); errCC(3,k) =abs(int_f3 - clenshaw_curtis(f3,k)); errCC(4,k) =abs(int_f4 - clenshaw_curtis(f4,k)); end x = 1:N; figure; semilogy(x,errGauss(1,:),'r*-',x,errCC(1,:),'b+-'); legend('Gauss','Clenshaw-Curtis'); grid on figure; semilogy(x,errGauss(2,:),'r*-',x,errCC(2,:),'b+-'); legend('Gauss','Clenshaw-Curtis'); grid on figure; semilogy(x,errGauss(3,:),'r*-',x,errCC(3,:),'b+-'); legend('Gauss','Clenshaw-Curtis'); grid on figure; %loglog(x,errGauss(4,:),'r*-',x,errCC(4,:),'b+-'); semilogy(x,errGauss(4,:),'r*-',x,errCC(4,:),'b+-'); legend('Gauss','Clenshaw-Curtis'); grid on