Professional Documents
Culture Documents
MATLAB
ode45
3/2/2009
Prepared by Dr.Waleed
ode45(odefun,tspan,y0)
odefun:A function that evaluates the right side of the differential equations.
tspan:A vector specifying the interval of integration, [t0,tf]
y0:A vector of initial conditions,[y,y,..]
1-Re-arrange equation to dy/dt=..
2-Specify time interval
3-Specify initial condition
3/2/2009
Prepared by
2 Dr.Waleed
x ' (t ) sin(tx) 0,
x(0) 1, for 0 t 10
File name
function xprime=ex1(t,x)
xprime=sin(t*x);
3/2/2009
Prepared by Dr.Waleed
clc
clear Time interval
[t,x] = ode45(ex1,[0 ,10], [1]);
x
plot(t,x)
Initial condition
vertical axis
Time
horizontal axis
3/2/2009
Prepared by Dr.Waleed
3/2/2009
Prepared by Dr.Waleed
'
2
yprime=[cos(z(2))+sin(t);sin(z(1))-cos(t)];
Now z and yprime are both column vectors
3/2/2009
Prepared by Dr.Waleed
3/2/2009
Prepared by Dr.Waleed
3/2/2009
Prepared by Dr.Waleed
....eq1
z '2 9 z1 2tz 2
......eq2 ,
State Variables
Put it in Matrix
Form?
Prepared by Dr.Waleed
clc;clear
z0=[0,1];
tspan=[0,5];
[t,z]=ode45(ex3, tspan,z0);
plot(t,z);
3/2/2009
Prepared by Dr.Waleed
10
: 1 0 = , 1 0 =
2 0 = , x2 0 =
3/2/2009
Prepared by Dr.Waleed
11
z1 x1
z 2 x1
z 3 x2
z 4 x 2
3/2/2009
Prepared by Dr.Waleed
12
z1 z 2
K2
1
z 2
( K1 K 2 ) z1
z3
M1
M1
z3 z 4
K2
1
B
z 4
( K 2 K 3 ) z3
z1
z4
M2
M2
M2
In Matlab form
Eq1 z (2)
K2
1
Eq 2
( K1 K 2 ) z (1)
z (3)
M1
M1
Eq3 z (4)
K2
1
B
Eq 4
( K 2 K 3 ) z (3)
z (1)
z (4)
M2
M2
M2
3/2/2009
Prepared by Dr.Waleed
13