Trouble with MATLAB Triple Integral

1 visualización (últimos 30 días)
Matthew Worker
Matthew Worker el 25 de Jul. de 2019
Comentada: Walter Roberson el 15 de Mayo de 2020
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?
  4 comentarios
Walter Roberson
Walter Roberson el 6 de Feb. de 2020
Editada: Walter Roberson el 25 de Mzo. de 2020
The policy is not to remove questions with a valid attempt an an answer from a volunteer, unless the question is abusive or not permitted by law; on rare occassions, some intellectual property claims are also accepted.
The process here is that public Questions get free public responses from volunteers, and that both are left in public view to be of potential assistance to whomever bothers to look at the material later.
Over the years, there has been quite a number of time when people have posted a question, received a satisfactory answer, and then have wanted to close or delete the question. The volunteers tend to view such situations as-if the person who attempted to do that was effectively trying to get free private consulting. In such cases, the close / removal request is often perceived as being disrespectful of the efforts of the volunteers, who only agreed to donate their labour under the understanding that the material would be left public indefinitely for the good of everyone.
The most active volunteers encounter a lot of instances in which people expect them to give free major labour for the gain of one individual, and most of them have become pretty blunt with people that there are limits.
Walter Roberson
Walter Roberson el 15 de Mayo de 2020
You indicated that the answer did not work for you. What difficulty did you have with the proposed solution?

Iniciar sesión para comentar.

Respuestas (1)

David Goodmanson
David Goodmanson el 26 de Jul. de 2019
Editada: Walter Roberson el 25 de Mzo. de 2020
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.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by