May I ask everyone to help me solve this problem

조회 수: 7 (최근 30일)
rte r
rte r 2025년 7월 24일
편집: Torsten 2025년 7월 24일
mu = [0, 0]; % 均值向量(行向量)
cov_2d = [1 0.5; 0.5 1]; % 协方差矩阵
% 定义二维正态分布函数
fun = @(x, y) mvnpdf([x, y], mu, cov_2d); % 直接传递 mu 作为行向量
% 使用 integral2 计算二维积分
p = integral2(fun, -2, 3, 3, 4); % x从-2到3,y从3到4
错误使用 mvnpdf (67 )
X 和 MU 的列数必须相同。
出错 jifen>@(x,y)mvnpdf([x,y],mu,cov_2d) (6 )
fun = @(x, y) mvnpdf([x, y], mu, cov_2d); % 直接传递 mu 作为行向量
出错 integral2Calc>tensor (240 )
Z = FUN(X,Y); NFE = NFE + 1;
出错 integral2Calc>integral2t (55 )
[Qsub,esub,FIRSTFUNEVAL,NFE] = tensor(thetaL,thetaR,phiB,phiT,[],[], ...
出错 integral2Calc (9 )
[q,errbnd] = integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
出错 integral2 (105 )
Q = integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);
出错 jifen (9 )
p = integral2(fun, -2, 3, 3, 4); % x从-2到3,y从3到4

답변 (1개)

Torsten
Torsten 2025년 7월 24일
편집: Torsten 2025년 7월 24일
I'm not sure, but if you want to integrate the normal distribution, use "mvncdf". integral2 can be very inaccurate when integrating probability density functions (not in the case given):
format long
mu = [0, 0];
cov_2d = [1 0.5; 0.5 1];
p = mvncdf([-2,3],[3 4],mu,cov_2d)
p =
0.001241214814729
fun = @(z) mvnpdf(z, mu, cov_2d);
p = integral2(@(x,y)arrayfun(@(X,Y)fun([X,Y]),x,y),-2,3,3,4)
p =
0.001241214813916
%or - most probably faster -
p = integral2(@(x,y)reshape(fun([x(:),y(:)]),size(x)),-2,3,3,4)
p =
0.001241214813916

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by