CS计算机代考程序代写 matlab Semester 2 Supplementary Assessment, 2020

Semester 2 Supplementary 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
Question 1 (9 marks) The following code
close all;
f=@(t,y) -4*pi^2*(y-cos(t))-sin(t);
y0=1; tspan=[0 2];
n=1000;
[tvals,yvals] = FixedEuler(f,tspan,y0,n);
plot(tvals,yvals,’o’);
xlabel(’t’);ylabel(’y(t)’);
hold on;
n=100;
[tvals,yvals] = FixedEuler(f,tspan,y0,n);
plot(tvals,yvals,’x’);
n=10;
[tvals,yvals] = FixedEuler(f,tspan,y0,n);
plot(tvals,yvals,’r’);
produces the following plot.
x 105
1
0 −1 −2 −3 −4 −5 −6 −7
Semester 2, 2020
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
t
Which solutions do you think are accurate? Any? 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
y(t)

MAST30028 Semester 2, 2020 Question 2 (9 marks) Consider the following procedure for determining the limit
on a computer. Let
lim (cos(h) − 1) h→0 h
dn =fl!cos(2−n)−1″ 2−n
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 cos(h) = 1−1h2+···) 2
(c) Compare the theoretic result n in (b) with the simulation experiment undertaken in (a).
Page 3 of 8 pages

MAST30028
Question 3 (6 marks) Explain the output of the following MATLAB code:
(a) n=10;
A= rand(n);
b = rand(n,1);
x= A\b;
b = b+1.e-8*rand(n,1);
x1=A\b;
norm(x-x1);
(b) n=10;
A= hilb(n);
b = rand(n,1);
x= A\b;
b = b+1.e-8*rand(n,1);
x1=A\b;
norm(x-x1);
Semester 2, 2020
Page 4 of 8 pages

MAST30028 Semester 2, 2020
Question 4 (12 marks) Let p be the probability that three random points on unit circle form an obtuse triangle (see the figure).
P1 c
P2
function [p, stderror] = approxProb(Nreps)
to estimate the probability p. Your MATLAB function should return your estimate of p and the standard error fo the estimator, given the number of repetitions as an input argument.
(b) Run the simulation 10 times and print the probability p with 4 decimal places for the number of repetitions Nreps = 100 and Nreps = 10,000, respectively. Describe what do you observed.
(c) Determine by simulation the number of repetitions for the standard error to be less than 1 × 10−3, i.e. the estimate for p should have 2 decimal place accuracy.
(d) Estimate the number of repetitions you would need for 3 decimal place accuracy. Explain your answer.
a
b P3
(a) Write a MATLAB function with calling sequence
Page 5 of 8 pages

MAST30028
Question 5 (12 marks) The following data:
s = [2.5 5 10 15 20];
v = [0.024 0.036 0.053 0.060 0.064];
is thought to be described by the model: v ∼ c1s/(c2 + s) (a) Show that the model can be re-written as
1 ∼ 1 + c2 1 v c1 c1s
Semester 2, 2020
(b) Hence transform the data to new variables in which the model appears linear in the parameters. Now fit the transformed data to a line by constructing a suitable linear system and using \. Report the corresponding parameters c1 and c2.
(c) Now fit the original data directly to the nonlinear model, by using lsqcurvefit. Use as initial guesses for the parameters: c1 = 0.1, c2 = 6. Compare the parameter values with those from part (b).
(d) Plot the data and both fits on the same plot, and comment.
Page 6 of 8 pages

MAST30028 Semester 2, 2020
Question 6 (12 marks) We want to find a solution of the equation log(x) − exp(−x) = 0
(a) Use a suitable theorem to show that there is (at least) one root in the interval [1,2].
(b) Use Newton’s method to find a root in [1,2], using an absolute tolerance only of 10−12. Plot the residuals on a suitable plot. How many iterations are required?
(c) Repeat part b but using fzero with the Display option set to iter, but don’t plot the residuals.
(d) Show that the solution above can be found from computing the fixed point of the function g(x) = exp(exp(−x))
Hence use fixed point iteration, starting from x0 = 2 with 40 iterations, to solve the original equation. Plot the residuals on a suitable plot. Explain what you observe after about 35 iterations.
(e) Based on your results above, compare all three methods for solving the equation.
You may use any code used in the Labs.
Page 7 of 8 pages

MAST30028 Semester 2, 2020
Question 7 (20 marks) The equations of motion describing a planet with position (x(t),y(t)) orbiting the Sun at the origin are given by:
x ̈=−x/r3; y ̈=−y/r3; r=#x2 +y2. Solve for the motion of a planet with initial conditions
x(0) = 0.1; y(0) = 0; x ̇(0) = 0; y ̇(0) = √19.
(know to be periodic) over the time interval [0, 20], using the following methods:
(1) Fixed step RK3 and RK5 methods, with number of time steps n = 1000, 10000.
(2) MATLAB’s inbuilt methods ode23, ode45. Using the default tolerances, as well as relative
tolerances of 10−4, 10−5.
Answer the following equations, using your results as evidence.
(a) In terms of accurately producing a periodic orbit, which of RK3 or RK5 is more efficient, as measured by time? as measured by function evaluations?
(b) Intermsofaccuratelyproducingaperiodicorbit,whichofode23orode45ismoreefficient, as measured by time? as measured by function evaluations.
(c) For this problem, are fixed-step or variable-step method more efficient? What properties of the solution are responsible for one class of methods being more efficient?
(d) Why compare using RK3 and RK5 methods, rather than (say) RK4?
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