0% found this document useful (0 votes)
3 views

assignment-3

This document outlines the details for Assignment 3 of the MA2K4 Numerical Methods and Computing course, due on February 29, 2024. It includes instructions for both the theoretical and numerical parts of the assignment, specifying submission formats, collaboration rules, and penalties for late submissions. The assignment consists of various problems related to numerical methods, including quadrature rules and initial value problems, requiring both theoretical proofs and practical implementations in Python using Jupyter Notebook.

Uploaded by

Wangyh0630
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

assignment-3

This document outlines the details for Assignment 3 of the MA2K4 Numerical Methods and Computing course, due on February 29, 2024. It includes instructions for both the theoretical and numerical parts of the assignment, specifying submission formats, collaboration rules, and penalties for late submissions. The assignment consists of various problems related to numerical methods, including quadrature rules and initial value problems, requiring both theoretical proofs and practical implementations in Python using Jupyter Notebook.

Uploaded by

Wangyh0630
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

MA2K4 Numerical Methods and Computing

Assignment 3

Submission Details
This assignment is due to be handed in before

Thursday 29th February 2024, 12 noon

to be submitted via the submission point on the module moodle page.

Student ID

Student ID of partner

Please fill in your ID and that of your working partner above. You need to submit your work
even when working with a partner.

Please read carefully all instructions on this page to make sure you understand all rules and restric-
tions. Every submission consists of two parts: A theoretical part, which can be handwritten or computer-
written, and a numerical part, which is to be submitted as jupyter notebook .ipynb-file. Further rules
and restrictions:
All handwritten parts must be legible to receive full marks.
Make sure to provide explanations and show your work. The correct answer alone and without
explanation will not receive full marks.
Numerical work should come in an .ipynb-file with comments, explanations, code, and figures.
The submission file needs to be able to run through from top to bottom to reproduce all the results
of your submission.
Python is the only computer language to be used in this course.
You are allowed to use pre-defined mathematical functions (such as exp, linspace, max, ...), but
you are NOT allowed to use high-level numerical functions (such as interpolate, polyfit, ...).
All work must be explained, commented on, and all work must be shown. Implementation should
contain comments and explanations in markdown surrounding them. Figures should have appro-
prate axis scaling, labels, legends, etc.
The assignments can be worked on and submitted in pairs. If you choose to do so, indicate your
own and your partner’s student ID in the fields above. Each partner must upload all submission
files to moodle. In this case,both partners receive the same mark.
Late panelties apply automatically to late submissions. Even if you submit together with a part-
ner, and your partner submits in time, you will be penalised for a late submission if your own
submission is not in time.
To reiterate the above: You will only earn marks if you submit work, and do so before the deadline.
The use of generative AI in this assignment is strictly forbidden.
Assignment 3 MA2K4 2023/24– Numerical Methods and Computing

Theoretical Part

This part is to be solved by hand and manual calculation, without the help of a computer. Show
all your work to receive full marks.

3.1 Show that the Newton-Cotes quadrature rule of order n > 1 is exact for all polynomials
of degree n + 1 if n is even.
Hint: For the integration interval x ∈ [a, b], consider the polynomial (x − 21 (a + b))n+1 .

3.2 Consider the Newton-Cotes quadrature rule of degree n = 3 on the interval x ∈ [−1, 1],
3
I3 (f ) = ∑ αk f (xk )
k=0

with xk = −1 + 32 k. Using the fact that this quadrature rule must be exact for all poly-
nomials of degree 3, or otherwise, find the values of the four weights αk , k ∈ {0, . . . , 3}.

3.3 For the composite trapezoidal rule I1,n (f ) and the composite Cavalieri-Simpson rule
I2,n (f ), show that
I2,n (f ) = 34 I1,2n (f ) − 13 I1,n (f ) .

3.4 In this problem, show that it is not true that the Cavalieri-Simpson rule is necessarily
more accurate than the trapezoidal rule, by constructing an explicit counter example.
For this, calculate
1
∫ (x5 − λx4 ) dx
0
and find the range of values of λ ∈ R for which the trapezoidal rule gives a more accu-
rate estimate than the Cavalieri-Simpson rule.

3.5 Derive the 3-node Gauss quadrature on the interval [−1, 1] by finding the three weights
αi and nodes xi for i ∈ {0, 1, 2}. Then, use the rescaling formula
n
Gn (f ) = 12 (b − a) ∑ αi f ( 12 (a + b) + xi 12 (b − a))
i=0

to write down the 3-node Gauss quadrature on an arbitrary interval [a, b].

3.6 Consider the initial value problem

y ′ (t) = (y(t))1/5 , y(0) = 0 .

a) Show that
5/4
y(t) = ( 45 t)
is a solution of the above IVP.

2
Assignment 3 MA2K4 2023/24– Numerical Methods and Computing

1/5
b) Show that the forward Euler method un+1 = un + hun with u0 = y(0) fails to approx-
imate this solution. Give a reason for why this is the case.

3
Assignment 3 MA2K4 2023/24– Numerical Methods and Computing

Numerical Part

This part is to be solved in python in a single jupyter notebook .ipynb-file. Make sure that all
your explanations, code, figures, results, comments, and discussions are included in this single
file to receive all marks. Re-use as much code as possible and avoid any code duplication.

3.7 Implement two functions, composite trapezoidal(f, a, b, n) and composite simpson(f,


a, b, n) which implement the composite trapezoidal and composite Simpson rules,
respectively, for approximating the integral of a function f ∶ [a, b] → R, and where n is
the number of equally sized subintervals in [a, b].
a) Compute an estimate of the integral of f (x) = tan x on the interval [0, 1] with both
methods, with n = 10 subintervals, in comparison to the exact answer.
b) Do a convergence study for the function f (x) = tan x on the interval [0, 1] by perform-
ing multiple experiments for n = 2k with k ∈ {0, 1, . . . , 10}, then plotting, in a log-log
plot, the observed quadrature error against h̃ = 1/n (which is a variable proportional
to the node spacings), and comparing against lines h̃γ for appropriately chosen γ to
find the scaling of the errors of the two methods.
c) Compile a table containing the columns “h̃”, “error I1,n ”, “eval I1,n ”, “error I2,n ”,
“eval I2,n ”, which compares h against the error of the two methods (in the “error”
columns), as well as the number of function evaluations (in the “eval” columns) for
each of the methods. Comment on which method is the most efficient in terms of
function evaluations to reach an error of 10−6 .

3.8 In problem 3.5 the 3-node Gauss quadrature on an arbitrary interval [a, b] was derived.
Do a convergence study in the interval size h = b − a to find the error scaling of this
quadrature in (b − a) both graphically and by computing the experimental order of
convergence (EOC) for a suitable number of experiments and spacings for the function
f (x) = cos(x) on the interval [0, h].

3.9 Consider the initial value problem

y ′ (t) = αy(t) , y(0) = 1 ,

for α ∈ R and t ∈ [0, 5].


a) Implement the forward Euler method and plot its result un against the exact results
y(t) for N = 10 time steps, for the values α ∈ {−0.8, −0.1, 0.1, 0.3} into a single figure.
b) Similarly, implement the Heun method, and again plot its results ui against the exact
result for N = 10 time steps, for the values α ∈ {−0.8, −0.1, 0.1, 0.3}. Comment on the
comparison between the two.

4
Assignment 3 MA2K4 2023/24– Numerical Methods and Computing

Helper Code

You can use the below code to display very small or very large numbers in scientific notation
up to a given precision.
1 def scientific (a , precision =3) :
2 expo = int ( np . log ( abs ( a ) ) / np . log (10) )
3 expo = expo if expo >0 else expo -1
4 manti = np . round ( float ( a ) /10** expo , precision )
5 if expo < -1 or expo > 1:
6 return ’ {} E {} ’. format ( manti , expo )
7 else :
8 return ’ {} ’. format ( np . round (a , precision ) )

You might also like