Professional Documents
Culture Documents
Math5335 2015
Math5335 2015
• Question 5 also requires you to define a function M-file q5pdf.m, in addition to q5.m.
• Questions 1, 2, 3, and 4 are each worth 10 marks, while Question 5 is worth 15 marks.
• Each script must require no interactive input, or depend on any variables defined
outside the script. To obtain the output for Question 1, you must be able to type
>> clear
>> q1
Do not include the clear statement in your scripts q1.m, q2.m etc.
• Save all files in your home folder. Do NOT create any sub-folders.
>> what
should list the M-files gauleg.m and the MAT file q3val.mat. At the end you should
also see your M-files q1.m, q2.m, ...
1
Question 1 (10 marks): Answer in the file q1.m
Let n = 10. Consider the n × n matrix
2 0 1 0 3 0 0 0 0 0
0 2 0 1 0 3 0 0 0 0
0 0 2 0 1 0 3 0 0 0
0 0 0 2 0 1 0 3 0 0
3 0 0 0 2 0 1 0 3 0
A= −2
.
3 0 0 0 2 0 1 0 3
0 −2 3 0 0 0 2 0 1 0
0
0 −2 3 0 0 0 2 0 1
0 0 0 −2 3 0 0 0 2 0
0 0 0 0 −2 3 0 0 0 2
(d) Verify your result by computing, and then printing out, the value of the matrix
norm kA − U SV T k∞ , where U, S, V are the matrices obtained from the SV D factor-
ization.
(e) Compute the largest and smallest singular value of the singular value decomposition
storing it in the variables lsv and ssv.
(f) Compute the condition number in 2-norm of the matrix A using the singular values
of A.
(h) Solve Ax = b using the singular value decomposition of A storing the answer in the
variable xsvd.
2
(b) Construct the n by n matrix C storing only the non-zero elements (Hint: spdiags).
(d) Compute the inverse matrix C −1 using inv. In Figure 1 create a spy plot of C −1
(Hint: spy).
(e) Use the Matlab command symamd to re-order the rows and columns of C. Store the
re-ordered matrix in the variable B.
y = x1 + x2 t + x3 exp(t)
(d) Print out the values of the coefficients x1 , x2 and x3 , with at least 4 significant figures.
(e) Calculate the cubic spline that interpolates the data which has slope 0 at the first
and last data points.
(f) On the same axes, plot the data, the least-squares fit and the cubic spline interpolant
for t ∈ [0, 1]. Make sure you include a legend.
Background
A matrix C = (ci,j )1≤i,j≤n is circulant if ci,j = di−j for some values d−n+1 , d−n+2 , . . . , d−1 ,
d0 , d1 , . . . , dn−1 which satisfy di+n = di for −n < i < 0. Thus a circulant matrix is of the
form
d0 dn−1 dn−2 . . . d1
d1 d0 dn−1 . . . d2
d2 d d . . . d
C= 3 .
1 0
.. ... . . . . . . ..
. .
dn−1 dn−2 dn−3 . . . d0
3
Let y = (y0 , y1 , . . . , yn−1 )> be a vector of length n. The Fourier transform is given by
n−1
X
Fk (y) = ybk = yj e−i2πjk/n for k = 0, 1, . . . , n − 1. (1)
j=0
Matlab questions
(a) Define n = 1000.
(b) Set c = [1, 2, 3, . . . , n].
(c) Use
C = gallery(’circul’,c);
to generate a circulant matrix C. The first row of the matrix C is then the vector c.
(d) Generate a column vector of length n of standard normal random variables using the
Matlab command randn. Store this vector in the variable b.
(e) Solve the linear system Cx = b using the Matlab backslash operator and store the
solution in the vector xbs.
(f) Use the Matlab command fft to compute the Fourier transform of the vector b and
store it in the vector bfft.
(g) Define d to be the first column of the matrix C. Compute the Fourier transform of
d and store it in the vector dfft.
(h) Compute x b as given by the formula (2) using coordinate-wise division and store it in
the vector xfft.
(i) Compute the inverse Fourier transform of the vector xfft using the Matlab command
ifft and store the result in the vector x.
(j) Compute the infinity norm of xbs - x and store the result in nrmchk.
4
Question 5: Answer in the files q5pdf.m and q5.m
Consider the following distribution with real parameters µ and s > 0 with probability
density function
2π x−µ x−µ
+ sin π for µ ≤ x ≤ µ + s;
f (x) = s(4 + π) s s (3)
0 otherwise.
i) Define variables for µ = 40, s = 30, N = 80 and the interval [a, b] = [µ, µ + s].
ii) Use the Matlab function gauleg to calculate N Gauss-Legendre nodes and
weights for the interval [a, b].
iii) Use your function q5pdf to calculate the probability density function f , which
is given by (3), at the Gauss-Legendre nodes.
iv) Plot the probability density function f which is given by (3).
v) The payoff function for a put option with strike K = 50 and asset value Y is