calculus - Surface integration in MATLAB -
i'm facing problem in calculating surface integration. defined function below calculates surface integration discrete dataset using trapezoidal rule.
< trapz2d.m > function out = trapz2d(x,y,f) x = x(:); y = y(:); nx = length(x); ny = length(y); dx = diff(x); dy = diff(y); ds = dy*dx.'; df = (f(1:ny-1,1:nx - 1) + f(2:ny,1:nx-1) + f(1:ny-1,2:nx) + f(2:ny,2:nx))/4; out = sum(sum(ds.*df)); end
i calculated surface integration using function , dataset in link below, , compare value obtained "trapz" matlab built-in function.
< surfinteg.m > clc close clear format long load('dataset.mat') i1 = trapz(y, trapz(x,pz3,2)); i2 = trapz2d(x,y,pz3); disp([i1; i2]) >>>1.0e-12 * 0.307618158054522 - 0.000000000004792i 0.307618158054522 - 0.000000000004792i i1 = trapz(y, trapz(x,pz1,2)); i2 = trapz2d(x,y,pz1); disp([i1; i2]) >>>1.0e-27 * -0.135645057561047 + 0.013248760976931i -0.129284381233370 + 0.013497757971006i
the results similar "pz3", not "pz1". explain why happening?
Comments
Post a Comment