# Numerical Algorithms and Programming AM10NP Yordan Raykov Group Assessment To be handed in on or before May XXXXXXXXXX In AM10NP, we have learnt the introductory concepts of programming such as: how...

Numerical Algorithms
and Programming
AM10NP
Yordan Raykov
Group Assessment
To be handed in on or before May XXXXXXXXXX
In AM10NP, we have learnt the introductory concepts of programming such as: how to read
information from files; how to store it in an array, how to display information, as well as, how
to iterate through data, include conditions and execute basic numeric algorithms which can be
iterative in nature. This assessment provides you with an opportunity to reveal these obtained
skills in addressing real-world challenges common today.
Question 1: Together with the coursework instructions, you will find a file named smartphone.txt:
the file contains raw measurements from an accelerometer placed in a smartphone device. The
data contains 4 columns: column 1 records the times at which measurements are collected,
columns 2, 3 and 4 record the x-axis, y-axis and z-axis of measured acceleration in the device.
• Load the accelerometer data from a file to an arrays ti and ai containing the first axis
and the second-fourth axis of the file. Create a plot of the measured acceleration against
time, i.e. display each column of ai against ti.
• Implement a for loop which passes through each element of the array ti and stores the
difference of two successive elements in array df(i), i.e. df(i) = |ti(i+1) −
ti(i)|. Display a histogram of df.
• Create an array ti un which includes equally spaced values between min(ti) and
max(ti), i.e. uniformly time index. Use the MATLAB function interp1 to interpolate
the arrays ai(:,1), ai(:,2) and ai(:,3) from the known times ti to the desired
times ti un. Display your result by plotting the iterpolated arrays ai interp(:, 1),
ai interp(:,2) and ai interp(:,3) on a single plot.
• For each axis ai interp(:,1), ai interp(:,2) and ai interp(:,3) esti-
mate an unknown piecewise linear trend g from the data which satisfies the following
criteria:
minimize
g∈R
‖ai− g‖22 + λ‖Dg‖22 (1)
where λ is a user-defined hyperparameter and you can use that the matrix D ∈ R(n−2)×n
is known as the second-order difference matrix, defined as:
D =

1 − XXXXXXXXXX . . .
0 1 −2 1 0 0 . . .
0 0 1 −2 1 0 . . .
. . .
. . .
XXXXXXXXXX −2 1
 (2)
with n being the length of the array ai and all off-diagonal elements being 0.
• Create an array ai filt = ai − g using the estimated g from above. Display a figure
with the following 3 subplots: subplot(1) plotting the array ai against time in seconds;
subplot(2) plotting the estimated array g against time; subplot(3) plotting the filtered array
ai filt. Save a .txt file which stores the filtered array ai filt.
Question 2: Data on the viscosity of water as a function of temperature are given below,
where T is the temperature in degrees Celsius and ν is the viscosity in mPa·sec:
Ti XXXXXXXXXX XXXXXXXXXX
νi XXXXXXXXXX XXXXXXXXXX 0.32
It is desired to determine which of the following two models is appropriate for the above data:
model 1:v(T ) = exp (c0 + c1T )
model 2:v(T ) = exp
(
c0 + c1T + c2T
2
) (3)
(a) Using the basis-functions method, fit both models to the given data and determine the ci
coefficients. Then, determine the model that fits the data better.
(b) Repeat the fitting using the polyfit method, and verify that you get identical results as
in part (a).
(c) To verify the correctness of your fitted values, plot ν versus T from Eq. (3) using your
best model evaluated at 100 equally-spaced points over the interval 0 ≤ T ≤ 100, and
add the data points {Ti, νi} to the graph, plotted with dots.
(d) Using at most four fprintf commands, print the ci coefficients from the two models as
in the following table:
2
c0 c1 c2
model 1: XXXXXXXXXX
model 2: XXXXXXXXXX0001
Hint: You can use these values to check you got the write coefficients in steps (a)-(c).
Question 3: Write a function which implements Jacobi method and use it to approximate the
solution of the following system of linear equations:
x1 + 15x2 + 5x3 + x5 = 15
20x1 − 2x4 + 4x5 = 25
3x2 + 12x3 + x4 = 11
x1 + x2 + 3x3 + 11x4 + x5 = 38
3x3 + 3x4 + 9x5 = 30
(4)
Continue the iterations until two successive approximations are identical when rounded to three
significant digits. Following the implementation of the direct method for solving linear systems
which uses Gaussian elimination and back substitution, find the exact solution of the system.
Elaborate on the conditions required for the different approaches to be appropriate.
Statement of Assignment:
• Use what you have learned in the module to produce well annotated and structured code
to implement the solutions of the exercises.
• Include short worded discussion for each problem justifying the steps you have taken, as
well as, practical limitations where relevant
• You will be assigned a group and encourage to work together on the different exercises
and the reasoning provided, but everyone should submit an individual report with code
and instructions
• Your submission should include a grade for each of your team members on the scale of
• Equal marks will be awarded for each of the three questions and 20% of your grade is
reserved for teamwork, programming style and program efficiency
If you are not sure what to do, or if there are any other problems, please contact me by email
me ( XXXXXXXXXX).
END OF SHEET
3
Answered 4 days AfterMay 03, 2021

## Solution

Joice G Philip answered on May 08 2021

### Submit New Assignment

Copy and Paste Your Assignment Here