Comments on coding: ⚫ Define the integrand as a function using a def statement. This way, it's extremely easy to use the same code for a different function. • Define your trapezoid algorithm also as a function. The function's inputs will be the function to integrate, the two limits, and the number of trapezoids. The function's output will be the estimate of the integral. Do not use any loops inside the trapezoid function. Use vector operations instead of loops. • Make your plotting routine be a function also. Make your inputs be: ■ A list of functions to plot ■ The title of the plot The function will have no return value, but will produce the plot. • Make your slope calculation also a function. Inputs would be the vectors of x and y values that you are fitting the line for. Output would be the calculated slope. 1. Consider the integral f² (x³ + 2)dx. a. Compute the exact value by hand. b. Estimate the integral using the trapazoid method for n = 1, 2, 4, 8, 16, 32, 64, 128. c. Make a plot that includes; • log of absolute true error (y axis) versus log of number of trapezoids (x axis). Make this a solid line. ⚫ log of absolute approximate error (y axis) versus log of number of trapezoids (x axis). Make this a dotted line. (Recall that approximate error is the difference between two successive approximations.) d. Calculate the slopes of the lines that you obtained in c. Explain this result in terms of the theory. (We had similar questions in the "differentiation of continuous functions" chapter.)

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter14: Numerical Methods
Section14.6: The Trapezoidal Rule
Problem 3E
icon
Related questions
Question

Please do part B-D and make sure the code is in python

Comments on coding:
⚫ Define the integrand as a function using a def statement. This way, it's extremely easy to use the same code for a different function.
• Define your trapezoid algorithm also as a function. The function's inputs will be the function to integrate, the two limits, and the number of trapezoids. The
function's output will be the estimate of the integral. Do not use any loops inside the trapezoid function. Use vector operations instead of loops.
• Make your plotting routine be a function also. Make your inputs be:
■ A list of functions to plot
■ The title of the plot
The function will have no return value, but will produce the plot.
• Make your slope calculation also a function. Inputs would be the vectors of x and y values that you are fitting the line for. Output would be the calculated
slope.
Transcribed Image Text:Comments on coding: ⚫ Define the integrand as a function using a def statement. This way, it's extremely easy to use the same code for a different function. • Define your trapezoid algorithm also as a function. The function's inputs will be the function to integrate, the two limits, and the number of trapezoids. The function's output will be the estimate of the integral. Do not use any loops inside the trapezoid function. Use vector operations instead of loops. • Make your plotting routine be a function also. Make your inputs be: ■ A list of functions to plot ■ The title of the plot The function will have no return value, but will produce the plot. • Make your slope calculation also a function. Inputs would be the vectors of x and y values that you are fitting the line for. Output would be the calculated slope.
1. Consider the integral f² (x³ + 2)dx.
a. Compute the exact value by hand.
b. Estimate the integral using the trapazoid method for n = 1, 2, 4, 8, 16, 32, 64, 128.
c. Make a plot that includes;
•
log of absolute true error (y axis) versus log of number of trapezoids (x axis). Make this a solid line.
⚫ log of absolute approximate error (y axis) versus log of number of trapezoids (x axis). Make this a dotted line. (Recall that approximate error is the
difference between two successive approximations.)
d. Calculate the slopes of the lines that you obtained in c. Explain this result in terms of the theory. (We had similar questions in the "differentiation of
continuous functions" chapter.)
Transcribed Image Text:1. Consider the integral f² (x³ + 2)dx. a. Compute the exact value by hand. b. Estimate the integral using the trapazoid method for n = 1, 2, 4, 8, 16, 32, 64, 128. c. Make a plot that includes; • log of absolute true error (y axis) versus log of number of trapezoids (x axis). Make this a solid line. ⚫ log of absolute approximate error (y axis) versus log of number of trapezoids (x axis). Make this a dotted line. (Recall that approximate error is the difference between two successive approximations.) d. Calculate the slopes of the lines that you obtained in c. Explain this result in terms of the theory. (We had similar questions in the "differentiation of continuous functions" chapter.)
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr