def integrand(x, params): value = 0 for coefficient, power in params: value += coefficient *x** power return value def trapezoidal_rule(f, a, b, n): x = np.linspace (a, b, n+1) # a- Lower Limit, b-upper limit, n= number of trapezoid fx = f(x) weights = np.ones(n+1) weights[0] /= 2 weights [-1] /= 2 h (b a) n = integral h✶ np.sum(weights return integral * fx) def plot_errors (x_values, y_values, labels, linestyles, title): plt.figure(figsize=(10, 6)) for x, y, label, linestyle in zip(x_values, y_values, labels, linestyles): plt.loglog(x, y, linestyle, label-label) plt.xlabel('Number of Trapezoids (log scale)') plt.ylabel('Error (log scale)') plt.title(title) plt.legend() plt.show() def calculate_slope (x_values, y_values): coefficients = np. polyfit (np.log(x_values), np.log(y_values), 1) return coefficients[0] 4. Use Richardson extrapolation for the trapezoid rule to compute the integral for 15 ✓e dx. Compute the 1st, 2nd, 3rd, 4th, and 5th best approximation. This is analagous to finding 121, 122, 123, 124, and 125. Once again, make use of the functions that you defined in 1. There is no graph for this exercise--just output the 5 numbers.
def integrand(x, params): value = 0 for coefficient, power in params: value += coefficient *x** power return value def trapezoidal_rule(f, a, b, n): x = np.linspace (a, b, n+1) # a- Lower Limit, b-upper limit, n= number of trapezoid fx = f(x) weights = np.ones(n+1) weights[0] /= 2 weights [-1] /= 2 h (b a) n = integral h✶ np.sum(weights return integral * fx) def plot_errors (x_values, y_values, labels, linestyles, title): plt.figure(figsize=(10, 6)) for x, y, label, linestyle in zip(x_values, y_values, labels, linestyles): plt.loglog(x, y, linestyle, label-label) plt.xlabel('Number of Trapezoids (log scale)') plt.ylabel('Error (log scale)') plt.title(title) plt.legend() plt.show() def calculate_slope (x_values, y_values): coefficients = np. polyfit (np.log(x_values), np.log(y_values), 1) return coefficients[0] 4. Use Richardson extrapolation for the trapezoid rule to compute the integral for 15 ✓e dx. Compute the 1st, 2nd, 3rd, 4th, and 5th best approximation. This is analagous to finding 121, 122, 123, 124, and 125. Once again, make use of the functions that you defined in 1. There is no graph for this exercise--just output the 5 numbers.
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
Related questions
Question
PLEASE DO Q4 IN PYTHON
![def integrand(x, params):
value = 0
for coefficient, power in params:
value += coefficient *x** power
return value
def trapezoidal_rule(f, a, b, n):
x = np.linspace (a, b, n+1) # a- Lower Limit, b-upper limit, n= number of trapezoid
fx = f(x)
weights
=
np.ones(n+1)
weights[0] /= 2
weights [-1] /= 2
h (b a) n
=
integral h✶ np.sum(weights
return integral
*
fx)
def plot_errors (x_values, y_values, labels, linestyles, title):
plt.figure(figsize=(10, 6))
for x, y, label, linestyle in zip(x_values, y_values, labels, linestyles):
plt.loglog(x, y, linestyle, label-label)
plt.xlabel('Number of Trapezoids (log scale)')
plt.ylabel('Error (log scale)')
plt.title(title)
plt.legend()
plt.show()
def calculate_slope (x_values, y_values):
coefficients = np. polyfit (np.log(x_values), np.log(y_values), 1)
return coefficients[0]](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F892e817a-9b32-4eeb-b8fc-5dd7ffde6479%2Fc53ea383-bb15-44d1-96ed-ffb037dc5ec0%2Fbeox0hb_processed.png&w=3840&q=75)
Transcribed Image Text:def integrand(x, params):
value = 0
for coefficient, power in params:
value += coefficient *x** power
return value
def trapezoidal_rule(f, a, b, n):
x = np.linspace (a, b, n+1) # a- Lower Limit, b-upper limit, n= number of trapezoid
fx = f(x)
weights
=
np.ones(n+1)
weights[0] /= 2
weights [-1] /= 2
h (b a) n
=
integral h✶ np.sum(weights
return integral
*
fx)
def plot_errors (x_values, y_values, labels, linestyles, title):
plt.figure(figsize=(10, 6))
for x, y, label, linestyle in zip(x_values, y_values, labels, linestyles):
plt.loglog(x, y, linestyle, label-label)
plt.xlabel('Number of Trapezoids (log scale)')
plt.ylabel('Error (log scale)')
plt.title(title)
plt.legend()
plt.show()
def calculate_slope (x_values, y_values):
coefficients = np. polyfit (np.log(x_values), np.log(y_values), 1)
return coefficients[0]

Transcribed Image Text:4. Use Richardson extrapolation for the trapezoid rule to compute the integral for 15 ✓e
dx. Compute the 1st, 2nd, 3rd, 4th, and 5th best
approximation. This is analagous to finding 121, 122, 123, 124, and 125. Once again, make use of the functions that you defined in 1.
There is no graph for this exercise--just output the 5 numbers.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps

Recommended textbooks for you

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education