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

Click For Summary
SUMMARY

The MATLAB function quad can yield incorrect results for certain integrals, as demonstrated by the user's experience with the integral of x*exp(-x^2/2), which returned zero instead of the expected result of one. The user successfully obtained the correct result for exp(-x^2/2) using the same bounds. The discussion highlights that the integral function is recommended for more accurate numerical integration, particularly for cases involving infinite limits.

PREREQUISITES
  • Understanding of MATLAB syntax and functions
  • Familiarity with numerical integration techniques
  • Knowledge of the properties of exponential functions
  • Experience with handling infinite limits in integrals
NEXT STEPS
  • Learn how to use the MATLAB integral function for numerical integration
  • Explore the differences between quad and integral in MATLAB
  • Study the behavior of integrals involving exponential decay
  • Investigate techniques for improving numerical integration accuracy in MATLAB
USEFUL FOR

Mathematics students, MATLAB users, and researchers involved in numerical analysis or computational mathematics will benefit from this discussion.

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:
Physics news 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.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
Replies
27
Views
4K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 10 ·
Replies
10
Views
3K
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 8 ·
Replies
8
Views
10K
  • · Replies 4 ·
Replies
4
Views
2K