Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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...

1 answer below »
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 e
or estimate at the end. Your romberg function should have the
form
[int,e
,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 =

a
f(x)dx.
ˆ tol-the e
or 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.
ˆ e
– The value of Tk(h)− Tk−1(h), the e
or estimate.
ˆ ier – You are to have a maximum of l0 levels of extrapolation, i.e.,
k = 10. If you reach 10 levels and |e
| > 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 a
ay 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 sc
≫ 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 3 days After Dec 09, 2022

Solution

Baljit answered on Dec 13 2022
32 Votes
clea
help romberg_sc
CMPSC/Mathematics 455
Final Exam – Part III
function romberg_sc
it will take 4 input arguments and give 3 outputs.
first input rgument is function to be integrated,second argument is lowe
limit,3rd argument is upper limit.4th argument is tolerance to be reached
First...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here