2.2 (a)
ENGR20005
Numerical Methods in Engineering
Workshop 2 Solutions
For a > 0, the solutions to the quadratic equation
f(x)=ax2 +(1−a)x=0 (1)
are given by
Rearranging for x gives
which suggests the fixed point form
x=0 x=a−1
a
To apply fixed point iteration to solve Eq. (1), we expand Eq. (1) to give ax2 −ax+x=0
ax(x − 1) + x = 0 x = ax(1 − x)
xi+1 = g(xi) = axi(1 − xi) (2) (b) To analyse the stability of the fixed point scheme, we compute the linear stability
of Eq. (2)
The derivative of Eq. (2) is given by
dg =a−2ax dx
To determine which root the method will converge when we vary a, we look at the absolute value of the derivatives at each root.
1
For x ̄ = 0:
For stability, we require
Or equivalently, as a > 0
|g(0)| = |a| < 1 a<1
For x ̄ = (a − 1)/a:
Stability of the method is ensured when
a−1 a−1
g a = a − 2a a = |a − 2(a − 1)| = |2 − a| < 1 (3)
A useful inequality is if x ∈ R, then
|x| < 1 ⇐⇒ −1 < x < 1
So we may write Eq. (3) as
which is equivalent to
−1 < 2 − a < 1
1 0.
Assuming that x ̸= 0, we may write
x2 − S = 0
=⇒ x2 = S
=⇒ x = Sx
=⇒ x + x = Sx + x
=⇒ x = 1 x + S 2x
Alternatively, we can derive the Babylonian method by applying the Newton–Raphson method to Eq. (5)
Thus, we have
f(x)=x2 −S f′(x) = 2x
xi+1 = xi − f(xi) f′(xi)
= x i − x 2i − S 2xi
= xi − xi + S 2 2xi
= 1xi + S 2 xi
4
2.5 For the quadratic equation
f(x)=x2 −2x−1=0 (6) (a) The roots may be determined analytically by using the quadratic formula, giving
(b) i.
ii.
iii.
√
x= 2± 22 −4×1×−1
√2 =1± 2
x2 −2x−1=0
=⇒ x2 = 1 + 2x √
=⇒x= 1+2x
x2 −2x−1=0 =⇒ 2x = x2 − 1
=⇒ x = 21(x2 − 1) x2 −2x−1=0
=⇒ x(x − 2) − 1 = 0 =⇒x= 1
x−2
(c) For an implementation of the fixed point method to solve Eq. (6) see the MAT-
LAB script Q2 5 sol.m.
(d) f(x) and f′(x) for Eq. (6) are given by
f(x)=x2 −2x−1 f′(x) = 2x − 2
Hence, applying the Newton–Raphson method gives xi+1 = xi − f(xi)
f′(xi)
= x i − x 2i − 2 x i − 1
2xi − 2 5
(e) Approximating the derivative of f using the finite difference formula df = f(xi) − f(xi−1)
dx xi − xi−1 the Newton–Raphson method may be written as
xi+1 = xi − f(xi) f′(xi)
= xi − f(xi)
f (xi )−f (xi−1 )
xi −xi−1
= xi − f(xi)(xi − xi−1)
f(xi) − f(xi−1)
Applying this to Eq. (6), we have
xi+1 =xi − (x2i −2xi −1)(xi −xi−1)
(x2i − 2xi) − (x2i−1 − 2xi−1))
(c) For an implementation of the Newton–Raphson and Secant method to solve Eq.
(6), see the MATLAB script Q2 5 sol.m.
6