MATLAB - Numerical integration

In summary, the conversation discusses a problem with using the quad function in Matlab for numerical integration. An example is given where the correct result is obtained for the integral of exp(-x^2/2) but not for x*exp(-x^2/2). The potential problem is unknown, and the suggestion is made to use the function integral instead.
  • #1
vlajchek
1
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
  • #2
Nowadays, one should use the function integral instead. It is also possible to set a limit as Inf to integrate to infinity.
 

1. What is numerical integration?

Numerical integration is a method used in mathematics and scientific computing to approximate the value of a definite integral. It involves dividing the integral into smaller sub-intervals and using numerical techniques to calculate the area under the curve.

2. What is the difference between numerical integration and analytical integration?

Numerical integration uses numerical methods to approximate the value of an integral, while analytical integration involves finding an exact solution to the integral using algebraic techniques. Numerical integration is typically used when an analytical solution is not possible or too complex to find.

3. What are the advantages of using MATLAB for numerical integration?

MATLAB has built-in functions and tools for performing numerical integration, making it a convenient and efficient tool for scientists and engineers. It also allows for easy visualization of results and the ability to test different integration methods.

4. What are the different numerical integration methods available in MATLAB?

MATLAB offers several numerical integration methods, including the Trapezoidal rule, Simpson's rule, and Gaussian quadrature. Each method has its own advantages and is suitable for different types of integrals.

5. How can I improve the accuracy of my numerical integration results in MATLAB?

To improve accuracy, you can use a smaller step size or increase the number of sub-intervals in your integration. You can also try using a more advanced integration method or adjust the tolerance settings in MATLAB's integration functions. It is also helpful to check your results using different methods to ensure consistency.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
27
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
802
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
3K
Back
Top