COS2633 Exam 2014 s2 Memo
COS2633 Exam 2014 s2 Memo
COS2633 Exam 2014 s2 Memo
of south africa
SOLUTIONS
QUESTION 1
(1.1)
√
(a) Write the Newton formula (recurrence relation) to approximate 3 5. (3)
√
3 3 3
5 is a solution to the equation x = 5, or equivalently, x − 5 = 0. So if we apply the Newton’s
method to the function f defined by f (x) = x3 − 5, provided x0 is given, we obtain the relation
3
(xn ) − 5
(1) xn+1 = xn − 2 .
3 (xn )
(b) Perform three iterations of the Newton algorithm as given in (1.1(a)), starting at x0 = 2. (3)
Applying the formula in equation (1), we have:
Iteration 1:
3
(x0 ) − 5 23 − 5
x1 = x0 − 2 = 2 − 3(2)2 = 1.75
3 (x0 )
Iteration 2:
3
(x1 ) − 5 (1.75)3 − 5
x2 = x1 − 2 = 1.75 − = 1.7109
3 (x1 ) 3(1.75)2
Iteration 3:
3
(x2 ) − 5 (1.7109)3 − 5
x3 = x2 − 2 = 1.7109 − = 1.7100
3 (x2 ) 3(1.7109)2
x2 y2
(1.2) The ellipse defined by + = 1 and the parabola defined by y = x2 − 2x − 4 intersect at four
16 9
distinct points.
(a) Write the Newton formula (recurrence relation) in the form of a system of equations, to approxi- (6)
mate any of the intersection points.
We define
y2
2
x
F (x, y) = 16 + 9 − 1
x2 − 2x − y − 4
The Jacobian is
x 2y
JF (x, y) = 8 9
2x − 2 −1
and its inverse is
− 2y
−1 1 −1
(JF (x, y)) =−x x
9 .
8 + 49 y(x − 1) −2x + 2 8
[TURN OVER]
2 COS2633
OCTOBER/NOVEMBER 2014
(b) Perform two iterations of the Newton algorithm as given in (1.2(a)), starting with (x0 , y0 ) = (4, 1). (4)
The results are as follows:
Iteration 1: We have D0 = − x80 − 94 y0 (x0 − 1) = − 84 − 49 × 1 (4 − 1) = − 116 . Then
h 2 2
i
x y
x1 = x0 − D10 −1 160 + 90 − 1 − 2y90 x20 − 2x0 − y0 − 4
h 2 2
i
6 4
= 4 + 11 −1 16 + 19 − 1 − 29 42 − 8 − 1 − 4
= 11833 = 3.5758
2
y2
h i
x
y1 = y0 − D10 (−2x0 + 2) 160 + 90 − 1 + x80 x20 − 2x0 − y0 − 4
h 2 2
i
6 4
= 1 + 11 (−2 × 4 + 2) 16 + 19 − 1 + 84 42 − 8 − 1 − 4
16
= 11 = 1.4545
118
Iteration 2: We have D1 = − x81 − 94 y1 (x1 − 1) = − 33 4 16 118 471
− 9 × 11 33 − 1 = − 223 . Then
8
x21 y12
h i
x2 = x1 − 1
D1 −1 16 + 9 −1 − 2y91 x21 − 2x1 − y1 − 4
118 2 16 2
" ! #
32
118 223 33 11 118 2 118 16
− 1 − 11
= 33 + 471 −1 + 33 −2× 33 − 11 −4
16 9 9
717
= = 3.5320
203
2
y12
h i
x x1
y2 = y1 − D11 (−2x1 + 2) 161 + 9 −1 + 8 x21 − 2x1 − y1 − 4
118 2 16 2
" ! #
118
33 11 118 2
= 11 + 471 −2 × 118
16 223 33 118 16
33 + 2 + −1 + 33 −2× 33 − 11 −4
16 9 8
1133
= 804 = 1.4092
(c) What is the error of this process, given the fact that the exact solution is (3.5316, 1.4088)? (1)
The error of the process is
p
e = (3.5316 − 3.5320)2 + (1.4088 − 1.4092)2 = 5.6569 × 10−4
[17]
QUESTION 2
(2.1) By means of Gaussian Elimination on a larger augmented matrix A ... I where I is the identity (7)
h i
matrix of appropriate size, and by using exact calculation, find the inverse of the matrix
1 2 3
A = 2 3 4 .
3 4 1
[TURN OVER]
3 COS2633
OCTOBER/NOVEMBER 2014
.
1 2 3 .. 1 0 0
.
0 −1 −2 ..
−2 1 0 Row ← Row − 2Row
. 3 3 2
0 −2 −8 .. −3 0 1
..
1 2 3 . 1 0 0
..
0 −1 −2 . −2 1 0
Row ← 1 Row
.. 3 −4 3
0 0 −4 . 1 −2 1
..
1 2 3 . 1 0 0
.. 1
Row2 ← −1 (Row2 + 2Row3 )
0
−1 −2 . −2 1 0
..
0 0 1 . −1/4 1/2 −1/4
..
1 2 3 . 1 0 0 Row1 ← 1 (Row1 − 2Row2 − 3Row3 )
1
..
0 1 0
. 5/2 −2 1/2
..
0 0 1 . −1/4 1/2 −1/4
..
1 0 0 . −13/4 5/2 −1/4
.
0 ..
0
1 5/2 −2 1/2
..
0 0 1 . −1/4 1/2 −1/4
Therefore the inverse of A is
−13/4 5/2 −1/4
A−1 = 5/2 −2 1/2
−1/4 1/2 −1/4
(2.2) The SOR algorithm, with relaxation parameter ω for solving a linear system Ax = b is defined by the
formula
i−1 n
[k] [k−1] ω X [k]
X [k−1]
xi = (1 − ω)xi + bi − aij xj − aij xj .
aii j=1 j=i+1
(a) Perform two iterations of the SOR algorithm to solve the system (4)
1 2 x 8
=
3 1 y 9
[TURN OVER]
4 COS2633
OCTOBER/NOVEMBER 2014
ω
y1 = (1 − ω)y0 + [b2 − a21 x1 ]
a22
0.5
9 − 3 × 72
= (1 − 0.5)1 +
1
= − 14
Iteration 2:
ω
x2 = (1 − ω)x1 + [b1 − a12 y1 ]
a11
0.5
(1 − 0.5) 72 + 8 − 2 × − 41
=
1
= 6
ω
y2 = (1 − ω)y1 + [b2 − a21 x2 ]
a22
0.5
(1 − 0.5) − 14 +
= [9 − 3 × 6]
37
1
= −8
(b) Does the approach in question (2.2(a)) give the exact solution? Justify your answer. (2)
No, because it is an iterative method and it only gives closer approximations to the exact solution,
which in this case is (2, 3).
(2.3) What is the essential difference between direct and iterative methods for solving linear systems? (3)
Direct methods give exact solutions and are more suitable for small scale systems, whereas iterative
methods give approximations to the solutions and are more suitable for large scale systems.
[16]
QUESTION 3
(3.1) By means of divided differences, determine the Hermite interpolating polynomial of least degree that (7)
matches the data points.
The divided difference table is given as follows:
(3.2)
(a) Use the Least Squares method to approximate f with a function of the form kxm . (5)
[TURN OVER]
5 COS2633
OCTOBER/NOVEMBER 2014
ln y = ln k + m ln x
z = a0 + a1 ln x
which means we are fitting the new variable z as a linear combination of ln x. This yields the two
normal equations to be solved for a0 and a1
P P
(2) P N a0 + aP 1 ln xi = P ln Yi
a0 ln xi + a1 (ln xi )2 = ln xi ln Yi
a0 = 1.4903
a1 = 1.5048
k = ea0 = 4.4384
y = 4.4384x1.5048
(b) What is the sum of square errors for the approximation in (3.2(a))? (1)
X
S= (yi − kxm 2
i ) = 8.3852
(3.3) Approximate f (1.25) using each of the methods in (3.1) and (3.2). (2)
sin x
(3.4) Assuming the values in the table above are generated by the function f defined by f (x) = xex + , (2)
x
determine the absolute error of the approximation at 1.25 in each case.
• With Hermite interpolation, the absolute error is |f (1.25) − 5.1221| ≈ 1.1830 × 10−5 .
• With the kxm approximation, |f (1.25) − 6.2096| ≈ 1.0875.
[17]
[TURN OVER]
6 COS2633
OCTOBER/NOVEMBER 2014
QUESTION 4
Consider
1
(
2 x3 − 3x + 2 if 0≤x<2
S(x) = 1
3 2
2 x − 12x + 45x − 46 if 2≤x≤4
(4.1)
(a) Show that S is a cubic spline. (3)
00
S is not a natural cubic spline because S is not continuous at 2.
(b) Is it a natural cubic spline? (2)
It is not a natural cubic spline because it is not a cubic spline in the first place.
(4.2) The equation of the quadratic Bezier curve joining P0 (x0 , y0 ) to P2 (x2 , y2 ) using control point P1 (x1 , y1 )
is given by
x(t) = x0 + 2(x1 − x0 )t + (x2 − 2x1 + x0 )t2
t ∈ [0, 1] .
y(t) = y0 + 2(y1 − y0 )t + (y2 − 2y1 + y0 )t2
(a) Determine the equation of the quadratic Bezier curve joining (0, 1) to (2, 2) using 34 , 1 .
(3)
Straightforward substitution leads to
8 2 2
x(t) = 3t − 3t t ∈ [0, 1] .
y(t) = 1 + t2
8
(b) Determine the equation of the quadratic Bezier curve joining (2, 2) to (4, 3) using 3, 5 . (3)
Straightforward substitution leads to
x(t) = 2 + 43 t + 32 t2
t ∈ [0, 1] .
y(t) = 2 + 6t − 5t2
(c) Connecting the two Bezier curves gives a curve C. Is the curve C smooth at (2, 2)? Justify your (3)
answer.
No, because the points 43 , 1 , (2, 2) and 83 , 5 are not aligned. Indeed, at the end points, the
Bezier curve follows the tangent from the end point to the corresponding guide point, and the
tangents would be the same (meaning the curve would be smooth) if the points were aligned.
[14]
QUESTION 5
[TURN OVER]
7 COS2633
OCTOBER/NOVEMBER 2014
3
(c) The errors due to composite trapezoidal rule and Simpson 8 rule are respectively given by (4)
b − a 2 00 3h5 (4)
h f (ξ) and f (ξ).
12 80
Estimate the errors from the two methods used above in (5.1(a)) and (5.1(b)).
We have
1 2 2 12
f 00 (x) = + and f (4) (x) = +
x + 2 (x + 2)2 (x + 2)3 (x + 2)4
Then the error due to composite trapezoidal rule is
1 00
e1 = f (ξ)
4
3
and the error due to Simpson 8 rule is
3 (4)
e2 = f (ξ)
80
(c) From the results obtained in (5.2(a)) and (5.2(b)), estimate J by means of a three-term Gaussian (2)
quadrature.
J = c0 g(x0 ) + c1 g(x1 ) + c2 g(x2 ) = 2048
(d) Why is the result from (5.2(c)) exact? (1)
Because the n−term Gaussian quadrature has degree of precision 2n − 1, in particular the three-
term Gaussian quadrature has degree of precision 3×3−1 = 5 and we are integrating a polynomial
of degree 5.
[26]
8 COS2633
OCTOBER/NOVEMBER 2014
c
UNISA 2014