Assignment 1 - Suggested Answers 1.0 Numerical Analysis
Assignment 1 - Suggested Answers 1.0 Numerical Analysis
ASSIGNMENT
QUESTION 1
Newton’s law of cooling says that the temperature of a body changes at a rate
proportional to the difference between its temperature and that of the surrounding medium
(the ambient temperature),
dT
=−k ( T −Ta )
dt
where T = the temperature of the body (°C), t = time (min), k = the
proportionality constant (per minute), and Ta = the ambient temperature (°C).
Suppose that a cup of coffee originally has a temperature of 70 °C. Use Euler’s
method to compute the temperature from t = 0 to 20 min using a step size of 2 min if Ta =
20 °C and k = 0.019/min.
SOLUTION
dT
=−k ( T −Ta ) .
dt
We let starting time be ti. Now from 0 to 20 min using a step size of 2 min, ti can be 0, 2, 4,
6, 8, 10, 12, 14, 16, 18, and 20.
Initially at ti = 0 min, T(ti) = T (0) = 70 °C.
Also, Ta = 20 °C; k = 0.019/min; step¿ ∆t = 2 min
Using Euler’s method, New value = old value + slope × step size. We have;
T (ti + 1) = T(ti) + [-k (T - Ta)] × ∆ t
Therefore,
At i = 1, ti = 2 T (2) = 70 + [-(0.019) (70 - 20)] × 2 = 68.1 °C
I 1 2 3 4 5 6 7 8 9 10 11
ti (min) 0 2 4 6 8 10 12 14 16 18 20
T (°C) 70 68.10 66.27 64.51 62.82 61.20 59.63 58.12 56.68 55.28 53.94
QUESTION 2
A storage tank (Figure 1.7) contains a liquid at depth y where y = 0 when the tank is half
full. Liquid is withdrawn at a constant flow rate Q to meet demands. The contents are
resupplied at a sinusoidal rate 3Qsin2(t). The
mathematical expression for this system can
be written as
d ( Ay )
=3Q sin 2 ( t )=Q
dt
We let starting time be ti. Now from 0 to 10 d with a step size of 0.5 d, ti can be 0, 0.5, 1,
1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5, 9, 9.5, and 10.
Initial condition states at ti = 0 d, y(ti) = y (0) = 0.
Also, A = 1250 m2 and Q = 450 m3/d
Using Euler’s method, New value = old value + slope × step size. We have;
Q 2 450 2
y (ti + 1) = y(ti) + A ( 3 sin ( t )−1) × ∆ t = y(ti) + 1250 (3 sin ( t )−1) × 0.5
QUESTION 3
You are working as a crime scene investigator and must predict the temperature of
a homicide victim over a 5-hr period. You know that the room where the victim was found
was at 10 °C when the body was discovered.
a. Use Newton’s law of cooling (Equation (1.12) and Euler’s method to compute the
victim’s body temperature for the 5-hr period using values of k = 0.12/hr. and t =
0.5 hr. Assume that the victim’s body temperature at the time of death was 37 °C, and
that the room temperature was at a constant value of 20°C over the 5-hr period.
b. Further investigation reveals that the room temperature had actually dropped
linearly from 20 to 10 °C over the 5-hr period. Repeat the same calculation as in (a)
but incorporate this new information.
c. Compare the results from (a) and (b) by plotting them on the same graph.
SOLUTION
dT
=−k ( T −Ta )
dt
We let starting time be ti. Now from 0 to 5-hr using a step size of 0.5-hr, ti can be 0, 0.5, 1,
1.5, 2, 2.5, 3, 3.5, 4, 4.5, and 5
Initially at the time (when t = 0) of death, temperature T = 37 °C
Also, Ta = 20 °C; k = 0.12/hr.; step¿ ∆t = 0.5-hr
Now iteration equation; New value = old value + slope × step size.
T (t¿¿ i +1)=T (t¿¿ i)−k ¿ ¿ ¿× ∆ t
Therefore,
ti = 0.5 T (0.5) = 37 - 0.12 (37 - 20) × 0.5 = 35.98 °C
b. Here, the ambient temperature Ta actually dropped linearly from 20 to 10 °C over the 5-hr
period. So, we say Ta is no more constant but rather a function of time, t. Mathematically
expressed as;
Ta(t) = Ta + ∆ T /∆ t × t
Ta(t) = 20 + (10 - 20) / (5 - 0) × t
Ta(t) = 20 - 2t
Now the iteration equation become;
T (t¿¿ i +1)=T (t¿¿ i)−k ¿ ¿ ¿
34
T 35.98 35.02 34.12 33.2 32.48 31.73 31.02 30.3 29.74 29.16
33 7 6
32
(b)31
T 300.5 1 1.5 2 2.5 3 3.5 4 4.5 5
T' 2935.98 34.96 33.94 32.9 31.91 30.90 29.88 28.8 27.86 26.85
28 3 7
27
26
0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Forward difference
'
f ( x i+ 1) −f ( x i )
f ( x i )=
h
182.140625−102
'
f ( 2 )=
0.25
= 320.5625
Error
True value −Approximation value
Ɛt= ×100 %
True value
283−320.5625
Ɛt=
283
× 100 % = -13.27 %
|Ɛ t | = 13.27 %
Backward difference
'
f ( x i ) −f (x i−1)
f ( x i )=
h
102−39.859375
'
f ( 2 )=
0.25
= 248.5625
Error
True value −Approximation value
Ɛt= ×100 %
True value
283−248.5625
Ɛt=
283
× 100 % = 12.17 %
Central difference
f ( x i+ 1) −f ( x i−1)
f ' ( x i )=
2h
182.140625−39.859375
f ' ( 2 )=
2(0.25)
= 284.5625
Error
True value −Approximation value
Ɛt= ×100 %
True value
283−284.5625
Ɛt=
283
× 100 % = -0.55 %
|Ɛ t | = 0.55 %
Here, considering the difference between the true value and the various
approximated values:
For forward difference, 283−320.5625=−37.5625
¿∨37.5625∨¿
which is exactly considering the difference between the true value and the
approximated value from the centered difference computation (
283 – 284.5625=−1.5625) as expected.
QUESTION 5
Consider the function f(x) = x3 – 2x + 4 on the interval [-2, 2] with h = 0.25. Use the
forward, backward, and centered finite difference approximations for the first and second
derivatives so as to graphically illustrate which approximation is most accurate. Graph all
three first derivative finite difference approximation.
SOLUTION
f(x) = x3 – 2x + 4
f’(x) = 3x2 – 2
f’’(x) = 6x
For the interval [-2, 2] consider xi = 1.75; xi+1 = 2; xi-1 = 1.50
Now with xi = 1.75, h = 0.25
xi = 1.75
f(xi) = x3 – 2x + 4
f(xi) = f (1.75) = (1.75)3 – 2(1.75) + 4
f(xi) = 5.859375
Again, xi+1 = xi + h = 1.75 + 0.25
xi+1 = 2
f(xi+1) = (xi+1)3 – 2(xi+1) + 4
f(xi+1) = f (1.75) = (2)3 – 2(2) + 4
f(xi+1) = 8
Again, xi-1 = xi - h = 1.75 - 0.25
xi-1 = 1.50
f(xi-1) = (xi-1)3 – 2(xi-1) + 4
f(xi-1) = f (1.75) = (1.5)3 – 2(1.5) + 4
f(xi-1) = 4.375
Forward difference
f ( x i+ 1) −f ( x i )
f ' ( x i )=
h
8−5.859375
f ' ( 1.75 )=
0.25
= 8.5625
Error
True value −Approximation value
Ɛt= ×100 %
True value
7.1875−8.5625
Ɛt=
7.1875
× 100 % = -19.13 %
|Ɛ t | = 19.13 %
Backward difference
'
f ( x i ) −f ( x i−1 )
f ( x i )=
h
5.859375−4.375
'
f ( 1.75 )=
0.25
= 5.9375
Error
True value −Approximation value
Ɛt= ×100 %
True value
7.1875−5.9375
Ɛt=
7.1875
×100 % = 17.39 %
Ɛt = 17.39 %
Central difference
'
f ( x i+ 1) −f ( x i−1 )
f ( x i )=
2h
' 8−4.375
f ( 1.75 )=
2(0.25)
= 7.25
Error
True value −Approximation value
Ɛt= ×100 %
True value
7.1875−7.25
Ɛt=
7.1875
× 100 % = -0.86597 %
|Ɛ t | = 0.87 %
The above suggest that Central difference is more accurate than Forward and
Backward difference. Graphing the three differences,
' ' '
f ( xi ) f ( xi ) f ( xi )
xi f ( xi ) f ( x i−1 ) f ( x i +1) Backward Centered Forward
-2.000 0.000 -2.891 2.141 11.563 10.063 8.563
-1.750 2.141 0.000 3.625 8.563 7.250 5.938
-1.500 3.625 2.141 4.547 5.938 4.813 3.688
1.250 4.547 3.625 5.000 3.688 2.750 1.813
-1.000 5.000 4.547 5.078 1.813 1.063 0.313
-0.750 5.078 5.000 4.875 0.313 -0.250 -0.813
-0.500 4.875 5.078 4.484 -0.813 -1.188 -1.563
-0.250 4.484 4.875 4.000 -1.563 -1.750 -1.938
0.000 4.000 4.484 3.516 -1.938 -1.938 -1.938
0.250 3.516 4.000 3.125 -1.938 -1.750 -1.563
0.500 3.125 3.516 2.922 -1.563 -1.188 -0.813
0.750 2.922 3.125 3.000 -0.813 -0.250 0.313
1.000 3.000 2.922 3.453 0.313 1.063 1.813
1.250 3.453 3.000 4.375 1.813 2.750 3.688
1.500 4.375 3.453 5.859 3.688 4.813 5.938
1.750 5.859 4.375 8.000 5.938 7.250 8.563
2.000 8.000 5.859 10.891 8.563 10.063 11.563
12.000
10.000
8.000
𝑓′ (𝑥𝑖 )
6.000
4.000
2.000
0.000
-2.500 -2.000 -1.500 -1.000 -0.500 0.000 0.500 1.000 1.500 2.000 2.500
-2.000
-4.000
X values