Numerical Solution of Ordinary Diff Eqns
• Intro to numerical solution of Ordinary Differential
Equations (ODEs):
• Runge-Kutta methods
• MATLAB ODE solvers (sec 10.4)
• Solving systems of first-order ODEs w/ MATLAB
omment on Lab 14 Part VI
•
Comment on Lab 14, Part VI
• Examples of systems of ODEs
•2
nd
order ODEs as a system
of 1
st
order ODEs
y
•
Predator-Prey problem
•
Boundary Value Problems
4/14/2009
1
MASE201 Spring 2009
Solving a
system of ODEs
he same methods used to solve a single ODE can
•
The same methods used to solve a single ODE can
be used to solve a system of ODEs
• There is one independent variable and many (
n
)
dependent variables with one ODE per dependent
variable (denoted
j
):
he numerical solution of the system can be stated
n
j
j
j
y
y
y
y
t
f
dt
dy
,
,
,
,
,
,
2
1
•
The numerical solution of the system can be stated
as:
:
that
such
)
(
find
,
to
1
For
t
y
n
j
j
(0)
conditions
initial
the
with
)
,
,
...
,
,
(
o
j
j
2
1
y
y
t
y
y
y
f
dt
dy
n
j
4/14/2009
2
MASE201 Spring 2009
]
,
0
[
domain
the
over
final
t
Solving a system of ODEs in MATLAB
he built
MATLAB functions can solve a system of
•
The built-in MATLAB functions can solve a system of
ODEs. The syntax is the same as for a single
ODE,except that
yo
becomes a vector
, rather than a
scalar and odefun must return a column vector
with
the values of
f
1
,
f
2
etc.
•
a function m
e:
In a function m-file:
function dyvecdt = odesysfun(x,y)
k=10; m=1;
dyvecdt(1,1)= yvec(2);
%velocity is dx/dt
dyvecdt(2,1)= -k/m*yvec(1);
%acceleration is dv/dt
•
n the MATLAB command line:
On the MATLAB command line:
>> [t,y]=ode45(@odesysfun,[0 10],[0 3]);
% Note that t is a column vector of some length n and y is an n x 2
4/14/2009
3
% matrix. Each column contains the values of one dependent variable
% (x and v respectively)
MASE201 Spring 2009
Initial Value Problems and Boundary Value Problems
hen solving an ODE arbitrary constants
• When solving an ODE, arbitrary constants
appear in the solution.
or a second
rder ODE or higher it is
• For a second-order ODE or higher, it is
important to distinguish between initial value
nd boundary value problems
and boundary value problems
– When the independent variable is time, the ODE
is called an initial value problem
and we need to
specify
y
(0), d
y
/d
t
(0)
etc.
– When the independent variable is position (e.g.)
e
DE is called a
oundary value
roblem
nd
the ODE is called a boundary value problem
and
we can specify some combination
the value of
the dependent variable or its derivatives at
ifferent values of
4/14/2009
4
different values of
x
MASE201 Spring 2009