Link Search Menu Expand Document (external link)

How to write and evaluate definite integrals

Description

The area under a curve can be computed using a definite integral. To compute the area above the $x$ axis and under $f(x)$, from $x=a$ to $x=b$, we write

\[\int_a^b f(x)\;dx.\]

How can we write and evaluate definite integrals using software?

Related tasks:

Using SymPy, in Python

View this solution alone.

This answer assumes you have imported SymPy as follows.

1
2
from sympy import *                   # load all math functions
init_printing( use_latex='mathjax' )  # use pretty math output

Let’s compute the area under $\sin x$ from $x=0$ to $x=\pi$.

We use the same technique as in how to write and evaluate indefinite integrals, except that we add the lower and upper bounds together with $x$, as shown below.

1
2
3
var( 'x' )
formula = sin(x)
Integral( formula, (x,0,pi) )

$\displaystyle \int\limits_{0}^{\pi} \sin{\left(x \right)}\, dx$

The above code just displays the definite integral. To evaluate it, use the integrate command.

1
integrate( formula, (x,0,pi) )

$\displaystyle 2$

Content last modified on 24 July 2023.

See a problem? Tell us or edit the source.

Topics that include this task

Opportunities

This website does not yet contain a solution for this task in any of the following software packages.

  • R
  • Excel
  • Julia

If you can contribute a solution using any of these pieces of software, see our Contributing page for how to help extend this website.