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.)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education