Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i am using jupyter notebook the code for trapezoid rule is given as: # -- This is the function I want to integrate # --

i am using jupyter notebook

the code for trapezoid rule is given as:

# -- This is the function I want to integrate # -- NOTE THE SCOPE AND CONFLICT BETWEEN THE FUNCTION NAME AND VARIABLE NAME INSIDE def f(x): f=x**4-2*x+1 return f

# -- Use the trapazoidal rule to integrate f(x) from a to b # -- IMPORTANT: How does the function trapz know about the function f? def trapz(a,b): N=20 h=(b-a)/N s=0.5*f(a)+0.5*f(b) for i in range(1,N): s += f(a+i*h) I = s*h return I

# -- Use my trapazoidal rule function with the limits of integration 0->2 I = trapz(0.0,2.0)

# -- This is the true indefinite integral def intf(x) : intf=x**5/5-x**2+x return intf

# -- Evaluate the indefinite integral at the limits of integration Itrue = intf(2.0)-intf(0.0) deltaI = 100*abs(I-Itrue)/Itrue

print(f"Trapizoidal rule : {I:2.6}") print(f"The true value : {Itrue:2.6}") print(f"The percent difference is : {deltaI:1.2}%")

image text in transcribed

Extend the trapizoidal rule function I provided from the lecture notes to integrate the folowing function with Simpson's rule on 10 or more points 1= f*(?2x + 1)dx (x2 2x + 1)dx Compare your results with what you obtain from using scipy.integrate. simps with the same number of points Extend the trapizoidal rule function I provided from the lecture notes to integrate the folowing function with Simpson's rule on 10 or more points 1= f*(?2x + 1)dx (x2 2x + 1)dx Compare your results with what you obtain from using scipy.integrate. simps with the same number of points

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

What is the social discount rate

Answered: 1 week ago