Why Does MATLAB's Quad Function Return Zero for This Integral?

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 replies · 7K views
vlajchek
Messages
1
Reaction score
0
hello,

I have a problem with the use of quad function in Matlab for numerical integration. Let me try to explain on an example. When I want to find the integral of expression exp(-x^2/2) from 0 to infinity, where for the higher bound I use some very large number:

Q = quad('exp(-x.^2./2)',0,10000000000)

I get the correct result sqrt(pi/2)=1.2533.
If I try to use the same logic for the expression x*exp(-x^2/2) for the same bounds:

Q = quad('x.*exp(-x.^2./2)',0,10000000000)

I get the result 0, although I know that correct result for this integral is 1.

What can potentialy be the problem? The thing is I am solving some more difficult integrals, without analytical solutions, but in some way similar to this example, and I always get 0 where I don't expect it using the quad function.

Thank you in advance...
 
Last edited:
on Phys.org
Nowadays, one should use the function integral instead. It is also possible to set a limit as Inf to integrate to infinity.