Numerical Methods
Question 1
Given the function f(x) = cos(x) with x 2 [⇡/2, ⇡/2],
1. write a function that takes the limits of an interval and the order n of the polynomial interpolation pn(x), and returns the data points xi that can be used for the
Chebyshev interpolation. Test this with an example input (your choice).
(Marks: 7)
2. write a function that takes a function f, order n, array (of any length) z and the
array x with the data points for the polynomial interpolation, and returns the values
pn(z) of the polynomial interpolation. You can use any of the three methods for
finding the polynomial interpolation from the lecture notes.
(Marks: 22)
3. Use your interpolation function on the given function and the given interval using
second order interpolation and both, Chebyshev economisation and equidistant
data points. Plot the two interpolants in the same plot using di↵erent colours and
linestyles together with the data points for both methods using markers. Add axis
labels and a legend.
(Marks: 12)
Question 2
1. Given the function f(x) = ex+x2, use the composite trapezium rule to compute the
integral R b
a f(x) dx using n equally spaced sub-intervals. Write this into a function
that takes f, a, b and n as inputs and returns the integral.
(Marks: 13)
2. Using the interval [a, b] = [0, 2] and the values n = 2p with p = 0, 1, …20, compute
the integral and plot the result in dependence of n using a semi-logarithmic (in
n) plot. In a di↵erent figure, plot the absolute di↵erence between your numerical
result and the exact value of the integral against n using a log-log plot. As always,
add axis labels. Comment on your second figure.
(Marks: 11)
1
Question 3
Given the function f(x) = ex x2,
1. use the Newton-Raphson method to find its approximate unique real root.
(Marks: 11)
2. with your Newton-Raphson solution, find the minimum number of iterations needed
to find a solution of f(x) = 0 to a tolerance of ⌧ = 105 with starting points
x0 = 10, 9, …4, 5. Plot the minimum number of iterations nmin against x0.
(Marks: 11)
3. use the interval bisection method to find its approximate unique real root.
(Marks: 13)