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
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
Similar questions
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