Approximating Definite Integrals with Riemann Sums in Python

Author: David Manuel
In this video, it is demonstrated how to use Python to approximate a definite integral using a left endpoint Reimann sum. The presenter shows how to create a list of the left endpoint values, substitute the list of into the function, and then sum the list of the y values times the width of the rectangles.

Transcript 20

Exercises

Python Code: 
from sympy import * import numpy as np
x=symbols('x') f=exp(-x**2) a=0 b=2 n=50 dx=(b-a)/n xi=np.arange(a,b,dx) yi=[f.subs(x,i) for i in xi] Approx=np.sum(yi)*dx print('The area is approximately', Approx)

Open Python Notebook File