如何实现这个方程
在 Matlab 中,
其中:A和B是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);
但是当我运行代码时,我收到错误“输入参数太多。”.
代码有什么问题?
澄清你的问题后,让我更改我的帖子。
您所追求的是已经在固定网格上采样的函数的数值积分,并且函数值存储在矩阵
A
和 B
中,它们是 M
by M
的二维矩阵。我想您也有关联的网格点,假设它们被表示为 xc
和 yc
。然后,如果您对平滑函数进行了足够精细的采样,则积分接近:
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 ));
为了测试这一点,我做了一个简单的例子来评估圆的表面,即
因此,使用梯形方法,使用
N
的 r
样本和M
的 phi
样本,我们有,
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
。