Vous êtes sur la page 1sur 6

The Cooper Union for the Advancement of Science and Art

ChE 151 Lecture


3/24/15
Prof. Davis

Chemical Engineering Department

The Cooper Union for the Advancement of Science and Art

Ch. 5.2: Eulers Method

dy
f t , y for a t b with y a
dt
point ti:
Taylor says we can expand y at some
2
t ti ''

'
y t y ti t t i y t i
y i
2
If we define a step size h = ti+1 ti for any i and
evaluate at a nearby point ti+1:
h 2 ''
y ti 1 y ti hf ti , y ti y i
2
Chemical Engineering Department

The Cooper Union for the Advancement of Science and Art

Eulers Marching Formula


Ignoring the error term (which grows with h 2):
y ti 1 y ti hf ti , y ti

Since y is approximate, let the new variable w


indicate the approximation to y:
w y w ti 1 w ti hf ti , w ti

Simplifying notation:
wi @w ti

Chemical Engineering Department

wi 1 wi hf ti , wi

The Cooper Union for the Advancement of Science and Art

Using Eulers Method


To implement the method, we would define a
vector of times (call it t) and then calculate
an approximation to y (w) by marching
forwards in time from the initial time t 0 = a:

t t2

t
N 1

t, w

y t0

w0

w
w0 hf t0 , w0
ah

, w
w2
a 2h
w1 hf t1 , w1

a N 1 h
wN 1
wN 2 hf t N 2 , wN 2

t0
t
1

Chemical Engineering Department

The Cooper Union for the Advancement of Science and Art

Activity: Euler in Pseudocode


Time: 10 min to do, 10 min discuss
Write an algorithm in pseudocode which
implements Eulers method to solve the IVP
for the 1st order irreversible ethylbenzene
reactor:
dC
o
EB

k f CEB , CEB 0 CEB

Your output should be a vector of guesses for


CEB which can be interpolated to get an
approximating function. Assume your step
size is small (10-4) and you will go to = 10.

Chemical Engineering Department

The Cooper Union for the Advancement of Science and Art

Answer: Eulers Method


Set N = 100000
% Set # of time points (N) to evaluate
Set t0 = 0 , tfinal = 10 % Set the initial/final time points
h = (tfinal t0) / N
Set kf, CEB0

% Calculate the step size h = 1e-4


% Known initial EB conc., rate const.

% Calculate the first approximation points


w(1) = CEB0
% w vector is an output/answer
t(1) = t0

% Time vector is also an output

For ( i = 1:N 1 )
% We already did the first one
w(i+1) = w(i) + h*kf*w(i) % Find next guess from prev.
t(i+1) = t(i) + h
% Keep vector of times
End For loop
% Answer is vector of guesses w and vector of times t (same size)
Chemical Engineering Department