Semester 2 Special Assessment, 2020
School of Mathematics and Statistics
MAST30028 Numerical Methods & Scientific Computing This exam consists of 8 pages (including this page)
Authorised materials:
• The subject website hosted on the Learning Management System (LMS). • Any part of the provided software system MATLAB.
• Blank A4 paper.
Instructions to Students
• It is not an open book exam. You can only access specified authorized materials and should not access the internet for any other materials.
• This is a strict time limit exam. You have 30min reading time, 3hrs to finish, and 30mins to submit your work via LMS. The submitting page will close automatically after 240mins.
• Write your answers and put your numerical results into a document (e.g. Microsoft Word) file on computer. Start each question on a new page. Write the question number. For some questions, you can write on a piece of paper.
• Scan any written response on paper into a single PDF file using a proper scanning app such as Camscanner, Scannable or OfficeLens. Do not just take photos with your phone camera as this produces large files that you may not be able to upload. Scan from directly above to avoid any excessive keystone effect. Check that all pages are clearly readable and cropped to the A4 borders of the original page. Poorly scanned submissions may be impossible to mark.
• Upload the document file(s) (including your numerical results, comments, and other writ- ings) and the zip file (including all m-files) via the Canvas Assignments menu.
• You should attempt all questions.
• Full reasoning must be shown and penalties may be imposed for poorly presented, unclear,
untidy and badly worded solutions.
• There are 7 questions with marks as shown. The total number of marks available is 80.
Supplied by download for enrolled students only—©c University of Melbourne 2020
Student Number
MAST30028 Semester 2, 2020 Question 1 (7 marks) Run the following code and examine the plots it produces
close all;
f=@(t,y) y.^2.*(1-y);
delta = 0.01;
y0 = delta; tspan = [0 2/delta];
n = 100;
[tvals, yvals] = FixedEuler(f, tspan, y0, n);
figure(1);
plot(tvals, yvals, ’k’);
xlabel(’t’); ylabel(’y(t)’);
n = 10;
[tvals, yvals] = FixedEuler(f, tspan, y0, n);
figure(2)
plot(tvals, yvals, ’r’);
[tvals, yvals] = ode15s(f, tspan, y0);
figure(3)
plot(tvals, yvals, ’b’);
Which solutions do you think are accurate? Explain in general terms what the code is doing ( not a line-by-line description) and, in terms of concepts covered in this subject, explain what is happening in this problem.
You may use any code used in the Labs.
Page 2 of 8 pages
MAST30028 Semester 2, 2020 Question 2 (9 marks) Consider the following procedure for determining the limit ! sin(h)/h
h→0 for n = 0, 1, 2, . . . and accept as the machine limit the first value satisfying dn = dn−1.
(a) Write a MATLAB function examQ2.m implementing the procedure. Your MATLAB function should return dn and n.
(b) In floating-point arithmetic, with rounding by chopping, for what value of n will the correct limit be reached, assuming no underflow (of 2−n) occurs? (Hint: use sin(h) = h−1h3+···)
(c) Compare the theoretic result n in (b) with the simulation experiment undertaken in (a).
on a computer. Let
dn =fl”sin(2−n)# 2−n
Page 3 of 8 pages
6
MAST30028
Question 3 (10 marks) Explain the output of the following MATLAB code:
(a) forn=[481216] A = pascal(n);
xTrue = ones(n,1)*10/3;
b = A*xTrue;
format long;
x = A\b
relerr = norm(x – xTrue)/norm(xTrue);
fprintf(Relative error = %8.4e\n,relerr)
pause
end
(b) Why do the code snippets
A=rand(50);
[L,U]=lu(A); norm(A-L*U)
[L,U,P]=lu(A); norm(A-L*U)
produce different answers? Explain why one is small and one is not.
Semester 2, 2020
Page 4 of 8 pages
MAST30028 Semester 2, 2020 Question 4 (8 marks) T$he Hit-and-miss Monte Carlo method can be used to approximate
definite integrals such as ab f(x)dx where 0 ≤ m ≤ f(x) ≤ M. By using points randomly placed in the rectangle [a, b] × [m, M ], proportions of points under curve y = f (x) → !ab f (x)dx as
(b−a)(M −m) (a) Explain how the method can be used to approximate $ab $cd f(x,y)dxdy, where 0 ≤ m ≤
the number of points → ∞. f(x,y) ≤ M.
(b) Write a MATLAB function examQ4.m that estimates
%3%3
1 + sin(2xy)dxdy
00
using a Monte Carlo method as explained in part (a). Your MATLAB function should return your estimate as a scalar and the 95% confidence interval as a vector, given the number of random points as an input argument.
(c) Find the estimate and 95% confidence interval using 100, 000 random points.
(d) Compare your answer with the result of using MATLAB’s integral2 functions.
Page 5 of 8 pages
MAST30028
Question 5 (12 marks) The following data
is though to be described by the model: y ∼ &a+√x’2. b√x
Semester 2, 2020
x
0.5
1
2
3
4
y
10.4
5.8
3.3
2.4
2
(a) Use a transformation to transform the the nonlinear model into a linear model.
(b) Now fit the transformed data to a line by constructing a suitable linear system and using
(c)
(d. )
\. Report the corresponding parameters a and b.
Now fit the original data directly to the nonlinear model, by using lsqcurvefit with Levenberg-Marquardt algorithm. Choose initial guesses for the parameters by using part (b). Compare the parameter values with those from part (b).
By plotting the data and both fits in (b) and (c) on the same plot, decide which method gives the best fit for this data.
Page 6 of 8 pages
MAST30028 Semester 2, 2020 Question 6 (13 marks) One variant of Newton’s method for solving the equation f(x) = 0 uses
the formula
xn+1 = xn − 2 f(xn) . f′(xn)
(a) Modify Newton.m to produce a function ModifiedNewton.m that implements this method.
(b) Write a driver function to call ModifiedNewton.m. Compare the performance of Newton’s
method with that of ModifiedNetwon.m on the equation (x3 +x2 −8x−12)exp(x)=0
with x0 = −1 and a relative tolerance (only) of 10−11. Suitable plots may be useful. Based on your results, describe the behavior of the modified Newton’s method compared to Newton’s method.
(c) Describes what advantages and disadvantages does the modified Newtons have.
(d) Establish the convergence rate for the modified Newton’s method if x∗ is a double root of
f.
You may use any code used in the Labs.
Page 7 of 8 pages
MAST30028
Question 7 (21 marks) Consider the third order initial value problem
v′′′(t) + v′′(t) + 4v′(t) + 4v(t) = 4t2 + 8t − 10, v(0) = −3, v′(0) = −2, v′′(0) = 2.
Make sure you also specify the initial condition y = y0 as a 3-vector.
(c) Use the MATLAB function ode113 to solve this problem over the time interval 0 ≤ t ≤ 2.
Plot the true and computed solutions to make sure youve done this correctly.
(d) Test the ode113 solver by specifying different tolerances ranging from 10−4 to 10−10 . I suggest you set the relative and absolute tolerances equal. Create a table showing the maximum absolute error in the computed solution for each tolerance and the number of function evaluations required to achieve this accuracy.
Use the command options = odeset(Stats,on) to produce the number of function eval- uations.
(e) Repeat part (d) using the MATLAB function ode45.
(f) Plot the work required against the accuracy achieved from parts (d) and (e) using a
suitable plot. Comment on your findings.
Semester 2, 2020
v(t)=−sin(2t)+t2 −3
(b) Rewrite this problem as a first order system of the form y ̇(t) = f(t,y(t)) where y(t) ∈ R3.
(a) Verify that the function
is a solution to this problem.
Reminder: You may use any code used in the Labs. You may answer in a document (e.g. Microsoft Word). Include any relevant output and plots in the document as evidence to support your answers. Then convert the document into pdf.
End of Exam—Total Available Marks = 80
Page 8 of 8 pages