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
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
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
Related Videos (200)
Area Between Two Curves
Finding the area between two curves on an interval using a definite integral
MATH 152: Work Exercise 13
Calculating the work done pulling part of a rope to the top of a building
MATH 152: Work Exercise 8
Calculating the work done pumping water out of a tank shaped like a trough
