May I ask everyone to help me solve this problem
7 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Torsten
on 24 Jul 2025
Edited: Torsten
on 24 Jul 2025
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)
fun = @(z) mvnpdf(z, mu, cov_2d);
p = integral2(@(x,y)arrayfun(@(X,Y)fun([X,Y]),x,y),-2,3,3,4)
%or - most probably faster -
p = integral2(@(x,y)reshape(fun([x(:),y(:)]),size(x)),-2,3,3,4)
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!