Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

MTH1003 Mathematical Modelling

Project I (individual project): Interpolation and root nding

Submission deadline: 12:00 noon on Tuesday 6th December 2022 — see below.

In this project you will write some Matlab code to do cubic interpolation and root nding.  The project will test your understanding of these numerical methods as well as your knowledge of Matlab functions, loops, arrays, and plotting.

You will work individually on this project.  Your attention is drawn to the appropriate guidelines on collaboration and plagiarism, which are available from the Academic Misconduct web page.  To make everyone’s task distinct, the calculations done by each student will depend on their student ID. However, codes that are different by the student ID, but identical or very similar otherwise, will not be considered distinct and will be taken as evidence of academic misconduct, with corresponding disciplinary consequences.

This project contributes 10% of the overall module mark.

The function mydata

You are provided with a Matlab function mydata .m. It takes one input argument, your student ID, and returns two row vectors of length 6 containing some data for you to work with. For example, if your student ID is 123456789, then to obtain your data you could use the commands

studentid  =  123456789;

[x,  y]  = mydata(studentid);

Task 1: The function myID (5%)

Write a Matlab function called myID that takes no input arguments and returns your student ID as its output argument.  (You can nd your student ID number on your student card.  It will be a 9 digit number, usually beginning with a 7.)  This function will allow the marker to recreate your calculations.

Task 2: Plotting (15%)

Call the function mydata to obtain your data vectors x and y.  Use Matlab to produce a plot of y versus x. Produce a line plot (not a scatter plot). Include axis labels and a title. Make sure all the labelling, including axis tick values, are of suitable size. Save your plot as a pdf or png file — take a careful look at any file you generate to make sure it does contain a proper plot. In particular make sure the whole of the plot appears in the pdf/png file; you might find you need to move or resize the Matlab figure window before saving.

Task 3: Cubic interpolation (35%)

Write a Matlab function called cubicfit to do cubic interpolation.  It should take as input (i) a 4-element row vector of x values, (ii) a 4-element row vector of y values, and (iii) a scalar value . It should fit a cubic polynomial through the given data and evaluate that polynomial at to produce a single scalar output value (which you might call yˆ). You could use Lagrange’s interpolation formula. Thus, it should be possible to call your function with, for example,

studentid  =  123456789;                 %  or  studentid  = myID;

[x,  y]  = mydata(studentid);

xhat  =  3 .4;                                      %  or  any  other  value

yhat  =  cubicfit(x(2:5),y(2:5),xhat);

You should think of ways to test your function to convince yourself that it is working correctly, as the markers will read and test it.

Task 4: Root nding (45%)

Consider the cubic curve defined by tting through the four data points x(2:5), y(2:5), as in the above example.  We wish to determine where this cubic passes through y = 0 between x(3) and x(4).  Write a Matlab function called findroot that uses the regula falsi method (a bracketing method described in the lecture notes) to approximate the root.

The function findroot should take as input a pair of x values, xl0  and xr0, as a rst guess for the bracketing interval, and provide as output a single value of x, the approximate root. Your function should stop and return its result, say x* , when it finds a value of the cubic that is smaller in magnitude than 10_5 , that is |f (x* )| < 10_5 . It should output the corresponding value of x* .

Thus, it should be possible to call your function with, for example,

studentid  =  123456789;

[x,  y]  = mydata(studentid);

xl0  =  x(3);

xr0  =  x(4);

xstar  =  findroot(xl0,xr0);

%  or  studentid  = myID;

%  or  other pair  of  values

Your function findroot will need to call mydata to obtain the x and y values for the cubic t, and also call your earlier function cubicfit to obtain values of the cubic as needed.

You might want to base your function findroot initially on the code given in the lecture notes for the bisection method. Note, however, that the stopping criterion should be based on the value of the cubic function, not the size of the bracketing interval.  Once you are satisfied it is working you can convert it to regula falsi by a relatively small change.

Again you should think of ways to test your function to convince yourself that it is working correctly.

Marks

Your code will be tested in various ways by the marker to check that it gives correct results.  It is important that you submit your code in the form of Matlab functions, exactly as instructed, since we will partly automate the testing of your code.  Pay careful attention to the input and output arguments of your functions, including their order, as well as the function names.

Marks will be awarded for well structured and commented code, as well as correct answers when tested.

Important note: This is an individual project and while you are welcome to discuss it with your peers and with tutors, your work and coding must be your own and not copied from each other, nor from other sources, such as the internet.  If you do nd web-based resources and code, then of course you can study these and use them to inspire how you write your own scripts and functions, but you must not copy them (or copy and then make changes, or similar).  You can however take Matlab scripts or functions from the lecture notes and related materials on ELE, and use and modify these freely.

Submission

Submit only the following les:

● your Matlab function myID .m (task 1),

● your plot of y = f (x) in pdf or png format, in yplot .pdf or yplot .png (task 2),

● your Matlab function cubicfit .m (task 3),

● our Matlab function findroot .m (task 4).

The function les should be correctly named. The les should be submitted via the eBART system. Note: the eBART system will only allow you to submit a single le, so please zip your les into a single file before submission as follows:

On a Windows system: Put the four les (and nothing else) in the same folder. Right click on the folder and select send  to  . . .    compressed  folder.  The resulting folder will have a similar name to your original folder but with .zip on the end. You can submit the zipped folder to eBART.

On a Mac: Put the four les (and nothing else) in the same folder.  From a Finder window, ctrl-click on the folder and select Compress  . . .. The resulting folder will have a similar name to your original folder but with .zip on the end. You can submit the zipped folder to eBART.

The deadline is 12:00 noon on Tuesday 6th December 2022 (week 11 of term 1).