程序代写代做 html CMPSC/Mathematics 451 Final Exam

CMPSC/Mathematics 451 Final Exam
Due Tuesday 5 May 2020 (5pm) No extensions, please! Spring 2020
You are to write a MATLAB function to implement a table lookup approx- imation of the function ex for x ∈ [0, 0.5 ∗ ln 2]. You will also make use of the romberg function that you developed in part one of this exam and the logderiv function that I put on Canvas for the second MATLAB code and for Quiz Four. You will be using inverse interpolation with cubic splines followed by Newton method for correction.
A similar approach is discussed in Section 4.9 of the Cleve Moler text- book that is linked to on the class Canvas paper. The link for the textbook is https://www.mathworks.com/moler/chapters.html. The appropriate chapter is called “Zeros and Roots”.
There are five steps to this process.
1. Log Function. Create a function mylog that computes ln x over the
interval [1, 2]. Your function should compute mylog(y) = 􏰀 y dt
1t
using your Romberg integration function with a tolerence of 10−14 = 1e − 14. If you did not get your romberg function to work correctly in Part One, you are welcome to use the one that is posted for the solution to Quiz Four.
2. Set up Inverse Interpolation. Note that over the domain [0, 0.5 ∗ ln 2], ex has the range [1, √2]. Let

a=1, b= 2, h=(b−a)/10.
Compute the y values
yvals = a: h: b and then for each j compute
xvals(j) = mylog(yvals(j))
Clearly, for j = 1, you can (and should) use the fact that xvals(1) = 0.
1

3. Perform Inverse Iterpolation. After specifying the correct endpoint conditions for a complete spline the 1 × 2 array endconds, set up the spline with the command
pp=csape(xvals,yvals,’complete’,endconds).
Then save pp in a .mat file using the command
save ppexp pp
thus creating the file ppexp.mat.
In Octave, this is slightly different. There is no csape function. Instead you should make the call
yspline=[endconds(1) yvals endconds(2)];
pp=spline(xvals,yspline);
The rest is the same.
4. Exponential Function. Create the function myexp with form
function [y,y0]=myexp(x)
where y is the computed value of ex and y0 = ppval(pp,x) is initial guess for our Newton iteration. Its first line should be
load ppexp
thereby loading the object pp created in the previous step. That avoids the problem of making pp an extra input parameter.
After that, for a given x, you will use Newton’s method on the function
g(y) = mylog(y) − x
with initial guess y0 = ppval(pp, x) to compute y ≈ ex. You should do a maximum of two iterations and do not iterate if the absolute value of the Newton step |g(y)/g′(y)| < eps ∗ abs(y). 2 5. Test your myexp function. Do the computation c=xvals(11); hh=c/99; xx=0:hh:c; For each value in xx, compute y and y0 using myexp putting all of these values in two vectors called yy and yy0. In three separate plots, plot yy against xx, plot err = yy − exp(xx) against xx, and err0 = yy0−exp(xx) against xx. The first plot should look like the exponential function, and the other two plots should have very small values. Please turn into the dropbox for this assignment all MATLAB functions and scripts new to this part of the final, and all three plots. Note: This is not the best way to compute the exponential function but it is not a bad way and reasonably simple. However, limiting the range of the exponential function to [0, 0.5 ln 2] is part of any such routine. The reason is that we can write ex as ex =2x/ln 2 =2k2z where k is an integer and z is between [−1/2,1/2]. Computing 2k can be done at the binary level. Thus we need only compute 2z. But 2z=ew, w∈[−0.5ln2,0.5ln2] However, if w < 0, we can compute e−w where −w ∈ [0, 0.5 ln 2] and just take the reciprocal. 3