This preview shows pages 1–4. Sign up to view the full content.
Short Tutorial on Matlab
(©2003,2004 by Tomas Co)
Part 2. Ordinary Differential Equations
1.
Suppose we want to simulate the following set of differential equations:
2
t
y
d
d
2
3
t
y
d
d
⋅
+
2 y
⋅
+
4 exp
2

t
⋅
(
)
⋅
5

subject to the following initial conditions,
y 0
( )
2
t
y 0
( )
d
d
1

2.
You need to convert to state space form.
Let x
1
= y and x
2
= dy/dt, then we have
t
x
1
d
d
x
2
2
t
x
2
d
d
2
3

x
2
⋅
2 x
1
⋅

4 exp
2

t
⋅
(
)
⋅
+
5

x
1
0
( )
2
x
2
0
( )
1

This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document 3.
Next, create an mfile using either Matlab's editor or any text editor, e.g. "notepad":
function dx = tutorialEqn1(t,x)
% x is the state vector
% to minimize parentheses you could put them
% in other variables
x1=x(1);
x2=x(2);
% write the state equations
dx1 = x2;
dx2 = 3*x2 2*x1 +4*exp(2*t)  5;
% collect the derivatives into a column vector
dx = [dx1;dx2];
then save as an mfile,
e.g.
tutorialEqn1.m
4.
In matlab, you can now invoke the ode solvers.
For example, you can use
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
This note was uploaded on 09/22/2008 for the course CS 111 taught by Professor Stuff during the Spring '08 term at Bilkent University.
 Spring '08
 stuff

Click to edit the document details