0% found this document useful (0 votes)
9 views5 pages

MATH307 SP25 HW5 Solutions

This document outlines the instructions for Math 307 Homework #5, due on 2/28. It includes guidelines for significant figures, submission format, and resources allowed for completing the assignment. The homework consists of problems related to Lagrange interpolation and temperature data analysis, with specific tasks and solutions provided for each part.

Uploaded by

walterjeff191
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

MATH307 SP25 HW5 Solutions

This document outlines the instructions for Math 307 Homework #5, due on 2/28. It includes guidelines for significant figures, submission format, and resources allowed for completing the assignment. The homework consists of problems related to Lagrange interpolation and temperature data analysis, with specific tasks and solutions provided for each part.

Uploaded by

walterjeff191
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Math 307 Homework #5 due 2/28 by 11:45pm

Please read the instructions for each problem carefully. Write your answers neatly on your
own paper, indicating clearly which part of which problem is being answered.
Significant figures: Unless otherwise specified, include at least 4 significant digits in your
answer. (i.e. 41.75 is okay, 41.7 is not enough).
Submission: Submit your answers on Gradescope. The Canvas page for this assignment
will display a link for you to submit.
Typing your submission: You may write your answers with pen/pencil, or type your
submission. This is entirely your choice. However, if you type your submission, you are
strongly encouraged to you LATEXover MS Word or other word processor. We would
much rather see handwritten submissions over a (typical) MS Word submission, and LATEXis
easier than Word for math, once you get used to it.
Plots: plots should be generated in Matlab unless otherwise specified. When the directions
say “plot in Matlab,” you may receive 0 credit for plots not created in Matlab. See Canvas
for tips on including plots.
Resources: This assignment, like all Math 307 HW assignments, is to be completed as your
own work. Permitted resources are your notes, discussions with a MATH 307 instructor,
TAs in help hours (or CASA tutoring), tutors, and your own MATLAB. Prohibited resources
include copying work done by others, internet help forums, etc.

1. Consider the 4 points: (-1,2), (0,1), (2,3), (3,3).


(a) (3 points) Write the “building block” function L2 . Use the labeling convention
where the first point is point 1 and the points are listed in order above. Do not
simplify the result (do not expand).

Solution:
(z + 1)(z − 2)(z − 3) (z + 1)(z − 2)(z − 3)
L2 (z) = =
(0 + 1)(0 − 2)(0 − 3) 6

(Simplifying the denominator is not necessary.) I prefer to use z as an indepen-


dent variable name for the sake of the code in Matlab, but of course the name
of the independent variable doesn’t change the definition of the function! The
function L2 is the rule!

(b) (2 points) Compute L2 (1). That is, evaluate the “building block” function L2 with
an input of z = 1.

Solution:
(1 + 1)(1 − 2)(1 − 3) 4 2
L2 (1) = = =
(0 + 1)(0 − 2)(0 − 3) 6 3
(c) (2 points) Write the formula (by hand) for the Lagrange interpolating polynomial
as a linear combination of the building blocks and other numbers. You do not
need to find each Lk to answer this part, express your answer in terms of the Lk
functions, however, Ls should be the only symbols in your answer.

Solution:
P (z) = 2L1 (z) + 1L2 (z) + 3L3 (z) + 3L4 (z)

(d) (3 points) Use your lagrangepoly.m on the data set in this problem. Plot the
Lagrange Interpolating Polynomial over the domain of all x-values. That is, in a
driver script, define the z input to start at the left-most entry in your x vector, and
end at your right-most entry in your x vector, and include lots of points so you can
see the whole curve in between the data points. Also plot the data using markers
on the same axes: plot(x,y,’.’,’MarkerSize’,25). Turn in the plot.

Solution:

(e) (2 points) Use your code to compute P (1). That is, evaluate the Lagrange Poly-
nomial P with an input of z = 1. Hint: call your function again with a single z
input. Comment on the difference between this result and the result in part (b).

Solution: P (1) = 1.8333 (or 11/6). This is the actual interpolation value at
z = 1. In part (b), we just evaluated a building block at z = 1, which isn’t the
full interpolant.

2. Lakes can sometimes become thermally stratified during the summer, where warm water
near the surface overlies cold water toward the bottom. The plane separating the layers
is called the thermocline. A problem happens when thermal stratification inhibits mixing
between the two layers of water. Polluted surface water can result in oxygen depleted
water in the lower layers.
Consider the data of water temperature vs. depth. (This data set and all others in this
problem are provided in MATLAB syntax on the Canvas page so you don’t have to type
them yourself.)
Depth z (meters) 0 2.3 4.9 9.1 13.7 18.3 22.9 27.2

Temperature T ( C) 22.8 22.8 22.8 20.6 13.9 11.7 11.1 11.1
(a) (3 points) Use lagrangepoly.m to interpolate the data with equally spaced points.
In your plot, use temperature as the dependent variable and depth as the inde-
pendent variable. Turn in the plot of the interpolant overlayed by the data with
markers (plot(x,y,’.’,’MarkerSize’,25)) on the same axes. Label your axes with
descriptive labels.
Note: As usual, do not change your code to lagrangepoly.m or cubicInterp.m.
Write another script file that calls this functions. It is recommended
that you write a different script for a new data set. The script will call
lagrangepoly.m and cubicInterp.m and get the interpolating polynomials
to make the plots.
Hint: If your plots looks jagged in general, then you need to use a different input
vector z with good resolution between data points.

Solution:

(b) (1 point) Use lagrangepoly.m to predict the temperature when the depth is ex-
actly 25 meters. Hint: call the function again with a scalar input for z. Report at
least 5 significant digits.

Solution: T (25) = 8.6590 degrees C.

(c) (2 points) Do you trust that the interpolated value is accurate? Why or why not?

Solution: I would not trust it. It appears that Runge’s phenomenon is occur-
ring (a bump/oscillation is happening in between the data points of 22.9 and
27.2), messing up our accuracy.

(d) (3 points) Maybe we can make this prediction better by adding more points? Sup-
pose I added more points to the data set:
Depth z (meters) 0 2.3 3.6 4.9 9.1 10.8 13.7 15.6 18.3 22.9 27.2

Temperature T ( C) 22.8 22.8 22.7 22.8 20.6 18.1 13.9 12.4 11.7 11.1 11.1
Use lagrangepoly.m to interpolate the new data. Turn in the plot of the interpolant
overlayed by the data with markers (plot(xdata,ydata,’.’,’MarkerSize’,25)) on
the same axes.

Solution:

(e) (1 point) Use lagrangepoly.m to predict the temperature when the depth is ex-
actly 25 meters using the data set with more points included. Hint: call the function
again with a scalar input for z. Report at least 5 significant digits.

Solution: T (25) = 14.43699 degrees C.

(f) (2 points) Do you think your approximation is more accurate or less accurate using
more data points? Explain why this happened.

Solution: This got worse. This is Runge’s phenomenon: adding more points
causes overfitting to the data set.

(g) (3 points) Let’s not be too hasty in neglecting the value of Lagrange Interpolation.
A valid application is to represent a complicated function with a simpler one. Often
we can strategically choose the data points used in the sampling. Below is a similar
data set of water temperature vs. depth but the depths are sampled at Chebyshev
points.
Depth z (meters) 0 0.55 2.14 4.66 7.89 11.58 15.42 19.11 22.34 24.86 2

Temperature T ( C) 22.8 22.8 22.8 22.82 21.73 16.94 12.52 11.57 11.14 11.05 1
Use lagrangepoly.m to interpolate the new data with Chebyshev points. Turn in
the plot of the interpolant overlayed by the data with markers (plot(xdata,ydata
,’.’,’MarkerSize’,25)) on the same axes.
Solution:

(h) (1 point) Use lagrangepoly.m to predict the temperature when the depth is ex-
actly 25 meters using the data set with Chebyshev points. Hint: call the function
again with a scalar input for z. Report at least 5 significant digits.

Solution: T (25) = 11.05906 degrees C.

(i) (2 points) Did the Chebyshev points help? Do you think your interpolation is
trustworthy?

Solution: Yes, Chebyshev points helped, and this approximation is trustwor-


thy! Lagrange interpolation is helpful after all!

3. (10 points) The last ten points of this assignment will come from the in-class activity
Cubic Splines Worksheet.

Question Points Score


1 12
2 18
3 10
Total: 40

You might also like