MAE3456 - MEC3456 LAB 02: Due: 11:59PM (Sharp), Friday 19 March 2021 (End of Week 3)
MAE3456 - MEC3456 LAB 02: Due: 11:59PM (Sharp), Friday 19 March 2021 (End of Week 3)
– MEC3456 LAB 02
Due: 11:59PM (Sharp), Friday 19th March 2021 (End of Week 3)
This lab should be completed INDIVIDUALLY. Plagiarism will result in a mark of zero. Plagiarism
includes letting others copy your work and using code you did not write yourself without citing the
source. Collaborating with others to discuss algorithms and details of MATLAB syntax and structures
is acceptable (indeed encouraged), however you MUST write your own MATLAB code. All
assignments will be checked using plagiarism-detecting software and similarities in submitted code
will result in a human making a decision on whether the similarity constitutes plagiarism.
I NSTRUCTIONS
Download Lab02_Q+T.zip from Moodle and update the M-Files named Lab02_Q1a.m,
Lab02_Q1b.m, etc… with your Lab code. DO NOT rename the M-Files in the template and or modify
run_all.m (except to add in running scripts that answer any bonus questions
I might ask). Once you have coded, check your solutions to the questions by running run_all.m
and ensuring all questions are answered as required.
A SSIGNMENT H ELP
1) You can ask questions in the Discussion Forum on Moodle
2) Hints and additional instructions are provided as comments in the assignment template M-Files
3) Hints may also be provided during lectures
4) The questions have been split into sub-questions. It is important to understand how each sub-
question contributes to the whole, but each sub-question is effectively a stand-alone task that
does part of the problem. Each can be tackled individually.
5) I recommend you break down each sub-question into smaller parts too, and figure out what needs
to be done step-by-step. Then you can begin to put things together again to complete the whole.
6) To make it clear what must be provided as part of the solution, I have used bold italics and a
statement that (usually) starts with a verb (e.g. Write a function ..., Print the value..., etc.)
An experimental study to measure the blood flow rate inside the tissue found that the flow rate
changes with temperature. The data obtained from the experiment is summarized in Table 1.
Table 1: Blood flow rate inside the liver at different temperature elevation
Index, i 0 1 2 3 4 5 6
Temperature rise, DT(°C) 0 1 2 6 8 10 11
Blood flow rate (ml/min) 10 10.11 10.28 9.64 8.72 7.4 6.59
Q1a
Use the third order Lagrange polynomial interpolation to construct a cubic polynomial using the first
four data points from the table. [SHOW ALL WORKING]
Q1b
Use the cubic polynomial that you have constructed in Q1a to determine the blood flow rate when DT
= 8.5°C. [SHOW ALL WORKING]
Q1c
The solution that you get in Q1b is likely not to be accurate. Explain why. Suggest how you would
overcome this problem to obtain the most accurate estimate possible using a cubic polynomial.
Q2a
If you construct a cubic spline for the set of data in Table 2, list down the number of splines and the
number of unknowns that you will have.
Q2b
Using the details in Workshop 5 Playlist, OR the outline discussed in Workshop 5 (see in particular
Slides 8 and 11), construct by hand the system matrix that will allow you to determine the unknown
coefficients ci of your system matrix (it will be a 4x4 matrix). Assume natural spline boundary
conditions at both ends. Solve the resulting system matrix for the coefficients ci and work out the
remaining coefficients ai, bi and di. Construct the cubic spline equations based on the values of the
coefficients.
Q2c
Using the solution from Q2b, determine the value of y at x = 0.75 by hand. [SHOW ALL WORKING]
In Question 3, you will be writing Matlab code that will perform a 1D spline interpolation across N
arbitrary points.
Q3a
Write a MATLAB function that calculates the spline coefficients as defined in Workshop 05. The
function header MUST be
function [a,b,c,d] = SplineCoeff(x,y)
Here, the input parameters are
• Fit a spline to the 20 data points above using natural BCs at both ends.
• Calculate the spline value at 100 equally spaced points (including BOTH end points).
• Calculate the percentage error obtained for each point.
• Plot the natural spline using these 100 interpolated (x,y) values using a blue curve to represent
the interpolated data. On the same figure, plot the original data points using red dots.
• Using the yyaxis function, plot the percentage error at the 100 corresponding points using a
red curve and the right-hand-side y-axis.
• Print a short statement to the command window commenting what you observe and explain
why you obtain such a result.
A two-dimensional interpolation over a uniform grid can be carried out by performing 1D spline
interpolation twice, once in the x direction where all the necessary yp values are gathered, and once
in the y direction to obtain the final output. In this question, you will be constructing a 2D spline using
the 1D spline functions that you have written in Question 3.
Q4a
Write a MATLAB function that executes all the steps required to do spline interpolation (i.e. it
calculates the spline coefficients AND estimates the value). The function header should look like
function [yp] = Spline1D(xi,yi,xp)
Here, the inputs are
• xi – the x-values of the data.
• yi – the y-values that are to be interpolated
Continue with Lab_02_Q4c.m and write a Matlab code that will perform a spline interpolation across
the 51 x 51 data points using the 21 x 21 data points.
Plot the values of zi evaluated directly from the function based on the given data (i.e. the 21 x 21
points) in a surface plot using the Matlab function surf(xi,yi,zi).
In a different figure, plot the interpolated values of zp across the interpolation points (i.e. the 51 x 51
points) in a surface plot using the Matlab function surf(xp,yp,zp).
This question is optional and can be used to offset marks lost elsewhere in THIS lab
only. NOTE that it is NOT possible to get more than 50 marks for the lab.
Write a 1-D Lagrange polynomial interpolation function, and repeat Q4 with Lagrange polynomials
instead of splines. (Most of this question can be done by copying the Q4 code except for the 1D
interpolation). If you do this question, you can check if your answer to the last part of Q4 is correct.