CMPSC/Mathematics 455
Final Exam—Part II
Due Friday 2 December 2022
Fall 2022
You are to write a MATLAB function to implement a table lookup approx-
imation of the function sin−1 x = arcsin x for x ∈ [0, π/4]. You will be
using inverse interpolation with cubic splines followed by Newton’s method
for co
ection.
A similar approach is discussed in Section 4.9 of the Cleve Moler text-
ook that is linked to on the class Canvas page. The link for the textbook
is https:
www.mathworks.com/mole
chapters.html. The appropriate
chapter is called “Zeros and Roots”.
There are four steps to this process.
1. Set up Inverse Interpolation. Note that over the domain
[0, π/4], sin x has the range [0,
√
2/2]. Let
a = 0, b =
√
2/2, h = (b− a)/10.
Compute the y values
yvals = a:h:
and then compute
xvals = sin(yvals)
2. Perform Inverse Iterpolation. After specifying the co
ect endpoint
conditions for a complete spline in the 1 × 2 a
ay 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 pparcsin pp
thus creating the file ppexp.mat. [Hint: The dervative of f(x) =
sin−1 x = arcsin x is f ′(x) = (1− x2)−1/2. ]
In Octave, this is slightly different. There is no csape function. Instead
you should make the call
1
yspline=[endconds(1) yvals endconds(2)];
pp=spline(xvals,yspline);
The rest is the same.
3. Inverse Sine Function. Create the function myexp with form
function [y,y0]=arcsin(x)
where y is the computed value of arcsinx = sin−1 x and y0 = ppval(pp, x)
is initial guess for our Newton iteration. Its first line of the function
should be
load pparcsin
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 to solve the
nonlinear equation
g(y) = x− sin(y) = 0
with initial guess y0 = ppval(pp, x) to compute y ≈ sin−1 x = arcsinx.
Stop your iteration when
|g(y)/g′(y)| ≤ tol ∗max([|y| tol]), tol = 10−14 = 1e− 14
or after five iterations whichever comes first.
4. Test your inverse sine function. Do the computation
c=xvals(11);
hh=c/99;
xx=0:hh:c;
The MATLAB/Octave functon for sin−1 x = arcsinx is asin. For each
value in xx, compute y and y0 using arcsin putting all of these values
in two vectors called yy and yy0. In three separate plots, plot yy against
xx, plot e
= yy − asin(xx) against xx, and e
0 = yy0 − asin(xx)
against xx. The first plot should look like the inverse sine function,
and the other two plots should have small values.
Please upload into Canvas all MATLAB functions and scripts new to the
final, and all three plots.
2