0% found this document useful (0 votes)
127 views

Assignment 1 - Suggested Answers 1.0 Numerical Analysis

1) The document provides the solution to three numerical analysis questions using Euler's method to solve differential equations. 2) For the first question, it computes the temperature of a cup of coffee over 20 minutes using Newton's law of cooling. 3) The second question computes the depth of liquid in a storage tank over 10 days as liquid is added and withdrawn. 4) The third question estimates the temperature of a homicide victim over 5 hours using the same cooling law, first with a constant room temperature then a linearly decreasing temperature.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views

Assignment 1 - Suggested Answers 1.0 Numerical Analysis

1) The document provides the solution to three numerical analysis questions using Euler's method to solve differential equations. 2) For the first question, it computes the temperature of a cup of coffee over 20 minutes using Newton's law of cooling. 3) The second question computes the depth of liquid in a storage tank over 10 days as liquid is added and withdrawn. 4) The third question estimates the temperature of a homicide victim over 5 hours using the same cooling law, first with a constant room temperature then a linearly decreasing temperature.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

NAME: HUBERT KESSE-ADU

INDEX NUMBER: 41303518


CLASS: MN3
COURSE: 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

At i = 2, ti = 4 T (4) = 68.1 + [-(0.019) (68.1 - 20)] × 2 = 66.2722 °C


At i = 3, ti = 6 T (6) = 66.272 + [-(0.019) (66.272 - 20)] × 2 = 64.5138564 °C

At i = 4, ti = 8 T (8) = 64.5138564 + [-(0.019) (64.5138564 - 20)] × 2 = 62.82232986 °C

At i = 5, ti = 10 T (10) = 62.82232986 + [-(0.019) (62.82232986 - 20)] × 2 = 61.19508132 °C

At i = 6, ti = 12 T (12) = 61.19508132 + [-(0.019) (61.19508132 - 20)] × 2 = 59.62966823 °C

At i = 7, ti = 14 T (14) = 59.62966823 + [-(0.019) (59.62966823 - 20)] × 2 = 58.12374084 °C

At i = 8, ti = 16 T (16) = 58.12374084 + [-(0.019) (58.12374084 - 20)] × 2 = 56.67503869 °C

At i = 9, ti = 18 T (18) = 56.67503869 + [-(0.019) (56.67503869 - 20)] × 2 = 55.28138722 °C


At i = 10, ti = 20 T (20) = 55.28138722 + [-(0.019) (55.28138722 - 20)] × 2 = 53.9406945 °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

However, since the surface area, A is constant


dy Q 2 Q
=3 sin (t )−
dt A A

Use Euler’s method to solve for the depth y


from t = 0 to 10 d with a step size of 0.5 d.
The parameter values are A = 1250 m2 and Q
= 450 m3/d. Assume that the initial condition is y = 0.
SOLUTION
dy Q 2 Q Q 2
=3 sin (t )− = ( 3 sin ( t )−1)
dt A A A

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

Therefore, y (ti + 1) = y(ti) + 0.36(3sin2(ti) - 1) × 0.5


At i = 1, ti = 0 y (0) = 0 + 0.36(3sin2(0) - 1) × 0.5 = -0.18
At i = 2, ti = 0.5 y (0.5) = -0.18 + 0.36(3sin2(0.5) - 1) × 0.5 = -0.2358816226
At i = 3, ti = 1 y (1) = -0.2358816226 + 0.36(3sin2(1) - 1) × 0.5 = -0.03352197673
At i = 4, ti = 1.5 y (1.5) = -0.03352197673 + 0.36(3sin2(1.5) - 1) × 0.5 = -0.3237759973
At i = 5, ti = 2 y (2) = -0.3237759973 + 0.36(3sin2(2) - 1) × 0.5 = 0.590259775
At i = 6, ti = 2.5 y (2.5) = 0.590259775 + 0.36(3sin2(2.5) - 1) × 0.5 = 0.6036709849
At i = 7, ti = 3 y (3) = 0.6036709849 + 0.36(3sin2(3) - 1) × 0.5 = 0.4344250075
At i = 8, ti = 3.5 y (3.5) = 0.4344250075 + 0.36(3sin2(3.5) - 1) × 0.5 = 0.3208713988
At i = 9, ti = 4 y (4) = 0.3208713988 + 0.36(3sin2(4) - 1) × 0.5 = 0.450156408
At i = 10, ti = 4.5 y (4.5) = 0.450156408 + 0.36(3sin2(4.5) - 1) × 0.5 = 0.7861615787
At i = 11, ti = 5 y (5) = 0.7861615787 + 0.36(3sin2(5) - 1) × 0.5 = 1.102710892
At i = 12, ti = 5.5 y (5.5) = 1.102710892+ 0.36(3sin2(5.5) - 1) × 0.5 = 1.191515953
At i = 13, ti = 6 y (6) = 1.191515953+ 0.36(3sin2(6) - 1) × 0.5 = 1.053675384
At i = 14, ti = 6.5 y (6.5) = 1.053675384+ 0.36(3sin2(6.5) - 1) × 0.5 = 0.8986647532
At i = 15, ti = 7 y (7) = 0.8986647532 + 0.36(3sin2(7) - 1) × 0.5 = 0.9517457043
At i = 16, ti = 7.5 y (7.5) = 0.9517457043+ 0.36(3sin2(7.5) - 1) × 0.5 = 1.246861441
At i = 17, ti = 8 y (8) = 1.246861441+ 0.36(3sin2(8) - 1) × 0.5 = 1.5954295
At i = 18, ti = 8.5 y (8.5) = 1.5954295 + 0.36(3sin2(8.5) - 1) × 0.5 = 1.759723602
At i = 19, ti = 9 y (9) = 1.759723602 + 0.36(3sin2(9) - 1) × 0.5 = 1.671438091
At i = 20, ti = 9.5 y (9.5) = 1.671438091 + 0.36(3sin2(9.5) - 1) × 0.5 = 1.494487844

At i = 21, ti = 10 y (10) = -0.18 + 0.36(3sin2(10) - 1) × 0.5 = 1.474305687

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

a. To employ Euler’s method. We have;


T ( t¿¿ i)
T (t¿¿ i +1)− ¿¿
(t ¿ ¿ i+1−t i )=−k ¿ ¿

T (t¿¿ i +1)−T (t¿¿ i)=−k ¿ ¿ ¿

T (t¿¿ i +1)=T (t¿¿ i)−k ¿ ¿ ¿

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

ti = 1 T (1) = 35.98 - 0.12 (35.98 - 20) × 0.5 = 35.0212 °C

ti = 1.5 T (1.5) = 35.0212 - 0.12 (35.0212 - 20) × 0.5 = 34.119928 °C

ti = 2 T (2) = 34.119928 - 0.12 (34.119928 - 20) × 0.5 = 33.27273232 °C

ti = 2.5 T (2.5) = 33.27273232 - 0.12 (33.27273232 - 20) × 0.5 = 32.47636838 °C

ti = 3 T (3) = 32.47636838 - 0.12 (32.47636838 - 20) × 0.5 = 31.72778628 °C

ti = 3.5 T (3.5) = 31.72778628 - 0.12 (31.72778628 - 20) × 0.5 = 31.0241191 °C

ti = 4 T (4) = 31.0241191 - 0.12 (31.0241191 - 20) × 0.5 = 30.36267196 °C

ti = 4.5 T (4.5) = 30.36267196 - 0.12 (30.36267196 - 20) × 0.5 = 29.74091164 °C

ti = 5 T (5) = 29.74091164 - 0.12 (29.74091164 - 20) × 0.5 = 29.15645694 °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 ¿ ¿ ¿

T (t¿¿ i +1)=T (t¿¿ i)−k ¿ ¿ ¿

T (t¿¿ i +1)=T (t¿¿ i)−k ¿ ¿ ¿

Therefore using T (t¿¿ i +1)=T (t¿¿ i)−k ¿ ¿ ¿ but at ti = 0, T(ti) = 37 °C

ti = 0.5 T (0.5) = 37 - 0.12 [37 + 2(0) – 20] × 0.5 = 35.98 °C

ti = 1 T (1) = 35.98 - 0.12 [35.98 + 2(0.5) – 20] × 0.5 = 34.9612 °C

ti = 1.5 T (1.5) = 34.9612 - 0.12 [34.9612 + 2(1) – 20] × 0.5 = 33.943528 °C

ti = 2 T (2) = 33.943528 - 0.12 [33.943528 + 2(1.5) – 20] × 0.5 = 32.92691632 °C

ti = 2.5 T (2.5) = 32.92691632 - 0.12 [32.92691632 + 2(2) – 20] × 0.5 = 31.91130134 °C

ti = 3 T (3) = 31.91130134 - 0.12 [31.91130134 + 2(2.5) – 20] × 0.5 = 30.89662326 °C

ti = 3.5 T (3.5) = 30.89662326 - 0.12 [30.89662326 + 2(3) – 20] × 0.5 = 29.88282586 °C

ti = 4 T (4) = 29.88282586 - 0.12 [29.88282586 + 2(3.5) – 20] × 0.5 = 28.86985631 °C

ti = 4.5 T (4.5) = 29.88282586 - 0.12 [29.88282586 + 2(4) – 20] × 0.5 = 27.85766493 °C

ti = 5 T (5) = 27.85766493 - 0.12 [27.85766493 + 2(4) – 20] × 0.5 = 26.84620504 °C

c. Tabular form of answers at (a) and (b)

(a)36 Chart Title


35
T 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Temperature (°C)

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

(a) T (°C) (b) T' (°C) time (hr)


QUESTION 4

Use forward and backward difference approximations of O (h) and a centered


difference approximation of O (h2) to estimate the first derivative of the function
f(x) = 25x3 – 6x2 – 7x - 88
Evaluate the derivative at x = 2 using a step size of h = 0.25. Compare your results
with the true value of the derivative. Interpret your results on the basis of the
remainder term of the Taylor series expansion
SOLUTION

f(x) = 25x3 – 6x2 + 7x - 88


but x = 2 and;
f’(x) = 75x2 – 12x + 7
f’ (2) = 75(2)2 – 12(2) + 7
f’ (2) = 283
Now with xi = 2, h = 0.25
xi = 2
f(xi) = 25x3 – 6x2 + 7x - 88
f(xi) = f (2) = 25(2)3 – 6(2)2 + 7(2) - 88
f(xi) = f (2) = 102
Again, xi + h = xi+1 = 2 + 0.25
xi+1 = 2.25
f(xi+1) = 25(xi+1)3 – 6(xi+1)2 + 7(xi+1) – 88
f(xi+1) = f (2.25) = 25(2.25)3 – 6(2.25)2 + 7(2.25) – 88
f(xi+1) = 182.140625
Again, xi - h = xi-1 = 2 - 0.25
xi-1 = 1.75
f(xi-1) = 25(xi-1)3 – 6(xi-1)2 + 7(xi-1) – 88
f(xi-1) = f (1.75) = 25(1.75)3 – 6(1.75)2 + 7(1.75) – 88
f(xi-1) = 39.859375

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∨¿

For backward difference, 283−248.5625=34.4375


Now, comparing individual values, 36 is close but not exact.

For centered difference,


'''
−f ( x i ) 2
|Ɛ t | = h, but f '' ' ( x i)=150
6
−150 2
|Ɛ t | = 6
( 0.25) =−1.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

Compute the first derivation of the function f(x) = x3 – 2x + 4


f’(x) = 3x2 – 2
but xi = 1.75
f’ (1.75) = 3(1.75)2 – 2
f’ (1.75) = 7.1875

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

First Definite Derivative Approximations f'(x) - Backward


f'(x) - Centered
f'(x) - Forward
14.000

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

You might also like