Integrali Multipli
Transcript
Integrali Multipli
Contents • • • • • • • • Integrali Doppi Formule di riduzione per integrali doppi Integrali doppi su domini generici Disegno di insiemi nel piano Integrali Tripli Integrali Tripli su domini generici Grafico di regioni solide APPENDICE B: Metodo di Simpson 1D clear all close all %%%%%%%%%%%%%%%%%%%%%%%% %%%INTEGRALI MULTIPLI%%% %%%%%%%%%%%%%%%%%%%%%%%% Integrali Doppi %Somme di Riemann figure(1) % estremi di integrazione a=0; b=pi/2; c=a; d=b; %passo di integrazione N=50; M=N; dx=(b-a)/N; dy=(d-c)/M; [x,y]=meshgrid(a+dx/2:dx:b-dx/2,c+dy/2:dy:d-dy/2); f=sin(x+y); % plot funzione e valore dell’integrale surf(x,y,f); R=sum(sum(f))*dx*dy; R=num2str(R); text(.1,.1,1.4,[’Somma di Riemann= ’,R]); clear all 1 1 Somma di Riemann= 2.0002 0.8 0.6 0.4 0.2 0 2 1.5 2 1.5 1 1 0.5 0.5 0 0 Formule di riduzione per integrali doppi funzione handle f=@(x,y) 1./sqrt(x.^2+2*y.^2+1); %estremi di integrazione a=0; b=1; c=0; d=2; % plot funzione [x,y]=meshgrid(a:.1:b,c:.1:d); z=f(x,y); figure(2) surf(x,y,z); rotate3d; axis([a b c d 0 1]); % calcolo integrale con il comando dblquad Stima=dblquad(f,a,b,c,d); Stm=num2str(Stima); text(.2,1.5,.2,[’Dblquad= ’,Stm]); 2 % Somme di riemann di nuovo N=20; M=40; dx=(b-a)/N; dy=(d-c)/M; [x,y]=meshgrid(a+dx/2:dx:b-dx/2,c+dy/2:dy:d-dy/2); z=f(x,y); R=sum(sum(z))*dy*dx; R=num2str(R); text(.1,.1,1.4,[’Riemann= ’,R]); % Calcolo symbolico syms x y real I=int(int(f,x,0,1),y,0,2); % Non restituisce il valore in quanto la forma complicata % Utilizziamo allora la funzione double per averne una stima: I=double(I); I=num2str(I); text(.1,.5,1,[’Integrale esatto= ’,I]); clear all Warning: Explicit integral could not be found. 3 1 Riemann= 1.1598 0.8 Integrale esatto= 1.1597 0.6 0.4 0.2 Dblquad= 1.1597 0 2 1.5 1 0.8 1 0.6 0.4 0.5 0 0.2 0 Integrali doppi su domini generici f=@(x,y) (x.^2+y.^2<=1).*(3-x.^2-2*y.^2); % estremi di integrazione a=-1; b=1; c=-1; d=1; [x,y]=meshgrid(a:0.1:b,c:0.1:d); rotate3d; z=f(x,y); figure(3) surf(x,y,z); %shading flat % calcolo integrale: Stima=dblquad(f,a,b,c,d); Stm=num2str(Stima); % Riemann di nuovo N=50; M=N; dx=(b-a)/N; 4 dy=(d-c)/M; [x,y]=meshgrid(a+dx/2:dx:b-dx/2,c+dy/2:dy:d-dy/2); z=f(x,y); R=sum(sum(z))*dy*dx; R=num2str(R); text(-1,.8,3.2,[’Somma di Riemann= ’,R]); text(-1,.8,3.6,[’Integrazione numerica= ’,Stm]); text(-1,.8,4,’Valore preciso=9\pi/4=7.0686’); clear all 1 Riemann= 1.1598 0.8 Integrale esatto= 1.1597 0.6 0.4 0.2 Dblquad= 1.1597 0 2 1.5 1 0.8 1 0.6 0.4 0.5 0 0.2 0 5 Valore preciso=9π/4=7.0686 Integrazione numerica= 7.0686 3 Somma di Riemann= 7.0987 2.5 2 1.5 1 0.5 0 1 0.5 1 0.5 0 0 −0.5 −0.5 −1 −1 Disegno di insiemi nel piano figure(4) % Grafico del dominio x=linspace(-2,2); plot(x,x.^4,’r’,x,3*x-x.^3,’b’); axis([-.25 1.5 -1 4]); grid on; b=fzero(’x.^4-3*x+x.^3’,1); % calcolo simbolico dell’integrale syms x y real; A=int(int(x*y,y,x^4,3*x-x^3),x,0,b); A=num2str(double(A)); T=[’\int_D xy dx dy= ’,A]; text(.01,3.25,T); text(.7,1,’D’); set(gca,’XTick’,[0:.5:1 b]); text(-.1,3*(-.1)-(-.1)^3,’\leftarrow 3x-x^3’); text(1,1,’\leftarrow x^4’); clear all 6 4 3.5 ∫D xy dx dy= 0.80484 3 2.5 2 1.5 ← x4 D 1 0.5 0 −0.5 −1 ← 3x−x3 0 0.5 1 1.1746 Integrali Tripli %estremi di integrazione: a=0; b=2; c=-3; d=0; j=-1; k=1; % Somme di Riemann 3D N=40; M=60; P=40; dx=(b-a)/N; dy=(d-c)/M; dz=(k-j)/P; [x,y,z]=meshgrid(a+dx/2:dx:b-dx/2,c+dy/2:dy:d-dy/2,j+dz/2:dz:k-dz/2); f=x.^2+y.*z; R=sum(sum(sum(f)))*dx*dy*dz % Integrale esatto 7 syms x y z real A=int(int(int(x^2+y*z,z,j,k),y,c,d),x,a,b); A=double(A) R = 15.9975 A = 16 Integrali Tripli su domini generici clear all f=@(x,y,z) (0<=y).*(y<=1).*(0<=x).*(x<=y).*(0<=z).*(z<=x+y).*exp(x); a=0; b=1; c=0; d=1; j=0; k=2; N=50; M=50; P=100; dx=(b-a)/N; dy=(d-c)/N; dz=(k-j)/P; [x,y,z]=meshgrid(a+dx/2:dx:b-dx/2,c+dy/2:dy:d-dy/2,j+dz/2:dz:k-dz/2); Riemann=sum(sum(sum(f(x,y,z))))*dx*dy*dz syms x y z real; A=int(int(int(exp(x),z,0,x+y),0,y),0,1) % valore approssimato A=double(A) 8 pause clear all Riemann = 0.8017 A = 7/2 - exp(1) A = 0.7817 Grafico di regioni solide figure(5) y=linspace(0,1); x=0*y; z=0*y; plot3(x,y,z); hold on; grid on; x=0*y; z=y; plot3(x,y,z); x=y; z=0*y; plot3(x,y,z); x=y; z=x+y; plot3(x,y,z); x=linspace(0,1); y=1+0*x; z=0*x; plot3(x,y,z); z=x+1; plot3(x,y,z); z=linspace(0,2); x=1+0*z; y=1+0*z; plot3(x,y,z); z=linspace(1,0); x=0*z; y=1+0*z; plot3(x,y,z); xlabel(’x’) ylabel(’y’) zlabel(’z’) 9 hold off; clear all 2 z 1.5 1 0.5 0 1 1 0.8 0.5 0.6 0.4 y 0 0.2 0 x APPENDICE B: Metodo di Simpson 1D figure(6) clear all close all f=@(x) 1./(1+x.^2); a=0; b=2; n=20; h=(b-a)/n; xtutto=a+h/2:h:b-h/2; xdispari=a+h:2*h:b-h; xpari=a+2*h:2*h:b-2*h; fdispari=f(xdispari);%1./(1+xdispari.^2); fpari=f(xpari);%1./(1+xpari.^2); S20=h/3*(f(a)+4*sum(fdispari)+2*sum(fpari)+f(b)); S20=num2str(S20); Stima=sum(f(xtutto))*h; Stima=num2str(Stima); syms x real I=int(f,x,a,b); 10 I=double(I); I=num2str(I); plot(a:h:b,f(a:h:b)); text(1,0.7,[’Simpson = ’,S20]); text(1,0.8,[’Riemann = ’, Stima]); text(1,0.9,[’Esatta= ’, I]); 1 0.9 Esatta= 1.1071 0.8 Riemann = 1.1072 0.7 Simpson = 1.1071 0.6 0.5 0.4 0.3 0.2 0 0.5 1 1.5 11 2