MATLAB: Trouble with MATLAB Triple Integral

convolutionmatlab integraltriple integraltripleintegral

IMG_2545.JPG
I'm attempting to evaluate this integral (and equation) where 'a' and 'x' are just inputs, and x' is (x,y,z). also: x will have the form [a,b,c]. In my 'int_func' below, I have taken the dot product of the transpose and the original, to yield the ^2 power that is observable below, for example in: (X(:,1)-x).^2
The code I have so far is:
int_func = @(x,y,z) func([x,y,z]).*exp((-3/(2*a^2)).*((X(:,1)-x).^2 + (X(:,2)-y).^2 + (X(:,3)-z).^2));
val = integral3(int_func,-inf,inf,-inf,inf,-inf,inf);
disp(val * (3/(2*pi*a^2))^(3/2));
where:
X = [0, 0, 0];
a = 1;
With this code, I should be getting an answer of 0.0370, but instead I am getting 0.5556
Can someone suggest another form of evaluating this integral or spot what is wrong with what I have listed?

Best Answer

Hi,
The problem with the func([x,y,z]) approach is that there is too much expectation that [x,y,x] is 1x3. Once the integration takes over, that's not so clear. So instead just address x,y,z directly:
X = [0, 0, 0];
a = 1;
int_func = @(x,y,z) func(x,y,z).*exp((-3/(2*a^2)).*((X(1)-x).^2 + (X(2)-y).^2 + (X(3)-z).^2));
val = integral3(int_func,-inf,inf,-inf,inf,-inf,inf);
z = val * (3/(2*pi*a^2))^(3/2)
function result = func(x,y,z)
result = x.^2.*y.^2.*z.^2;
end
z = 0.0370
I also replaced X(:,1) by X(1) etc, for related reasons.
Related Question