Answered step by step
Verified Expert Solution
Question
1 Approved Answer
HI I NEED CODE IN PYTHON LANGUAGE ONLY PYTHON DO NOT WASTE MY QUESTION THANKS I GIVE YOU THUMBS UP - Consider the approximate integration
HI I NEED CODE IN PYTHON LANGUAGE ONLY PYTHON DO NOT WASTE MY QUESTION THANKS I GIVE YOU THUMBS UP
- Consider the approximate integration of a function f(x) over the interval [0,1]. Let M be a positive integer, and let h=1/M, and xk=kh, for k=0,1,2,3,,M. Thus x0=0 and xM=1. Then one approximate integration formula is 01f(x)dxh[f(x0+2h)+f(x1+2h)+f(x2+2h)++f(xM2+2h)+f(xM1+2h)]=MP(M). This method is known as the Midpoint Rule. Another approximate integration formula is 01f(x)dx3h[f(x0)+4f(x1)+2f(x2)+4f(x3)++2f(xM2)+4f(xM1)+f(xM)]=SI(M). This method, which requires M to be even, is known as the Simpson's Rule. (a) (30%) Implement these two methods in programs, and use each of these to approximately integrate the function f(x)=sin(x) over the interval [0,1], using successively the following values of M:M=2,4,8,16,. For each of these values of M print the error, i.e., the absolute value of the difference between the approximation and the known exact value of the integral, which you can obtain analytically. Plot the results on the graphs. Make sure to represent to sufficient precision in your program! Furthermore, for each of the two methods, determine from your computations the smallest value of M for which the error is less than 107. How many function evaluations are required in each of these two cases? Can you describe the observed behavior of the error? In particular, for each of the two methods, can you say approximately how the error depends on h ? More specifically, it is known that the errors will be approximately proportional to hp, where p is an integer that depends on the method. Can you tell from the numerical results what p is for each of the two methods? Also can you explain what happens to the error when M gets "very large"? In the last part of this problem you will justify some of the previous results theoretically. Specifically: (b) (5\%) Use the internet, the calculus books or the textbook to find the upper bounds on the error of the Midpoint Rule, i.e., on 01f(x)dxMP(M) in terms of f, its derivatives and M. Use the bound to find the smallest value of M such that the error bound becomes less than 107. c) (5\%) Use the internet, the calculus books, the textbook or the Notes, p. 26\%286 to find the error bound for the Simpson Rule, i.e. the upper bounds on 01f(x)dxSI(M) in terms of f, its derivatives and M. Use the bound to find the smallest value of M such that the error bound becomes less than 107
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started