Matlab中方程的二重积分

问题描述 投票:0回答:1

如何实现这个方程

在 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);

但是当我运行代码时,我收到错误“输入参数太多。”.

代码有什么问题?

matlab numerical-integration
1个回答
0
投票

澄清你的问题后,让我更改我的帖子。

您所追求的是已经在固定网格上采样的函数的数值积分,并且函数值存储在矩阵

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 ));

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

因此,使用梯形方法,使用

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

© www.soinside.com 2019 - 2024. All rights reserved.