Question: 4. Another approximation for integrals is the Trapezoid Rule: integral (a to b)f(x) dx x/2 (f(x_0) + 2f(x_1) + 2f(x_2) + + 2f(x_n2) + 2f(x_(n1))

4. Another approximation for integrals is the Trapezoid Rule:

integral (a to b)f(x) dx x/2 (f(x_0) + 2f(x_1) + 2f(x_2) + + 2f(x_n2) + 2f(x_(n1)) + f(x_n))

There is a built-in function trapz in the package scipy.integrate (refer to the Overview for importing and using this and the next command).

(a) Compute the Trapezoid approximation using n = 100 subintervals.

(b) Is the Trapezoid approximation equal to the average of the Left and Right Endpoint approximations? (c) Run the following code to illustrate the trapezoid method with 4 trapezoids (make sure you imported sympy as sp as stated in the Overview):

x=sp.symbols(x)

f=sp.exp(x/2)/x**3

sp.plot(f,(x,1,5))

xp=[1,2,3,4,5]

yp=[f.subs({x:i}) for i in xp]

import matplotlib.pyplot as plt

plt.plot(xp,yp) Notice that the trapezoid approximation is obtained by using lines to estimate f(x) on each subinterval.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!