CE 206: Engineering Computation Sessional Ordinary Differential Equations (ODE)
CE 206: Engineering Computation Sessional Ordinary Differential Equations (ODE)
Computation Sessional
CE 206: Engg. Computation Sessional Dr. Tanvir Ahmed
Euler’s Method
The first derivative provides a direct estimate of the
slope at ti:
dy
= f (t i , yi )
dt ti
50
Analytical solution:
gm gcd
v(t ) = tanh t
40 cd m
v (m/s)
30
20
10
0
0 2 4 6 8 10 12
t (sec)
CE 206: Engg. Computation Sessional Dr. Tanvir Ahmed
Heun’s Method
where
k1 =f (t i , yi )
1 1
k2 = f t i + h, yi + k1h
2 2
1 1
k3 = f t i + h, yi + k2 h
2 2
k4 = f (t i + h, yi + k3h)
k1 = dydt(tt,yy);
k2 = dydt(tt + hh/2, yy + 0.5*k1*hh);
k3 = dydt(tt + hh/2, yy + 0.5*k2*hh);
k4 = dydt(tt + hh, yy + k3*hh);
end
dy
= yt 3 − 1.5 y
dt
(a) Analytically
(b) Euler’s method with h = 0.5 and h = 0.25
(c) Heun’s method with h = 0.5
(d) 4th order RK method with h = 0.5
function yp = predprey(t, y)
yp = [1.2*y(1)-0.6*y(1)*y(2);… predprey.m file
-0.8*y(2)+0.3*y(1)*y(2)];
tspan = [0 20];
y0 = [2, 1];
[t, y] = ode45(@predprey, tspan, y0);
figure(1); plot(t,y);
figure(2); plot(y(:,1),y(:,2));
If l = 2 ft, g = 32.2 ft/s2 and θ0 = π/4, Solve for θ from t = 0 to 1.6 s using
(a) Euler’s method with h = 0.05
(b) Using ode45 function with h = 0.05
(c) Plot your results and compare with the analytical solution
d @t = 0, θ0 = π/4
=v
d g
2
dt
2
+ sin = 0 dv g
dt l = − sin @t = 0, v = 0
dt l
CE 206: Engg. Computation Sessional Dr. Tanvir Ahmed
Boundary value problem: the shooting method
the boundary-value problem is converted into an
equivalent initial-value problem.
dT
d 2T dx = z
+ h(T − T ) = 0
= − h(T − T )
dx 2 dz
dx
Generally, the equivalent system will not have
sufficient initial conditions
-A guess is made for any undefined values.
- The guesses are changed until the final solution satisfies all the B.C.
Solve d 2T
dx 2
+ h (T − T ) + (T
4
− T 4
)=0
The basic differential equation of the elastic curve for a uniformly loaded
beam is given as
d 2 y wLx wx 2
EI 2 = −
dx 2 2
If E = 30000 ksi, I = 800 in4, w = 1 kip/ft, L = 10 ft, solve for the deflection
of the beam using the shooting method and compare the numerical
results with the analytical solution
wLx 3 wx 4 wL3 x
y= − −
12 EI 24 EI 24 EI
CE 206: Engg. Computation Sessional Dr. Tanvir Ahmed
Numerical solution: finite difference
finite differences are substituted for the derivatives
in the original equation
d 2T
2
+ h(T − T ) = 0
dx
dT T1 − T−1 dT
= T−1 = T1 − 2x
dx 0 2x dx 0
dx 0
dT
(2 + hx )T0 − 2T1 = hx T − 2x dx
2 2
0
CE 206: Engg. Comp. Sessional Dr. Tanvir Ahmed
Practice Problem: Finite difference
Solve the nondimensionalized ODE using finite difference
methods that describe the temperature distribution in a
circular rod with internal heat source S
d 2T 1 dT
2
+ +S =0
dr r dr
Over the range 0 ≤ r ≤ 1, with boundary conditions
dT
T (r = 1) = 1 =0
dr r =0