1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| d1 = 0.2;
d2 = 0.1;
xx = -3:d1:3;
yy = -2:d2:2;
[X, Y] = meshgrid(xx, yy);
%MyFun = @(u,v)(exp(-(u.^2 + v.^2)));
MyFun = @(u,v)(u.^2 + v.^2);
% => d'où vient cette fonction, pourquoi celle-ci?
Z = MyFun(X,Y) ;
%--- Approximative value
s = size(Z);
Ztmp = (Z(2:s(1),2:s(2)) + Z(1:s(1)-1,1:s(2)-1))/2; % Moyenne des pavés
Iapprox = sum(Ztmp(:))*d1*d2; % Approximation en escaliers
%--- Exact Value
Iexact = dblquad(MyFun,-3,3,-2,2);
%---- Compare
fprintf(' ## Approx = %f \n ## Exact = %f \n ## Error = %f \n',...
Iapprox,Iexact, abs(Iapprox - Iexact)/Iexact) |
Partager