Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Ordinary Differential Equations

Example falling brick dv 1/ 2 K 2 =g v dt m Order since highest derivative is Spring mass damper d 2x dx m 2 +c + Kx = 0 dt dt Order Set of 1st order ODEs dx =v dt , m dv + cv + Kx = 0 dt

Sets of ODEs
So ODE problems can be reduced to a set of N first-order ODEs dyi ( x) = f i ( x, y1, y2 ,... y N ) for equations i = 1,..., N dx Not completely specified needs boundary conditions initial value problems boundary value problems

General Procedure
Re-write the dy and dx terms as y and x and multiply by x
dyi ( x) = f i ( x, y1, y2 ,... y N ) dx for equations i = 1,..., N

Literally doing this is Eulers method


dy ( x) = f ( x, y ) dx y ( x) = f ( x, y ) x yi +1 = yi + f ( xi , yi )x

Tank mixing problem


& dc(t ) V = in (cin c(t ) ) dt Vtank

& V in (cin ci ) t ci +1 = ci + Vtank

Mixing tank
t 300 150 100 50 30 15 10 5 3 Error Et at t=600 1.4 0.61 0.39 0.19 0.11 0.055 0.036 0.018 0.011

Quantify the error


Write Taylor series for ci +1 centred on ci c(ti ) 2 c(ti ) (t ) + (t )3 + ... c(ti +1 ) = c(ti ) + c(ti )t + 2 6

So error is

order?

Not quite accumulation of errors


We saw before that the error was 1st order But each step has this error, so total accumulate d error Etotal = E1 + E2 + E3 + ... + E N c(ti ) = (t )2 2 N c (t )2 N 2

Euler Error
Local error lk=yk-y*k-1(tk) Global error ek=yk-y(tk)
y

Euler Stability (1)


dy = y dx Euler y i +1 = y i + y i x = y i (1 + x ) So that y k = y 0 (1 + x )k y ( x ) = y 0e x

Euler Stability (2)


dy = y Real solution y ( x ) = y 0e x dx For negative If x small Euler y k = y 0 (1 + x )k

If x big

In terms of integration
dy = f ( x, y ) dx Integrate both sides from x x + x
x + x

dy dx = dx

x + x

f ( x, y) dx
x x + x

y ( x + x) y ( x) = y ( x + x) = y ( x) +

f ( x, y) dx
x

x + x

f ( x, y) dx
x

Runge-Kutta
dy = f ( x, y ) dx
x+h

y ( x + h) = y ( x ) +

f ( x, y) dx
x

Could use higher order (polynomia l) fit for integral based on values of f evaluated at locations between x x + h Or use Gaussian quadrature to evaluate the integral General form yi +1 = yi + h

is increment function (aka a slope)

R-K General form


General form yi +1 = yi + h Write as :

= a1k1 + a2 k 2 + K + an kn
where a1 , a2 ,K , an k1 = f ( xi , yi ) k 2 = f ( xi + p1h , k3 = f ( xi + p2 h , M k n = f ( xi + pn 1h , yi + qn 1,1k1h + qn 1, 2 k2 h + ... + qn 1, n 1k n 1h) yi + q11k1h) yi + q21k1h + q22 k 2 h) constants

R-K 1st Order Form


General form y i +1 = y i + h

= a1k1
where a1 = 1 constant k1 = f ( x i , y i ) y i +1 = y i + (1)f ( x i , y i )h

RK 4th Order
1 y i +1 = y i + (k1 + 2k 2 + 2k 3 + k 4 ) h 6 k1 = f ( x i , y i ) k2 = f ( xi + k3 = f ( xi k 4 = f ( xi 1 1 h , y i + k1h ) 2 2 1 1 + h , y i + k 2 h) 2 2 + h , y i + k 3 h)
xi xi+1 x y(x)

RK4 if f(x,y)=f(x)
If f ( x, y ) = f ( x) dy = f ( x) dx
x+h x+h

yi +1 = y i +

f ( x) dx
x

RK4 has =

f ( x) dx =

1 (k1 + 2k2 + 2k3 + k4 ) h 6

1 ( f ( xi ) + 4 f ( xi + h / 2) + f ( xi + h) ) h 6

Example y=x+y, y(0)=0


x 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 y 0 0.0214 0.092 0.222 0.426 0.718 1.120 1.655 2.353 3.250 k1=f(x,y) 0 0.221 0.492 0.822 1.226 1.718 2.320 3.055 3.953 k2=f(x+h/2,y+h/2k1) 0.1 0.344 0.641 1.004 1.448 1.990 k3=f(x+h/2,y+h/2k2) 0.11 0.356 0.656 1.023 1.470 2.017 2.685 3.501 4.498 5.715 k4=f(x+h,y+hk3) 0.222 0.493 0.823 1.227 1.720 2.322 3.057 3.955 5.052 6.393 yn=y+1/6(k1+2k2+2k3+k4)h 0.02140 0.0918 0.2221 0.4255 0.718 1.120 1.655 2.353 3.250

3.5 3 2.5 2 y 1.5 1 0.5 0 0

2.652 3.461 4.448 5.654

5.050

Euler analytical RK4

4.389

0.5

1 x

1.5

You might also like