Pongo un script de ejemplo integrando una normal multivariante. He usado esta función por sencillez y porque sabemos la solución que es uno.
clc
close all
clear all
pmax=10;
t=zeros(pmax,1);
result=zeros(pmax,1);
sigma=2;
for iter=1:pmax
str = [' Iteration ', num2str(iter), ' of ',num2str(pmax)];
disp(str)
p=iter;
S=(sigma^2)*eye(p);
invS=inv(S);
detS=det(S);
%x=[x1;...; xp]
x=sym('x',[p,1]);
% x'= complex conjugate transpose
% x.'= transpose without conjugation
xT=x.';
f=exp(-0.5*xT*invS*x);
fk=f;
tstart=tic;
for k=1:p
fk=int(fk,x(k),-inf,inf);
end
t(iter)=toc(tstart);
aux=1/sqrt((2*pi)^p);
aux=aux/sqrt(detS);
aux=aux*fk;
result(iter)=aux;
end
figure
plot(result)
title('Result (Ideally always 1)')
figure
plot(t)
title('time elapsed')