assignment-3
assignment-3
Assignment 3
Submission Details
This assignment is due to be handed in before
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].
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.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].
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 ) )