Question: 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}%")

i am using jupyter notebook the code for trapezoid rule is given

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!