首页 > > 详细

MECH 203 Week 6 Jupyter Notebook

 MECH 203

Week 6 Jupyter Notebook Written Report
INTERPOLATION
Due date: Thursday, February 27th, 2020
Grading & Weight: This assignment is out of 50 marks, as further specified in the mark 
breakdown for each question. The assignment is worth 6% of your overall final grade in the 
course.
Late Penalty: Late submissions will be penalized at 10% each day for up to 5 days, in which 
case a grade of zero will be given. 
1. Overview 
This assignment is about applying polynomial and spline interpolation to scientific and 
engineering data, both on “pen and paper” (Question 1) and using Python (Questions 2 
and 3).
Before you start working on the assignment make sure you:
• Review the online lecture videos and in-class lecture slides
• Watch the following two tutorial-like videos:
o Calculating a cubic spline on paper based on its mathematical definition:
https://www.youtube.com/watch?v=gT7F3TWihvk
o Piecewise linear and cubic spline interpolation with Python/SciPy: 
https://www.youtube.com/watch?v=s-3l_527ydQ
This assignment aligns with the following CLO’s:
CLO 4: Explain the principles behind interpolation methods
CLO 4: Develop interpolation methods using Python
CLO 4: Compare self-built interpolation methods with SciPy packages
1.1 Time for completion
This assignment will take approximately 4 hours to complete. 
2. Instructions 
When you have completed the assignment, upload the photos of the “pen 
and paper” calculations (for Question 1) and the Jupyter Notebook file to onQ. 
TASKS
Question 1
Suppose we have 4 data points, shown in Table 1, for which we would like to find interpolating 
curves.
x y
1.0 2.0
1.1 5.0
1.3 6.0
1.6 16
Table 1.
a. Find the interpolating polynomial using the Vandermonde matrix. Calculate the 
coefficients of the interpolating polynomial on “pen and paper” and upload a photo of it 
to onQ. You can use Python to solve the resulting system of algebraic equations to obtain 
the coefficients of the polynomial, if you do, include that code in the Jupyter Notebook
(8/50).
b. Find the natural cubic spline corresponding to the data points. Calculate the coefficients 
of the cubic spline on “pen and paper” and upload a photo of it to onQ. You can use 
Python to solve the resulting system of algebraic equations to obtain the coefficients, if 
you do, include that code in the Jupyter Notebook (8/50).
c. Plot the data points together with the interpolating polynomial and the natural cubic 
spline you have obtained (4/10). 
Question 2
The table below contains the water levels of Lake Ontario measured at Kingston at noon on the 
days of 19-26 October 2019. The same data can also be found on onQ in the text file “Water￾level_19-26October2019.dat”.
x
Day
y
Water 
level 
(m)
19 0.781
20 0.805
21 0.73
22 0.761
23 0.769
24 0.779
25 0.746
26 0.721
 Table 2.
a. If we have a known 𝑥𝑄 value within the interval defined by our data, write a code which 
can interpolate an 𝑦𝑄 value using piecewise linear interpolation. Calculate 𝑦𝑄 for the 𝑥𝑄
= 20.3, 22.8, 24.6 values. Do not use SciPy here but implement the linear interpolation
method based on its mathematical definition. For guidance, see Slide 12 and 22 in the 
“Week 6 In-Class Slides” and the videos listed in the Overview (6/50).
b. Implement a piecewise linear interpolation using SciPy (see link to videos in the 
Overview) and calculate 𝑦𝑄 for the 𝑥𝑄 = 20.3, 22.8, 24.6 values. Compare to the 𝑦𝑄
values from point a and see if you have obtained the same results (3/50).
c. Implement a cubic spline interpolation using SciPy (see link to videos in the Overview) 
and calculate 𝑦𝑄 for the 𝑥𝑄 = 20.3, 22.8, 24.6 values (3/50).
d. Make a plot which shown the data points together with the piecewise linear interpolation 
functions and the cubic spline you have obtained in b and c (3/10). 
Question 3
Download the “Zr-alloy_XRD-data.dat” and “BG-points_XRD-data.dat” data files from onQ. 
These are text files having two columns, the first and second column represents the x and y
coordinates, respectively.
“Zr-alloy_XRD-data.dat” file represents an X-ray Diffraction (XRD) (sometimes referred to as 
X-ray scattering) spectrum of a pressure tube made from Zirconium alloy, measured at the 
Advanced Photon Source, Argonne National Laboratory. The spectrum consists of an array of 
peak-shaped features which sit on the top of a smooth background, see Figure 1.
The first step in evaluating an XRD measurement is to estimate the smooth background and 
subtract it from the data. The background is typically estimated by choosing a few Background 
Points manually (see Figure 1) and interpolating them with a cubic spline, after which the cubic 
spline is subtracted from the data. The “BG-points_XRD-data.dat” file contains the coordinates 
of the Background Points.
a. Implement a cubic spline interpolation using SciPy on the Background Points listed in the 
“BG-points_XRD-data.dat” data file. Make a plot which shows the XRD spectrum, the 
Background Points and the cubic spline (7/50). 
b. Subtract the cubic spline obtained in a from the XRD spectrum. (I.e. for every x value 
listed in “Zr-alloy_XRD-data.dat” find the corresponding interpolated y background 
value and subtract that from the y value of the XRD data.) Make a plot which shows the 
XRD spectrum after the background subtraction (8/50).
Figure 1: The small red squares and large blue circles represent the XRD spectrum and the 
background points, respectively.
3. Evaluation
The report will be evaluated based on the completeness of the answers/solutions provided 
for each question.
 
联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!