USE PYTHON TO SOLVE
3) Given f(x) = e^-x
(a) Estimate the area under the graph between x = 0 and x = 2 with n = 10, 100, 1000 left endpoint rectangles.
(b) Compare your answers in part (a) to the exact area, 1 − (1 / e^2 ). What do you notice?
Python Script:
import math
def func(x):
return math.exp(-x)
N = [10, 100, 1000]
Sum = [0, 0, 0]
for i in range(len(N)):
n = N[i]
x = 0
h = 2/n
for j in range(n):
Sum[i] += func(x)*h
x += h
print('Area (n = ' + str(n) + ') =', Sum[i])
print('Exact Area =', 1 - 1/math.exp(2))
Output:
Area (n = 10) = 0.9540114845132726
Area (n = 100) = 0.873340185896101
Area (n = 1000) = 0.8655296697017035
Exact Area = 0.8646647167633873
Note: Approximation approaches the exact value as we increase the number of intervals.
Get Answers For Free
Most questions answered within 1 hours.