Sunteți pe pagina 1din 6

ChemE 109 - Numerical and Mathematical Methods

in Chemical and Biological Engineering


Fall 2007
Solution to Homework Set 4
1. Consider the following nonlinear ordinary differential equation:
dx
= t(1 x2 )e2x
dt
Show the exact form of the equations needed to calculate xi+1 from xi , with an integration
step equal to h, using the:
(a) Explicit Euler method
(b) Implicit Euler method
(c) Fourth-order Runge-Kutta method
Solution:
(a) Explicit Euler method
xi+1 = xi ti (1 x2i )e2xi h
(b) Implicit Euler method
xi+1 = xi (ti + h)(1 x2i+1 )e2xi+1 h
(c) Fourth-order Runge-Kutta method
1
xi+1 = xi + (k1 + 2k2 + 2k3 + k4 )h
6
k1

= ti (1 x2i )e2xi

k2

1
1
1
= (ti + h)(1 (xi + k1 h)2 )e2(xi + 2 k1 h)
2
2

k3

1
1
1
= (ti + h)(1 (xi + k2 h)2 )e2(xi + 2 k2 h)
2
2

k4

= (ti + h)(1 (xi + k3 h)2 )e2(xi +k3 h)

2. Consider the following nonlinear ordinary differential equation:


x + t2
dx
=
dt
t
with x(1) = 1. Estimate x(1.5)
1

(a)
(b)
(c)
(d)
(e)

Using the explicit Eulers method with h = 0.1.


Using the implicit Eulers method with h = 0.1.
Using the Euler predictor-corrector with h = 0.25.
Using the fourth-order Runge-Kutta method with h = 0.5.
Write a MATLAB code, which uses explicit Eulers method to compute x(10), with h=0.01.
Please print out the plot for t [1, 10] and the final result x(10) as well.

Solution:
(a) Using the explicit Eulers method with h = 0.1.
xi+1 = xi +
i
0
1
2
3
4
5

ti
1.0
1.1
1.2
1.3
1.4
1.5

xi + t2i
h
ti

xi
1.0000
1.2000
1.4191
1.6573
1.9148
2.1916

(b) Using the implicit Eulers method with h = 0.1.


xi+1 = xi +
xi+1 =
i
0
1
2
3
4
5

xi+1 + t2i+1
h
ti+1

ti+1 xi + t2i+1 h
ti+1 h

ti
1.0
1.1
1.2
1.3
1.4
1.5

xi
1.0000
1.2210
1.4629
1.7257
2.0092
2.3134

(c) Using the Euler predictor-corrector with h = 0.25.


xoi+1 = xi +

xi + t2i
h
ti

xi+1 = xi +

xoi+1 + t2i+1
h
ti+1

xoi+1 + xi+1
2

xi+1 =
2

i ti
0 1.0
1 1.3
2 1.5

xoi+1
N/A
1.5000
2.1800

xi+1
xi
N/A 1.0000
1.6125 1.5562
2.2946 2.2373

(d) Using the fourth-order Runge-Kutta method with h = 0.5.


k1

xi + t2i
ti

k2

(xi + 12 k1 h) + (ti + 12 h)2


(ti + 21 h)

k3

(xi + 12 k2 h) + (ti + 12 h)2


=
(ti + 21 h)

k4

(xi + k3 h) + (ti + h)2


(ti + h)

1
xi+1 = xi + (k1 + 2k2 + 2k3 + k4 )h
6
i ti
k1
0 1.0 N/A
1 1.5 2.0000

k2
k3
N/A
N/A
2.4500 2.5400

k4
xi
N/A 1.0000
3.0133 2.2494

(e) Write a MATLAB code, which uses explicit Eulers method to compute x(10), with h=0.01.
Please print out the plot for t [1, 10] and the final result x(10) as well.
Sample program:
h=0.01;
t=1:h:10;
n=length(t);
x(1)=1;
for i=1:n-1
x(i+1)=x(i)+h*Func4_2(t(i),x(i));
end
plot(t,x,b-,linewidth,3);
title(Fourth-order Runge-Kutta Method,fontsize,24);
xlabel(t,fontsize,24)
ylabel(x,fontsize,24)
Plot:

Fourthorder RungeKutta Method


100

90

80

70

60

50

40

30

20

10

t
3. Consider the following system of ordinary differential equations:
dx1
= 0.5x1 + 0.3x2
dt
dx2
= 4 0.3x2 + 0.1x1
dt
with x1 (0) = 2 and x2 (0) = 1. Estimate x1 (2) and x2 (2)
(a) Using the explicit Eulers method with h = 0.5.
(b) Using the Euler predictor-corrector with h = 1.0.
(c) Using the fourth-order Runge-Kutta method with h = 2.0.
Solutions:
(a) Using the explicit Eulers method with h = 0.5.
x1,i+1 = x1,i + (0.5x1,i + 0.3x2,i )h
x2,i+1 = x2,i + (4 0.3x2,i + 0.1x1,i )h
i
0
1
2
3
4

ti
0.0
0.5
1.0
1.5
2.0

x1,i
2.0000
1.6500
1.6800
1.9485
2.3592
4

x2,i
1.0000
2.9500
4.5900
5.9855
7.1851

10

(b) Using the Euler predictor-corrector with h = 1.0.


xo1,i+1 = x1,i + (0.5x1,i + 0.3x2,i )h
xo2,i+1 = x2,i + (4 0.3x2,i + 0.1x1,i )h
x1,i+1 = x1,i + (0.5xo1,i+1 + 0.3xo2,i+1 )h
x2,i+1 = x2,i + (4 0.3xo2,i+1 + 0.1xo1,i+1 )h
x1,i+1

xo1,i+1 + x1,i+1
=
2

x2,i+1 =
i
0
1
2

ti
xo1,i+1
2.0 N/A
1.0 1.3000
2.0 2.3140

xo2,i+1
N/A
4.9000
7.2020

xo2,i+1 + x2,i+1
2
x1,i+1
N/A
2.8200
3.0636

x2,i+1
x1,i
x2,i
N/A 2.0000 1.0000
3.6600 2.0600 4.2800
6.3508 2.6888 6.7764

(c) Using the fourth-order Runge-Kutta method with h = 2.0.


k1,1 = 0.5x1,i + 0.3x2,i
k2,1 = 4 0.3x2,i + 0.1x1,i
1
1
k1,2 = 0.5(x1,i + k1,1 h) + 0.3(x2,i + k2,1 h)
2
2
1
1
k2,2 = 4 0.3(x2,i + k2,1 h) + 0.1(x1,i + k1,1 h)
2
2
1
1
k1,3 = 0.5(x1,i + k1,2 h) + 0.3(x2,i + k2,2 h)
2
2
1
1
k2,3 = 4 0.3(x2,i + k2,2 h) + 0.1(x1,i + k1,2 h)
2
2
k1,4 = 0.5(x1,i + k1,3 h) + 0.3(x2,i + k2,3 h)
k2,4 = 4 0.3(x2,i + k2,3 h) + 0.1(x1,i + k1,3 h)

1
x1,i+1 = x1,i + (k1,1 + 2k1,2 + 2k1,3 + k1,4 )h
6
1
x2,i+1 = x1,i + (k2,1 + 2k2,2 + 2k2,3 + k2,4 )h
6
i
0
1

ti
k1,1
2.0 N/A
2.0 -0.700

k2,1
k1,2
k2,2
k1,3
N/A N/A N/A N/A
3.900 0.820 2.660 -0.312

k2,3
N/A
3.184

k1,4
N/A
1.522

k2,4
x1,i
x2,i
N/A 2.000 1.000
1.927 2.613 6.838

4. Consider the following third-order ordinary differential equation:


d3 x d2 x
dx

+
2
= et x
dt3
dt2
dt
d2 x
dx
with x(t0 ) = a,
(t0 ) = b and 2 (t0 ) = c. Reduce the above equation to a form that can be
dt
dt
treated by the methods learned in class.
Solutions:
Define:

x1 = x
x2 =

dx
dt

x3 =

d2 x
dt2

Then the third-order ODE can be written as:


dx1
= x2
dt
dx2
= x3
dt
dx3
= x3 2x2 + et x1
dt
with the initial conditions:
x1 (t0 ) = a x2 (t0 ) = b x3 (t0 ) = c

S-ar putea să vă placă și