Tutorial letter 201/1/2018
Numerical Methods II
APM3711
Semester 1
Department of Mathematical Sciences
IMPORTANT INFORMATION:
This tutorial letter contains important information about your
module.
BARCODE
Define tomorrow.
, ONLY FOR SEMESTER 1 STUDENTS
ASSIGNMENT 01
FIXED CLOSING DATE: 15 MARCH 2018
Unique Number: 635303
Question 1
Use the simple Euler method for the differential equation.
dy x
= , y(0) = 1,
dx y
with
(a) h = 0.2,
(b) h = 0.1
to get y(1). Compare your numerical solution with the analytical solution,
y 2 = 1 + x2 .
SOLUTION
QUESTION 1
For the simple Euler method, the algorithm is
yn+1 = yn + hf (xn , yn ) = yn + hyn′
where x0 = 0, y0 = y (0) = 1 and
x
f (x, y) = .
y
We will arrange the calculations in the form of a table with columns for xn , yn , yn′ , hyn′ . The table
will be filled one row at the time: We use xn and yn to find
yn′ = f (xn , yn ) ,
then multiply by h to get hyn′ , and add this to yn to get yn+1 for the next row.
(a) h = 0.2
2
, APM3711/201/1/2018
xn yn yn′ hyn′
0.0 1.0 0.0 0.0
0.2 1.0 0.2 0.04
0.4 1.04 0.384615384 0.076923076
0.6 1.116923077 0.537190082 0.107438016
0.8 1.224361094 0.65340201 0.130680402
1.0 1.355041496
(b) h = 0.1
xn yn y′n hy ′ n
0.0 1.0 0.0 0.0
0.1 1.0 0.1 0.01
0.2 1.01 0.198019802 0.0198019802
0.3 1.02980198 0.291318142 0.0291318142
0.4 1.058933794 0.37773844 0.037773844
0.5 1.096707638 0.455910018 0.0455910018
0.6 1.14229864 0.525256687 0.0525256687
0.7 1.194824309 0.585860192 0.0585860192
0.8 1.253410328 0.638258662 0.0638258662
0.9 1.317236194 0.683248762 0.0683248762
1.0 1.38556107
The analytical solution is
y 2 = 1 + x2
√
⇒ y = ± 1 + x2
of which only the “+” sign gives a solution to the initial value problem with y (0) = 1. So,
√
y = 1 + x2 .
√
At x = 1, this gives y (1) = 2 = 1.414213562. Let us compare our results with this:
Exact solution: 1.414213562 error
Euler with h = 0.2: 1.355041496 0.059172066
Euler with h = 0.1: 1.38556107 0.028652492
Note that halving the step size from h = 0.2 to h = 0.1 has halved the error. This is as expected,
since the global error in the Euler method is O (h), that is, proportional to h.
Question 2
Solve the differential equation given below by means of the Taylor-series expansion to get the value
of y at x = 1.1. Use terms up to x6 and ∆x = 0.1.
d2 y
2
= xy 2 − 2yy ′ + x3 + 4,
dx
y(1) = 1, y ′(1) = 2.
3
, SOLUTION
Given
dy 2
= xy 2 − 2yy ′ + x3 + 4, y (1) = 1, y ′ (1) = 2
dx2
We approximate y (1.1) by the truncated Taylor series
′ (0.1)2 ′′ (0.1)6 (6)
y (1.1) ≃ y (1) + (0.1) y (1) + y (1) + . . . + y (1) (1)
2 6!
The derivatives at x = 1 are calculated in the way illustrated on p. 453 [398] of Gerald :
′′
y (x) = xy 2 − 2yy ′ + x3 + 4,
∴ y ′′ (1) = 1 · 12 − 2 · 1 · 2 + 13 + 4 = 2
y ′′′ (x) = y 2 + 2xyy ′ − 2 (y ′)2 − 2yy ′′ + 3x2 + 4,
∴ y ′′′ (1) = 1 + 4 − 8 − 4 + 3 = −4
y (4) (x) = 2yy ′ + 2yy ′ + 2x (y ′)2 + yy ′′ − 4y ′y ′′ − 2y ′ y ′′ − 2yy ′′′ + 6x
= 2 [y (2y ′ + xy ′′ − y ′′′) + y ′ (xy ′ − 3y ′′) + 3x] ,
(4)
∴ y (1) = 2 [1 (4 + 2 + 4) + 2 (2 − 6) + 3] = 10
y (5) (x) = 2 y ′ (2y ′ + xy ′′ − y ′′′ ) + y 2y ′′ + y ′′ + xy ′′′ − y (4)
+ y ′′ (xy ′ − 3y ′′) + y′ (y ′ + xy ′′ − 3y ′′′ ) + 3]
= 2 y 3y ′′ + xy ′′′ − y (4) + y ′ (3y ′ + 3xy ′′ − 4y ′′′ ) − 3 (y ′′)2 + 3 ,
∴ y (5) (1) = 2 [1 (6 − 4 − 10) + 2 (6 + 6 + 16) − 3 (4) + 3] = 78
y (6) (x) = 2 y ′ 3y ′′ + xy ′′′ − y (4) + y 3y ′′′ + y ′′′ + xy (4) − y (5)
+ −6y ′′ y ′′′
(4)
y (3y + 3xy − 4y ) + y 3y + 3y + 3xy −4y
′′ ′ ′′ ′′′ ′ ′′ ′′ ′′′
= 2 y 4y ′′′ + xy (4) − y (5) + y ′ 12y ′′4xy ′′′ − 5y (4) + y ′′ (3xy ′′ − 10y ′′′ )
∴ y (6) (1) = 2 [1 (−16 + 10 − 78) + 2 (24 − 16 − 50) + 2 (6 + 40)] = −152
Substituting these values in (1) we get
y (0.1) ≃ −1.209381289.
The exact value, rounded to 10 significant numbers, can be calculated by adding more terms of the
Taylor series to (1) until it is clear that further addition of terms will not be alter the tenth digit.
Note that we have here calculated y ′ (0) from y (0) , y ′′ (0) from y ′ (0) , and so on. Alternatively we
could continue further to derive an expression for y ′, y ′′ etc. in terms of y and x only, as follows:
y ′ (x) = 3x + (2 + x) y,
y ′′ (x) = 3 + y + (2 + x) y ′ = 3 + y + (2 + x) (3x + (2 + x) y)
4