You are on page 1of 21

Numerical methods 

In  this  course  there  are  many  cases  where  you  will  need  to  find  the  solution  of  a  differential 
equation. Previously you will have come across simple differential equations such as; 

dy 
= y ' = - k r  × y 2  (1) 
dx

These simple equations can be solved easily. 

dy 
= y ' = - k r  × y 2 
dx
dy 
= - kr  × dx 
y 2 
y 1 
1  x 1 
òy 2 
dy = - kr  ò  dx 
x 0 
y 0 

which has the solution 

1 1 
- = kr  × ( x1 - x 0 )  (2) 
y1 y0 

Therefore given any four pieces of information (e.g. y0, y1  and k and x0) we can determine the fifth 
(e.g.  x1).  As  we increase  the complexity  of the system  direct  integration  becomes  problematic and 
alternative methods are necessary to solve such problems. 

Numerical methods for integration 

As stated above the evaluation of a definite integral such as 

ò f ( x) dx (3) 


by  formal  methods  is  often  difficult  or  impossible,  even  if  the  function  f(x)  has  a  relatively  simple 
analytical form. For such cases, and for the more general integration problem where we have a few 
values  of  f(x)  available  at  distinct  base‐points  arguments  xi,  i=0,  1,…,n,  some  other  approach  is 
required. An obvious alternative is to find a function g(x) that is both a suitable approximation of f(x) 
and simple to integrate formally. Then Eq. (3) can be estimated as 

ò g ( x ) dx (4) 


One possibility is to apply interpolation polynomials to the known points of the function, and  then 
carry  out  the  integration  of  the  polynomials.  In  the  figure  below,  such  a  procedure  is  illustrated. 
Here,  the  function  f(x)  is  shown  by  the  solid  curve,  and  some  discrete  points  at  equally  spaced
intervals are indicated by dots. Now, if we apply a polynomial to the discrete points, we may come 
up with an approximation of the function f(x) indicated by the dashed curve. 

Note that even though the polynomial fits exactly at the 5 discrete points, the area under the dashed 
line  will  not  be  the  same  as  the  area  under  the  solid  line.  However,  often  a  positive  error  in  one 
segment may cancel a negative error in another segment, so that the total error may be small. This is 
why integration often is called a smoothing process. Text books on numerical integration often focus 
on  formulas  for  approximation.  This  is  not  surprising  since  there  are  so  many  possibilities  for 
selecting  the  degree  of  interpolation  polynomial,  spacing  between  points,  and  location  of  points. 
Normally,  we  classify  the methods into two groups,  one  that  uses equally  spaced points  (Newton‐ 
Cotes formulas), and another that uses unequally spaced points (Gaussian quadrature formulas). We 
will  consider  some  of  the  simplest  and  most  common  methods  in  the  first  group,  namely  the 
trapezoidal method and the Simpson’s formula. 

Trapezoidal formula 

The method is illustrated in the figure below. Here, the exact function, f(x), is indicated by the solid 
line,  and  the  first  order  polynomial  approximation  (straight  line)  is  indicated  by  the  dashed  line, 
passing through two points on the function, at x0  and x1.
The equation for a straight line is of course 

y = mx + C

Which for the notation used in the figure above at the point (x0, f(x0)) becomes 

f ( x1 ) - f ( x 0 ) 
f ( x0 ) = × x0  + C 
x1 - x0 
f ( x1 ) - f ( x 0 ) 
\ C = f ( x0 ) - × x 0 
x1 - x0 

Therefore we can write the equation of the line p1(x) as 

æ f ( x1 ) - f ( x0 ) ö é f ( x1 ) - f ( x 0 )  ù
p1 ( x) = ç ÷ × x + ê f ( x0 ) - × x 0 ú
è x1 - x0 ø ë x1 - x0  û 

Which simplifies to;

( x - x 0  )
p1 ( x) = f ( x0 ) + [ f ( x1 ) - f ( x o ) ] (5) 
( x1 - x0 ) 
Integration of this approximation of the curve may then be carried out 

x x 
b  1
ìï

( x - x 0  ) üï
òa f ( x ) dx » p
òx 1 ( x ) dx = ò  í f ( x0 ) + [ f ( x1 ) - f ( xo ) ] ý dx 
0 x  î

ï ( x1 - x 
0  ) ïþ (6) 

= ( x1 - x0 ) [ f ( x1 ) + f ( x0 ) ] 

Now, consider the integration over a series of intervals, as illustrated with 5 intervals in the figure 
below. The function is approximated with straight lines between pairs of points.
We may apply Eq. (6) to each sub‐interval, and take the sum of the sub‐areas to get the total area 
under the function from a to b: 


Ai = ( xi - xi-1 ) [ f ( xi ) +  f ( xi -1 ) ]  (7) 

b  n
1  n 
ò f ( x )dx » å Ai = i =1
å ( xi - xi-1 ) [ f ( xi ) + f ( xi -1 ) ] 
2  i =1 
(8) 

Simpson’s formula 

Simpson’s  formula is  similar to the trapezoidal  rule in dividing  the total interval into many  smaller 


intervals  and  approximating  the  area  under  them,  but  different  in  that  it  fits  a  parabola  to  three 
points  of  two  adjoining  intervals.  Thus,  in  the  figure below  is  shown  two  sub‐intervals  with  three 
points that the second order polynomial p2(x) is fitted to. 

The Simpson’s formula may then be derived as: 
a + 2 h 

ò  f ( x) dx » [ f (a ) + 4 f (a + h) + f (a + 2h) ]  (9) 
a  3 

For  an  integration  interval  [a,b],  subdivided  into  n  intervals,  as  illustrated  with  6  intervals  in  the 
figure below, a parabola is fitted to pairs of intervals.
The total integral over the 6 intervals, by application of Eq. (9) three times, is 



ò f ( x)dx » 3 [ f (a) + 4 f ( x ) + f ( x  ) ]

1 2 


+ [ f ( x2 ) + 4 f ( x3 ) + f ( x 4 ) ]


+ [ f ( x4 ) + 4 f ( x5 ) + f (b ) ]


= é f (a ) + 4 ( f ( x1 ) + f ( x3 ) + f ( x5 ) ) + 2 ( f ( x2 ) + f ( x4 ) ) + f (b) ùû
3 ë

In general, for n intervals, Simpson’s formula becomes: 

h é f ( a ) + 4 ( f ( a + h ) + f ( a + 3h ) + .... + f (b - h ) ) ù


ò f ( x ) dx » ê
3 ëê +2 ( f ( a + 2 h) + ... + f (b - 2 h ) ) + f (b ) 
ú
a  ûú (10) 

where the interval length h=(b‐a)/(n). 

Example: 

Apply both the Trapezoidal and Simpson’s rule to determine the time taken (t) to decrease the value 


of x from an initial value of 10 to a final value of 1 when  t0  = 0 for the following rate equation. 

dx 
= -0.3 × x 2 
dt

Solution: 

Rearranging this rate equation and integrating the right side with respect to t gives us



1
ò -0.3 x  2 
= t 
10 


\ f ( x ) =
-0.3 x 2 

You can now solve this equation for 7 steps or 6 intervals as follows 

Steps  7  = 6  intervals 


h  ‐1.5 

x  f(x)  Trapezoidal  Simpson's 


‐ 
x0=xa  10  0.03333  ‐0.0333333 
‐ 
x1  8.5  0.04614  0.059602076  ‐0.1845444  4f(x) 
‐ 
x2  7  0.06803  0.085622484  ‐0.1360544  2f(x) 
‐ 
x3  5.5  0.11019  0.133665036  ‐0.4407713 
‐ 
x4  4  0.20833  0.238894628  ‐0.4166667 
‐ 
x5  2.5  0.53333  0.55625  ‐2.1333333 
‐ 
x6=xb  1  3.33333  2.9  ‐3.3333333 

Total  3.974034225  3.33901842 

From Eq (2) the correct answer is 3 which indicates a rather large error in the solution. You should 
notice in the solutions for f(x) the large difference in the final two values i.e. those at x5  and x6. This 
is  plotted in the accompanying  Excel  file  (integration.xlsx).  If this  problem  was  solved between  10 
and 4 the correct solution would yield 0.5 while the Trapezoidal and the Simpson’s rule give 0.508 
changes. In such cases either the number of steps can be increased or the problem can be split e.g. 
integrate from 10 to 4 and then from 4 to 1. 

Numerical methods for differentiation 

Apart from integration we will often need to solve differential equations such as; 

dy 
= y ' =  f ( x, y ) 
dx

One of the simplest methods for approximating a solution for such problems is shown in the figure 
below;
p 3 (x) 
(x 0 ,y 0 ) 
(x 1 ,y 1 ) 

(x 2 ,y 2 ) 
y=f(x) 
Slope = 
Dy  ( y1 - y 0 ) 
=
Dx ( x1 - x0 ) 
(x 3 ,y 3 ) 

(x 3 ,y true )

Here we can see a curve which represents the relationship between x and y. This curve can either be 


described by a direct function which relates y to x i.e. y = f(x) or by a function which relates the slope 
to either x or y. In chemical kinetics the latter is common as the rate of reaction (i.e. the change in 
concentration  of a species  with respect  to  time)  is  often given  as a function  of  concentration.  For 
example a simple first order reaction would have the rate; 

dC A 
= - kr C A 
dt

Where CA  = concentration of species A and kr  = reaction rate constant. 

An  approximation  of  the  above  curve  is  also  shown  whereby  we  have  used  the  slope  at  position 
(x0,y0)  to  find  (x1,y1).  We  can  then  use  this  point  to  recalculate  the  slope  and  find  (x2,y2).  This 
procedure can be repeated until we find the final position i.e. (x3,y3). Therefore, if we know the initial 
conditions  we  can move  forward in finite  difference  steps until  the final  condition  is  reached.  The 
final value of y, i.e. y3  however is different from the real value of y at this x position. 

The slope at position (x0,y0) is determined from the rate equation (as rate = slope) 

dy  ( y - y  ) 
= f ( x0 , y 0 ) = 1 0 
dx ( x1 - x0 )  (11) 

We can therefore rearrange this equation to find the value of y1  i.e. 

y1 = y0 + f ( x0 , y0 ) × ( x1 - x0 ) 

Rewriting to a more general form gives us 

yi +1  = yi + f ( xi , yi ) × Dx 


xi +1  = xn  + Dx 
Dx = ( xi +1  - xi )  (12) 
This is more commonly known as Euler’s method. In order to increase the accuracy of this technique 
an improved method for determining the slope can be used. The forth order Runge‐Kutta method is 
one of the most widely used approaches for such problems. For a differential of the form; 

dy 
= y ' = f ( x, y ) 
dx
y ( x0 ) = y0 

The values of yn+1  and xn+1  are calculated using the following equations; 


yi +1 = yi  + ( Dy1 + 2Dy2 + 2 Dy3 + Dy 4  ) 

xi +1  = xi  + D x (13) 

Where 

Dy1  = Dx × f ( xi , y i ) 
æ Dx  Dy  ö
Dy2  = Dx × f ç xi + , y i  + 1  ÷
è 2 2  ø
æ Dx  Dy  ö (14) 
Dy3  = Dx × f ç xi + , y i  + 2  ÷
è 2 2  ø
Dy4 = Dx × f ( xi + Dx, yi  + Dy3 ) 

Thus in this case, the next value (yi+1) is determined by the present value (yi) plus the product of the 
size of the interval (Δx) and a weighted average of slope: 

·  Δy1  is the slope at the beginning of the interval; 
·  Δy2  is the slope at the midpoint of the interval, using slope Δy1; 
·  Δy3  is again the slope at the midpoint, but now using the slope Δy2  to determine the y‐value; 
·  Δy4  is the slope at the end of the interval, with its y‐value determined using Δy3. 

Dy1 + 2Dy2 + 2 Dy3 + Dy 4 


slope = 
6  (15) 

Example: 

For the rate equation; 

dy 
= -0.3 × y 2 
dx

Calculate y(x) for the range 0 to 3 using a step size of Δx = 0.2 when y(0) = y0  = 10. 


See (Differenciation.xlsx) to see both methods. 

Euler’s method 

Eq. 12 becomes; 

yi +1  = yi + 0.2 × ( -0.3 × y i 2 ) 


xi +1  = xi  + 0.2 

Solving this gives the following results; 

I  X  yi  yi+1 
0  0  10  4 
1  0.2  4  3.04 
2  0.4  3.04  2.485504 
3  0.6  2.485504  2.11484 

Runge‐Kutta 

Since our problem only has y this simplifies Eq. 14 to 

(
Dy1  = 0.2 × -0.3 × y n 2  )

æ æ Dy 1  ö ö
Dy2  = 0.2 × ç -0.3 × ç y n  + ÷ ÷
ç è 2  ø ÷ø
è

æ æ Dy 2  ö ö
Dy3  = 0.2 × ç -0.3 × ç y n  + ÷ ÷÷
ç è 2  ø ø
è
(
Dy4 = 0.2 × -0.3 × ( yn  + D y3 )


and 


yn +1 = yn  + ( Dy1 + 2Dy2 + 2 Dy3 + Dy 4 ) 

xn +1  = xn  + 0.2 

The above procedure can then be applied to the problem which yields the following results. 

I  X  yi  Δy1  Δy2  Δy3  Δy4  yn+1 


‐  ‐ 
0  0  10  ‐6  ‐2.94  4.36565  1.90475  6.247323 
‐  ‐  ‐  ‐ 
1  0.2  6.247323  2.34174  1.54622  1.79802  1.18778  4.544323 
‐  ‐  ‐  ‐ 
2  0.4  4.544323  1.23905  0.92424  0.99986  0.75379  3.570814
A  comparison of both methods against  the real  solution  shows  the superiority  of the Runge‐Kutta 
method. 

Comparison of each method 
12 

10 

8  Real 
RK

Simple


0  0.5  1  1.5  2  2.5  3 

Extension of numerical methods for solving systems of ordinary differential equations. 

Consider the sequential reaction 

A ® B ® C 

If  each  of  these  reactions  was  elementary  then  we  could  state  that  the  following  three  rate 
equations apply. 

dA 
= - k1  × A 
dt
dB 
= k1 × A - k2  × B 
dt
dC 
= k2  × B 
dt

Hence  three  equations  are  used  to  describe  the  system  and  each  of  these  must  be  determined 
simultaneously to solve the problem. This is a series of ordinary differential equations (ODEs) and in 
this section we will show how the numerical methods described above can be used in such cases. 
For the general case we will consider two coupled ODE’s; 

dy 
= y ' = f ( x, y , z ) 
dx
dz 
= z ' =  g ( x, y , z ) 
dx (16) 

Euler’s method then becomes 

yi +1  = yi + f ( xi , yi , zi ) × Dx 


zi +1  = zi + g ( xi , yi , zi ) × Dx 
xi +1  = xn  + D x (17) 

These  equations  are  solved  simultaneously  using  the  current  values  of  x,  y  and  z  to  generate  the 
solution at the next interval. 

Similarly the Runge‐Kutta method extends to; 


yi +1 = yi  + ( Dy1 + 2Dy2 + 2 Dy3 + Dy 4 )


zi +1 = zi  + ( Dz1 + 2Dz 2 + 2 Dz3 + Dz 4 ) 

xi +1  = xi  + D x (18) 

where 

Dy1  = Dx × f ( xi , yi , z i ) 
Dz1  = Dx × g ( xi , yi , z i ) 

æ Dx  Dy Dz  ö
Dy2  = Dx × f ç xi + , yi + 1 , z i  + 1  ÷
è 2 2 2  ø
æ Dx  Dy Dz  ö
Dz 2  = Dx × g ç xi + , yi + 1 , z i  + 1  ÷
è 2 2 2  ø

æ Dx  Dy Dz  ö
Dy3  = Dx × f ç xi + , yi + 2 , z i  + 2  ÷
è 2 2 2  ø
æ Dx  Dy Dz  ö
Dz3  = Dx × g ç xi + , yi + 2 , z i  + 2  ÷
è 2 2 2  ø

Dy4 = Dx × f ( xi + Dx, yi  + Dy3 , zi  + Dz 3 )


Dz 4 = Dx × g ( xi + Dx, yi + Dy3 , zi  + D z3 ) 
(19)
Example: 

Consider the following system of two coupled ODE’s 

dy 
= y ' = z, y (0) = y 0 = 0 
dx
dz 
= z ' = 4 y, z (0) = z 0  = 50 
dx

Determine the value of y(1) and z(1) using both Euler’s and Runge‐Ketta methods using a step size of 


0.25. 

Solution: Euler’s method becomes 

yi +1  = yi  + z × 0.25 


zi +1  = zi  + 4 × y × 0.25 
xi +1  = xn  + 0.25 

Runge‐Kutta method becomes 


yi +1 = yi  + ( Dy1 + 2Dy2 + 2 Dy3 + Dy 4 )


zi +1 = zi  + ( Dz1 + 2Dz 2 + 2 Dz3 + Dz 4 ) 

xi +1  = xi  + D x

where 

Dy1  = Dx × z 
Dz1  = Dx × 4 × y 

æ Dz  ö
Dy2  = Dx × ç z i  + 1  ÷
è 2  ø
æ Dy  ö
Dz2  = Dx × 4 × ç y i  + 1  ÷
è 2  ø

æ Dz  ö
Dy3  = Dx × ç z i  + 2  ÷
è 2  ø
æ Dy  ö
Dz3  = Dx × 4 × ç y i  + 2  ÷
è 2  ø

Dy4 = Dx × ( zi  + Dz 3 )


Dz4 = Dx × 4 × ( yi  + Dy3 ) 
Calculating the above gives (ODEs.xlsx) 

Euler’s Method 
i  X  yi  zi 
0  0  0  50 
1  0.25  12.5  50 
2  0.5  25  62.5 
3  0.75  40.625  87.5 
4  1  62.5  128.125 

Runge‐Kutta 
i  X  yi  zi 
0  0  0  50 
1  0.25  13.02083  56.38021 
2  0.5  29.36469  77.13793 
3  0.75  53.19975  117.5693 
4  1  90.60526  187.988 

Again the Runge‐Kutta method gives the more correct result. 

Solving ODE’s in Matlab 

Matlab has a number  of functions  built in which can solve  ODE’s.  For example the function  ode45 


uses a version of the 4 th  order Runge‐Kutta method described above. The ode45 function requires at 
least 3 input arguments. The first is the list of differential equations, the second is the range along 
the x axis and the third is the initial starting conditions. An example of a Matlab m‐file for solving the 
above problem is given below; 

% Simple example of using ODE45 
function [C]=ODEexample; 

xspan = [0:0.25:1];  % x increment 
C0 = [0;50];  % initial vlaues 

[x,C]=ode45(@f,xspan,C0);  % solve the problem 
plot(x,C(:,1),'r­',x,C(:,2),'b­');  % plot the solution 

%­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 
function dydx = f(x,C) 

dydx = [C(2) 
4*C(1)];  % individual rate equations 
%­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ 

You can see the three input arguments i.e. 

·  xspan = [0:0.25:1];  i.e. (0, 0.25, 5, 0.75, 1)
·  C0 = [0; 50];  i.e. y0, z0 
·  dydx = [C(2) ; 4*C(1)];  i.e. z and 4y 

More information on using ode45 can be found in the file “usingode45.pdf”. 

Converting an n th  order ODE to a system of n first order ODE’s 

Consider the following second order ODE and initial conditions; 

d 2 y dy 

+ A( x) + B ( x) y + C ( x ) = 0 
dx dx

Where y(x0) = a 

dy 
= b 
dx x 0 

In the above equation we can make the following substitution: 

dy 
z = 
dx

Then the differential becomes 

dz 
+ A( x ) z + B ( x ) y + C ( x ) = 0 
dx

Rearranging both equations, we obtain 

dz 
= - A( x ) z - B ( x) y - C ( x ) 
dx
dy 
=  z 
dx

Where z(x0) = b and y(x0) = a. 

Now the second order ODE has been converted into a set of two coupled first order ODE’s which can 
be integrated using the previously described methods. 

Example: 

The differential equations which describe the trajectory of an object are:
2 2 
d 2 x dx æ dx ö æ dy ö
m 2  = - k  ç ÷ +ç ÷
dt dt è dt ø è dt  ø
2 2 
d 2 y dy æ dx ö æ dy ö
m 2  = - k ç ÷ + ç ÷ - ma g 
dt dt è dt ø è dt ø 

Using the initial conditions;

ì x = 0 
ï y = 3( m ) 
ï
ï
t  = 0 í dx  = V0  cos q (ms -1 ) 
ï dt 
ï dy  -1 
ï = V0  sin q (ms  ) 
î dt

Convert the trajectory equations into a system of first order ODE’s 

Solution 

Let

dx 
z 1  =
dt 
dy 
z 2  = 
dt

Then the equations become 

dz 1  k  2 2 
= - z1 ( z1 ) + ( z 2  )
dt m 
dz 2  k  2 2 
= - z2 ( z1 ) + ( z2  )  - ma g 
dt m 
dx 
= z 1 
dt 
dy 
=  z 2 
dt

Using the initial conditions would allow us to solve the problem. 

Initial value Partial differential equations 

Linear initial value partial differential equations are often encountered in chemical engineering 
problems. These equations are of the form;
¶ 2Y ¶ 2Y ¶ 2 Y æ ¶Y ¶Y  ö
A 2
+ B + C 2 
= f ç x, y , Y , ,  ÷ (20) 
¶x ¶x¶y ¶y è ¶x ¶y ø 

For example consider the temperature distribution through a solid wall. Initially the wall has a 
uniform temperature equal to that of the outside environment, T0. Then at some time, the inside 
wall is raised to Ti. Over time a temperature distribution through the wall is reached as shown in the 
figure below. 

Temp profile 
T i 
@ t = ¥ 

Temp profile 
@ 0 < t < ¥ 
T 0 
0  L 

The energy balance on a differential element inside the wall is given as; 

¶T ¶ 2 T 
r C p  = k  2  (21) 
¶t ¶ x

Where r is the density, Cp  is the heat capacity, k is the thermal conductivity of the wall, T is the local 


temperature, and x indicates the location inside the wall. The initial conditions can be written as 

t = 0;  T = T0  for 0 £ x £ L 

and the boundary conditions are given by 

T = T0  at x =0  for t > 0 

T = T1  at x = L  for t >0 

Note that the temperature is a function of time (t) and the spatial location (x); i.e., there are two 
independent variables. Therefore, the differential equation is a partial differential equation. 

Several methods are available for solving such problems. Here we will use one of the simplest which 
is known as the explicit method. 

f(x i+1 )
f(x i ) 
f(x i‐1 ) 

Δx  Δx 

x i‐1  x i  x i+1 


We have shown previously that the forward difference slope at xi  is given as 

¶y  f ( xi +1 ) - f ( x i ) 


= f '( x i ) = (22) 
¶x x i  D x

The second derivative can then be calculated as; 

f ( xi ) - 2 f ( xi +1 ) + f ( x i + 2 ) 
f ''( x i ) = (23) 
D x 2 

We will not go into the proof here but higher orders of Δx approximations are more accurate. In this 
case the central derivatives become; 

f ( xi +1 ) - f ( x i -1 ) 
f '( x i ) =
2 D x

f ( xi +1 ) - 2 f ( xi ) + f ( x i -1 ) 
f ''( x i ) = (24) 
D x 2 

Using the above we can represent the problem 

¶T k ¶ 2 T 
= as a two dimensional grid with finite Δx and Δt axis as shown. 
¶t r C p  ¶ x 2 

Node values along 
here are unknown

Node values along 
here are known 
Δt  j th  location 

Δx 
i th  location 

Specified initial conditions 

Specified boundary conditions 

The lines along the x axis represent x0, x1, …, xi, xi+1  etc, while those along the t axis are t0, t1, …, tj, tj+1 
etc. Each node (i.e. the points where the lines cross) represent a temperature at that point i.e. Ti,j. 
The points Ti‐1,j  , Ti,j  , Ti+1,j  and Ti,j+1 are also marked in the above figure. 

¶T  Ti +1, j - T i -1, j 


= (25) 
¶x T i , j  2 D x
¶ 2 T  Ti +1, j - 2 Ti , j + T i -1, j 
2
= (26) 
¶x T  D x 2 
i , j 

And the first order time derivative is given by the forward difference approximation; 

¶T  Ti , j +1 - T i , j 


= (27) 
¶t T i , j  D t

Putting these approximations into our equation gives 

Ti , j +1 - Ti -1, j k  Ti +1, j - 2 Ti , j + T i -1, j 


=
Dt r C p  D x 2 

Which we can rearrange to give; 

k Dt 
Ti , j +1 = Ti , j + (T - 2 Ti, j + T i -1, j  ) 
r C p D x 2  i +1, j
(28) 

Hence if the nodes along the j th  line are known as well as the boundary conditions then all the other 


values can be calculated. 

Example: 

Consider the above heat transfer problem where 

¶T m 2 ¶ 2 T 
= 0.005  and 
¶t s ¶ x 2 

T(x,0) = T0  = 0  i.e. temp along the left wall = 0 

T(0,t)=T0= 0  i.e. initial temp profile at t = 0 

T(L,t) = TL  = 25  i.e. temp along the right wall = 25 

L = 0.5 

Determine the temperature profile through the wall at t = 2, 4, 6, 8, and 10 s. 

Solution: 

0.005 m 2  Dt 
Ti , j +1 = Ti , j +
s D x 2 
(Ti +1, j - 2 Ti, j + T i-1, j ) 
Using the initial conditions we can set up an Excel spreadsheet to solve the equation for each of the 
times specified.
Δx  0.0625 
Δt  0.25 

Time  0  0.0625  0.125  0.1875  0.25  0.3125  0.375  0.4375  0.5 
0  0  0  0  0  0  0  0  0  25 
0.25  0  0  0  0  0  0  0  8  25 
0.5  0  0  0  0  0  0  2.56  10.88  25 
0.75  0  0  0  0  0  0.8192  4.4032  12.736  25 
1  0  0  0  0  0.2621  1.7039  5.9228  13.994  25 
1.25  0  0  0  0.0839  0.6396  2.5926  7.1555  14.933  25 
1.5  0  0  0.0268  0.2349  1.0867  3.4278  8.1842  15.666  25 
1.75  0  0.0086  0.0848  0.4409  1.5633  4.2007  9.0562  16.259  25 
2  0  0.0302  0.1744  0.6861  2.0481  4.9105  9.8072  16.751  25 

Plotting this data for the times specified gives; 

25 

t = 0 s 
t = 2 s 
20 
t = 4 s 
Temperature 

t = 6 s 
t = 8 s 
15 
t = 10 s

10 


0.0  0.1  0.2  0.3  0.4  0.5 
Distance 

Changing the values of x and t can make this problem unstable, this can be observed in the 


accompanying Excel file “PDE.xlsx” by changing the Δt value to 0.5 (you should observe negative 
values for a number of the T values). 
Test questions: 

Q1. A lumped mass m initially at a temperature T0  is cooled by convection  to its surroundings at a 


temperature Ta. From Newton’s law of cooling, 

qconv  = – hA(T‐Ta), 

where  h  is  the  convective  cooling  coefficient  and  A  is  the  surface  area  of  the  mass.  The  energy  E 
stored in the mass is 

E = mCT, 

where C is the specific heat. From an energy balance, the rate of change of E must equal the rate of 
cooling due to convection (qconv). Thus 

dT hA 
=  - (T  - T a ) ,  T(0) = T0 
dt  mC 

Consider a sphere of radius r =1.0 cm made of an alloy for which ρ = 3000 kg/m 3  and C = 1000 J/(kg 
K). If h = 500 J/(s m 2  K), T(0) = 500 °C and Ta  = 50 °C, calculate T(t) for t = 0 to 10 s. 

Q2. For heat loss by radiation the following equation applies; 

dT A es  4 
dt 
=-
mC 
(
T  - T a 4  ,  )  T(0) = T0 

Consider a sphere of r = 1.0 cm made from an alloy for which ρ = 8000 kg/m 3  and C = 500 J/(kg K). If ε 


= 0.5, T(0) = 2500 K and Ta  = 100 K, calculate T(t) for t = 0 to 10 s. The Stefan‐Botlzmann constant σ = 
5.67 × 10 ‐8  J/(s m 2  K 4 ). 

Q3. The annual population of two species competing for the same food supply can be modelled by 
the pair of ODEs 

dN 1 
=  N 1 ( A 1  - B 1 N 1  - C 1 N 2 ),  N 1 ( 0 ) = N 1 , 0 
dt 
dN 2 
= N 2 ( A 2  - B 2 N 2  - C 2 N 1 ),  N 2 ( 0 )  = N 2 , 0 
dt 

Where AN is the birth rate, BN 2  models the death rate due to disease, and CN1N2  models the death 


rate due to competition for food supply. If N1(0) = N2(0) = 100,000. A1  = 0.1, B1  = 8 × 10 ‐7 , C1 = 1 ×10 ‐6 , 
A2  = 0.1, B2  = 8 ×10 ‐7 , and C2  = 1 × 10 ‐7 , calculate N1(t) and N2(t) for t = 0 to 10 years. 

Q4.  The inherent  features of finite‐rate  chemical  reactions  can be modelled by  the prototype  rate 


equation
dC  C e - C 

dt  t 

Where C is the nonequilibrium mass fraction of the species under consideration, Ce  is its equilibrium 


mass fraction corresponding to the local conditions, and τ has the character of a chemical relaxation 
time. Assume that Ce  varies quadratically with time. That is, 

Ce = C e , 0  + at 2 

Let C(0) = 0.1, Ce,0  = 0.1, α = 0.5, and τ = 1 ×10 ‐4 . Solve for C(t) from t = 0 to 0.01. 

Q5. Consider the absorption of A from a gas into a liquid film B in which A reacts with B according to 

A + B " 2C 

r = k CA 2 

the unsteady‐state mole balance on A in the liquid film is given as 

¶C A ¶ 2 C A 
= DAB - kC A 2 
¶ t dx 2 

where 

t = 0  CA  = 0 

x = 0  CA  = CA0 

dC
x = L  = 0 
dx

For the following data, determine the concentration profile of A at t = 0.50 seconds: 

DAB  = 10 ‐4  m 2  s ‐1 

L = 0.3 cm 

k = 10 ‐3  m 3  mol ‐1  s ‐1 

CA0  = 1000 mol m ‐3

You might also like