How to | Do an Integral
The Wolfram Language contains a very powerful system of integration. It can do almost any integral that can be done in terms of standard mathematical functions.
To compute the indefinite integral
, use Integrate. The first argument is the function and the second argument is the variable:
Integrate[Sin[x], x]For the definite integral
, the second argument is a list of the form {variable,lower limit,upper limit}:
Integrate[Cos[x], {x, 0, π / 2}]To do the multiple integral
, use a mix of a variable and a range:
Integrate[x y, y, {x, 0, 1}]Alternatively, you can use Integrate twice:
Integrate[Integrate[x y, {x, 0, 1}], y]Calculating the area of a circle is a classic calculus problem. An intuitive way to approach this is the integral
, which involves substitution:
Integrate[1, {y, -1, 1}, {x, -Sqrt[1 - y ^ 2], Sqrt[1 - y ^ 2]}]Integrate gives exact answers to many improper integrals; for example,
:
Integrate[E ^ (-x ^ 2), {x, 0, ∞}]Suppose that there is no closed form for a definite integral; for example,
:
Integrate[E ^ -E ^ x ^ 2, {x, 1, ∞}]In that case, you can get an approximation with NIntegrate:
NIntegrate[E ^ (-E ^ x ^ 2), {x, 1, ∞}]If you want a numerical result from the start, it is faster to use NIntegrate than to use Integrate and follow it with N.
This compares the time taken for the two methods:
NIntegrate[E ^ (-x ^ 3), {x, 0, ∞}]//AbsoluteTimingN[Integrate[E ^ (-x ^ 3), {x, 0, ∞}]]//AbsoluteTimingRepeating the calculations is fast because of caching:
NIntegrate[E ^ (-x ^ 3), {x, 0, ∞}]//AbsoluteTimingN[Integrate[E ^ (-x ^ 3), {x, 0, ∞}]]//AbsoluteTimingNIntegrate can also compute multiple integrals:
NIntegrate[ArcTan[x y], {x, 0, 1}, {y, 0, x}]