infinite integration with matlab

emper picture emper · Aug 7, 2012 · Viewed 8k times · Source

I want to compute the following type of integrals in Matlab.

\int _{0}^\infty e^{-(u*u)} du

It is the integral of function e^-(u)*u and the boundaries are zero and infinity. This integral should return 1.

How can I do this in Matlab?

Answer

Rody Oldenhuis picture Rody Oldenhuis · Aug 7, 2012

And if you don't have the symbolic toolbox, or want more speed, quadgk supports infinite limits:

f = @(x) x.*exp(-x);
a = quadgk(f, 0, inf) 

a =
    1.000000000000000e+00