CMPSC/Mathematics 455Final Exam – Part IIIDue 14 December 2022At Midnight–On CanvasNo extensions, please !!!Fall 2022You are to write a MATLAB function to implement Romberg...

1 answer below »
MATLAB


CMPSC/Mathematics 455 Final Exam – Part III Due 14 December 2022 At Midnight–On Canvas No extensions, please !!! Fall 2022 You are to write a MATLAB function to implement Romberg integration with an error estimate at the end. Your romberg function should have the form [int,err,ier]=romberg(f,a,b,tol) The input variables are ˆ f–a function handle for the function to be integrated ˆ a, b– the limits of integration, i.e., you are approximating I = ∫ b a f(x)dx. ˆ tol-the error between the last two Romberg approximations. In the notation in the notes this means that |Tk(h)− Tk−1(h)| ≤ tol. and Tk(h) is accepted as the integral. For your first value of h for the Trapezoid rule, choose h = (b− a)/4. The output variables are ˆ int–The approximate integral. ˆ err– The value of Tk(h)− Tk−1(h), the error estimate. ˆ ier – You are to have a maximum of l0 levels of extrapolation, i.e., k = 10. If you reach 10 levels and |err| > tol, then ier = 1 (tolerence was not reached), otherwise ier = 0 (tolerence was reached). 1 To design this code you will need to design a function for the composite trapezoid rule, that is, for computing T0(h). You will also need a function to perform an update, that is, to compute T0(h/2) from To(h) and summing the midpoints. The matlab function sum will save you some loops for both of these functions. You should be able to accumulate the approximations with one vector that stores T0(h/2 k), T1(h/2 k−1), . . . , Tk−1(h/2), Tk(h) at a given point in the Richardson extrapolation process. Again, the maxi- mum for k is 10, and you may take advantage of that in the development on your code (e.g., you can precompute all of the powers of 4 necessary for the extrapolation steps). You should not need a two-dimensional array for this! Test your code on three functions that I will put in the subfolder Final Part Three on Canvas. They are pifunc.m, logderiv.m, and erfderiv.m and they are all one line functions. For these three functions, approximate the following integrals with tol = 1e− 14: ˆ pifunc.m. Compute the integral over the interval [0, 1]. You should get a very good approximation of π. ˆ logderiv.m. Compute the integral over the interval [1, e] where e = exp(1) is the natural logarithm base. The integral should be 1 (or very close to it). ˆ erfderiv.m. Compute the integral over the intervals [0, 1] and [0, 3]. You should get good approximations of erf(1) and erf(3) from the erf function in MATLAB. Please turn in your codes and the output from these tests on Canvas. Your romberg function should be documented to explain how to call it and to explain any unusual code, but you do not need to document every single line. Note: The easiest way to get an output file is to use the MATLAB di- ary command. Suppose that romberg scr is a MATLAB script for this assignment and you type the following. ≫ diary ≫ romberg scr ≫ diary off 2 The output produced appear in a file called diary. If you do this run multiple times, it just adds to the end of the file. Thus, to have the output of one set of MATLAB commands, you should remove the diary file before doing the runnning those commands. Suggestion: Start outlining your solution to this project right after the class lecture on Romberg integration. If you start this on the day it is due, you may find this to be very difficult. 3
Answered Same DayDec 11, 2022

Answer To: CMPSC/Mathematics 455Final Exam – Part IIIDue 14 December 2022At Midnight–On CanvasNo...

Sathishkumar answered on Dec 11 2022
29 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here