2013lectures 8a ODEs
2013lectures 8a ODEs
2013lectures 8a ODEs
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
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
So error is
order?
Euler Error
Local error lk=yk-y*k-1(tk) Global error ek=yk-y(tk)
y
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
= 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
= 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 ( f ( xi ) + 4 f ( xi + h / 2) + f ( xi + h) ) h 6
5.050
4.389
0.5
1 x
1.5