MATH4064-c++或者matlab代写
时间:2023-03-03
1 MATH4064
The University of Nottingham
SCHOOL OF MATHEMATICAL SCIENCES
SPRING SEMESTER 2022-2023
MATH4064 - COURSEWORK 1 — 20% —
Coursework 1 — Hand-in deadline: 3 pm Wednesday 08/Mar/2023
Your neat, clearly-legible solutions should be submitted electronically as a pdf file via the MATH4064 Moodle
page by the deadline indicated there. Your report should include discussions and comments on all your
results with reference to the underlying mathematical theory. Upload 2 files on Moodle: a PDF of your
coursework submission and a ZIP containing all the computer codes you used to do your coursework. Since
this work is assessed, your submissionmust be entirely your ownwork (see the University’s policy onAcademic
Misconduct). Submissions up to five working days late will be subject to a penalty of 5% of the maximum mark
per working day.
1. Problem set [2-Cubic B-spline Interpolation] [50 marks]
a Consider a function ∶ [, ] → ℝ has been sampled at + 1 ≥ 4 equally spaced points = 0 <
1 < … < = . Write a subroutine/function that will take as input the function values {()}

=0
and return the coefficients {}
+1
=−1 of the natural
2-Cubic B-spline 3 () that interpolates .
b Write a function that will take as input the coefficients {}
+1
=−1, and the nodes {}

=0 and output the
values of the spline 3 evaluated at 20+1 uniformly spaced points {}
20
=0 on the interval [, ]. Your
code should also output the evaluation points {}.
c Test your code for () = cos(6) on the interval [0, 1] for = 8, 16, 32, 64, 128. For each :
i Provide a plot of the spline 3 ().
ii Compute an approximation to the error ‖ − 3 ‖∞,[0,1].
Plot log10(‖ −

3 ‖∞,[0,1]) against log10(). Comment on these results.
d Now consider ∶ [, ] → ℝ is a periodic function with period − and that has been sampled at
≥ 3 equally spaced points = 0 < 1 < … < −1 = − ℎ, where ℎ = ( − )/.
i By exploiting periodicity, write down thematrix problem to find the coefficients { ̃}
−1
=0 of the
2-Cubic
B-spline ̃3 () that interpolates .
ii By suitably modifying the code from part a , write a function/subroutine that will take as input the
function values {()}
−1
=0 and return the coefficients { ̃}
−1
=0 .
iii By suitably modifying the code from part b , write a function/subroutine that will take as input the
coefficients { ̃}
−1
=0 , and the nodes {}
−1
=0 and output the values of the spline evaluated at 20+1
uniformly spaced points {}
20
=0 on the interval [, ].
e Test the code from part d for () = cos(6) on the interval [0, 1] for = 8, 16, 32, 64, 128. Again,
for each :
MATH4064 Turn Over
2 MATH4064
i Provide a plot of the spline ̃3 ().
ii Compute an approximation to the error ‖ − ̃3 ‖∞,[0,1].
On the same set of axes as in part c , plot log10(‖ − ̃

3 ‖∞,[0,1]) against log10() and comment on
the results.
f Cubic B-splines can be used to plot smooth curves embedded in 2D, defined at only a small number
of points. Suppose that we have the set of points {(, )}

=0, then we can paramaterise a curve that
passes through these points with the parameter 0 ≤ ≤ 1. Let 0 = 0 < 1 < … < = 1 be equally
spaced points, then the spline ((), ()), should pass through the points ((), ()) = (, ) for
= 0,… , .
Consider the files spline_natural1.dat, spline_natural2.dat and spline_periodic.dat. These
files each define a set of points in 2D. Load these files and apply the code from part a and b to
spline_natural1.dat and spline_natural2.dat and the code from part d to spline_periodic.dat.
Hence, generate and plot the 3 2D cubic splines on the same set of axes.
2. Problem set [Root Finding] [50 marks]
a Write a function/subroutine that will implement Newton’s method for solving F(x) = 0, where F ∶
ℝ → ℝ. Your code should take as input a routine that implements F, a routine that implements the
Jacobian matrix JF, and an initial guess x
(0). The code should stop when
‖x() − x(−1)‖2 ≤ 10
−12,
or when 100 iterations have been performed.
b Use the code from part a to find the 4 solutions to the system of equations:
2 + 2 + 2 = 1,
4(2 + 2) − 2 = 0,
3 − = 0.
For each solution, record the initial guess used and the number of Newton iterations required.
c Consider the problem of plotting a curve in 2D defined implicitly by the equation
(, ) = 0,
where (⋅, ⋅) is some nonlinear function.
One way of plotting an approximation is to choose various values of and use a root-finding algorithm
to find the corresponding , however, this is not robust, as some values of may have no corresponding
, while others may have more than one .
An alternative approach is to ‘follow’ the path of the curve, by starting at some initial (−1, −1) that
lies on the curve, predicting a new point ( ̃, ̃) by moving in a tangential direction to the curve and
then correcting using Newton’s method to a point (, ) that does lie on the curve.
Suppose that we would like to move along the curve with a roughly constant arclength of . Letting
x = (, ), then at each step, the method amounts to solving the following problem
(, ) = 0, (1)
(x − x−1) ⋅ t−1 = , (2)
where t−1 is the unit tangent to the curve at x−1. This method is called pseudo-arclength continuation.
MATH4064
3 MATH4064

(0, 0)
(1, 1)
( ̃1, ̃1)
Write a code that will solve problem (1)-(2) using Newton’s method with an initial guess x−1+t−1.
Hence, draw an approximation to the ellipse
2 +
2
22
= 1,
using = 0.05.
[Hint: You should make sure that each new t points roughly in the same direction as t−1.]
MATH4064 End

essay、essay代写