Absurd result using 'integral2' with non-"centered" functions
3 views (last 30 days)
I have been trying to compute an expression for a probability which involves four normal density functions ; those are by definition positive on all real numbers. That is, when integrating over any bounds the expression of a density function, we shouldn't get a smaller result by integrating over larger bounds.
Everything comes up to this problem : this code snippet given should yield 1 !
sigma = sqrt(6) ;
Theta = 50 ; % Replace Theta by something less than 34 and it gives 1 !
f = @(x) normpdf(x,Theta,sigma) ;
integral2(@(x,y) f(x).*f(y),-inf,inf,-inf,inf) % Integrating product of two normal probability density functions over R^2
This is not a problem with normpdf as I still observe the problem by replacing f by the litteral expression of the normal probability density function.
Am I missing something ?
Thanks for your time.
More Answers (2)
Askic V on 6 Mar 2023
Edited: Askic V on 6 Mar 2023
@Torsten already answered, please keep in mind that integral2 still performs numerical integration.
have a look at this:
sigma = sqrt(6) ;
Theta = 50 ;
g = @(x,y) (normpdf(x,Theta,sigma) .* normpdf(y,Theta,sigma));
Q2 = integral2(g,-inf,inf,-inf,inf, 'Method','iterated','AbsTol',0)
John D'Errico on 6 Mar 2023
Edited: John D'Errico on 6 Mar 2023
Why should you be surprised?
Integral and integral2 are tools that look at your function as a complete black box. A black box in this context means the code passes some numbers in, and then looks at the output. They cannot look at your code and "understand" it, parsing it, and then somehow know this is a Normal distribution involved, and to look near the mode of that normal? The code would then need to go back, and understand how the distribution is parameterized, and from that, infer where to look. The tool does not know the function has a very localised peak at one point in the domain, and where that may be.
A numerical integration tool looks at the function values it sees. If they are all zero to within a very high degree of precision EVERY where it has looked, what could you expect? A normal PDF has the property that in a moderately small region, so within plus or minus 6 or 10 sigma, it is ZERO to a fairly high tolerance.
What did you do? You passed the integration tool limits of -inf and +inf. Is there a wide range between -inf and +inf? What are the odds the integration tool should somehow know to look in a VERY relatively narrow band for something to happen?