Trouble with MATLAB Triple Integral
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Walter Roberson
2020년 2월 6일
편집: Walter Roberson
2020년 3월 25일
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
2020년 5월 15일
You indicated that the answer did not work for you. What difficulty did you have with the proposed solution?
답변 (1개)
David Goodmanson
2019년 7월 26일
편집: Walter Roberson
2020년 3월 25일
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.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!