1. Ciaran Cox (1115773)
MA5605: Financial Computing 1 Assignment
0.1 Task 1: Newton’s Method
Newton’s method approximates a solution for f(x) = 0 by a series of iterations until enough accu-
racy is achieved. This sequence is computed by:
xi+1 = xi −
u(xi)
u (xi)
. for i = 0,1,2,3,...
The function in question is x5 +x−5 = 0, hence xi+1 = xi −(x5
i +xi −5)/(5x4 +1) for i ≥ 0. The
C file implemented (Appendix .1) approximates the solution to the function with 5 decimal points
of accuracy, with the user inputting the initial value of x. The C file (Appendix .2) tabulates the
iterations for initial values of x = 0 and x = 2 into a text file called ’tabulated results’, shown below.
Figure 1: tabulated results
Can see from the results in figure 1, that the same final value was achieved regardless of the initial
value of x. However the number iterations can vary depending on the initial value of x.
1
2. 0.2 Task 2: Quadrature
The N-panel composite Simpsons rule for numerical quadrature is used to approximate an integral
in a interval [a,b] of a given function u(x) by;
SN(u) : =
N
∑
i=1
(
h
6
u(xi)+
4h
6
u(xi−1
2
)+
h
6
u(xi−1))
with h := (b−a)/N and xi := a+ih, so that
SN(u) → I(u) :=
b
a
u(x)dx as N → ∞
The C program simpsons.c (Appendix .3) requests x,y and N > 0 from the user, and prints out a
double precision approximation to the following function.
f(x,y) :=
y
x
sin(t)cost(t +2)dt
Running the C file table simpsons.c (Appendix .4) tabulates the results in to a separate text file, for
N ∈ 8,16,32,64,128,256,512 with the exact error (figure 2).
Figure 2: simpsons tabulated results
As N increases the error decreases and gives a higher decimal place of accuracy.
2
3. 0.3 Task 3: Matrix algebra
Creating an N by N matrix A, with the entry in i-th row and j-th column being (i+ j)−1
. Let
y = (N,N −1,N −2,...1)T
∈ RN be a vector and define b = Ay. Then using the Gaussian elimina-
tion (without pivoting) algorithm given to solve Ax = b for x. The C file matrix.c (Appendix .5) im-
plements this and tabulates ||y−x||p
for p = 2 and p = ∞, into a text file called ’tabulated results’,
with the user’s choice of N.
Figure 3: matrix.c tabulated results
Tabulated above (Figure 3) is the output of C file matrix.c with a user input of 25. As N increases the
norms are moving away from 0, with the 2 norm diverging faster than the infinity norm. The choice
of N should not have an effect on the values of the norm, however due to computational restrictions
and decimal point accuracy, more N is increased further away from 0 the norms become.
3