Question: Consider the trivial integral, I = 0 1 e x p ( t ) d t and compare the relative error for the trapezoid rule,
Consider the trivial integral, I=01exp(t)dt and compare the relative error for the trapezoid rule, Simpson's rule and Gauss- Legendre quadrature for single precision.
a) Write code that implements the three methods.
b) Make a log-log plot of as a function of the number of intervals N (choose reasonable values of N, e.g.?=2,10,20,40,80,jQuery22409147507518271334_1592194257542?) up to N "large enough" so you see the effects of roundoff error. Please think before doing extra work, for each method you will need different range in N.
c) Explain what you see in the plot.
d) Python actually has these functions built in as scipy.integrate.trapz, .simps, and .quadrature. Import scipy and compare your results above to the built in implementations. Do you get the same results for b&c? Figure out how to time your functions (I suggest timeit), how does your efficiency compare?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
