Question about surface integration

2 ビュー (過去 30 日間)
harulab
harulab 2016 年 2 月 7 日
コメント済み: Torsten 2016 年 2 月 8 日
Hi, I'm facing a problem in calculating surface integration. I defined the function below which calculates surface integration for a discrete dataset using the trapezoidal rule.
.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 this function and the dataset attached, and then compare it to the value obtained from "trapz" which is a MATLAB built-in function.
surfInteg.m
clc
close all
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 are similar for "Pz3", but not for "Pz1". Could someone explain why this is happening?
  1 件のコメント
Torsten
Torsten 2016 年 2 月 8 日
Scale Pz1 by a factor of 1e27 and see what happens.
Best wishes
Torsten.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by