Matlab 中方程的二重积分

Double integral of the equation in Matlab

如何实现这个等式

在 Matlab 中,

其中:AB是 mxm 矩阵。

例如:

A = [3.45 32.54 78.2; 8.4 33.1 4.66; 68.2 9.336 33.87 ]

B = [6.45 36.54 28.24; 85.4 323.1 74.66; 98.2 93.336 38.55 ]

我的代码:

  f1 = @(A) (abs(A) ).^2;  
  f2 = @(B) (abs(B) ).^2; 
  Q = integral2( f1, 0, 1, 0, 1) * integral2(f2, 0, 1, 0, 1);

但是当我 运行 代码时我得到了错误 "Too many input arguments.".

代码中有什么问题?

澄清你的问题后,让我改变我的post。

你所追求的是对一个已经在固定网格上采样的函数进行数值积分,函数值存储在二维矩阵AB中[=14] =] 通过 M。我想您也有关联的网格点,假设它们表示为 xcyc。然后,如果您对平滑函数进行了足够精细的采样,则积分接近:

xc = linspace(0,1,M);
yc = linspace(0,1,M);
Q = trapz(xc,trapz(yc, abs(A).^2)) * trapz(xc,trapz(yc, abs(B).^2 ));

为了测试这一点,我做了一个简单的例子来评估圆的表面,即 formula

所以要用梯形方法做到这一点 r 样本 Nphi 样本 M,我们有,

r = 2;       % Pick a value for r
M = 100;     % Pick M samples for the angular coordinate from 0 to 2*pi
N = 101;     % Pick N samples for the radial coordinate from 0 to r
phic = linspace(0,2*pi,M);   % take M samples uniformly for example
rc = linspace(0,r,N);        % take N samples uniformly for example
integrand = repmat(rc,M,1);  % Make MxN matrix, phi along rows, r along columns
I = trapz(rc, trapz(phic, integrand));

所以对于 r=2 的情况,它确实给出了 4*pi.