Engineering 7:
Prof. Alexandre Bayen
Introduction to Programming for Engineers
Spring 2011
Lab 11: Ordinary Differential Equations
Date Assigned: 5:00pm, Friday – April 22.
Date Due: 5:00pm, Friday – April 29.
The following help file for ode45 will be helpful for you during this lab.
ODE45
Solve
non-stiff
differential
equations,
medium
order
method.
[TOUT,YOUT] = ODE45(ODEFUN,TSPAN,Y0) with TSPAN = [T0 TFINAL]
integrates the system of differential equations y' = f(t,y) from
time
T0
to
TFINAL
with
initial
conditions
Y0.
ODEFUN
is
a
function handle. For a scalar T and a vector Y, ODEFUN(T,Y) must
return a column vector corresponding to f(t,y). Each row in the
solution array YOUT corresponds to a time returned in the column
vector
TOUT.
To
obtain
solutions
at
specific
times
T0,T1,.
..,TFINAL (all increasing or all decreasing), use TSPAN =
[T0 T1 .
.. TFINAL].
Problem 1:
The logistics equation is a simple differential equation model that can be used to relate the change
in population dP/dt to the current population, P, given a growth rate, r, and a carrying capacity, K. The logistics
equation can be expressed by:
Write a function with header
[dP] = myLogisticsEq(t, P, r, K)
that represents the Logistics equation.
Note that this format allows
myLogisticsEq
to be used as an input argument to
ode45
. You may assume that
the arguments
dP
,
t
,
P
,
r
, and
K
are all scalars, and
dP
is the value dP/dt given
r
,
P
, and
K
.
Note that the input
argument,
t
, is obligatory if
myLogisticsEq
is to be used as an input argument to
ode45
, even though it is part
of the differential equation.
Note
: The logistics equation has an analytic solution defined by:
where P
0
is the initial population. As an exercise, you should verify that this equation is a solution to the
logistics equation.