How to | Do an Integral
Mathematica 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:
| In[1]:= |
| Out[1]= |
For the definite integral
, the second argument is a list of the form
:
| In[2]:= |
| Out[2]= |
To do the multiple integral
, use a mix of a variable and a range:
| In[3]:= |
| Out[3]= |
Alternatively, you can use Integrate twice:
| In[4]:= |
| Out[4]= |
Calculating the area of a circle is a classic calculus problem. An intuitive way to approach this is the integral
, which involves substitution:
| In[5]:= |
| Out[5]= |
Integrate gives exact answers to many improper integrals; for example,
:
| In[6]:= |
| Out[6]= |
Suppose that there is no closed form for a definite integral; for example,
:
| In[7]:= |
| Out[7]= |
In that case, you can get an approximation with NIntegrate:
| In[1]:= |
| Out[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:
| In[4]:= |
| Out[4]= |
| In[5]:= |
| Out[5]= |
Repeating the calculations is fast because of caching:
| In[6]:= |
| Out[6]= |
| In[7]:= |
| Out[7]= |
NIntegrate can also compute multiple integrals:
| In[8]:= |
| Out[8]= |
