ode15i

Solve a system of stiff differential algebraic equations.

Syntax

[t,y] = ode15i(@func,tin,y0,yp0)

[t,y] = ode15i(@func,tin,y0,yp0,options)

[t,y,te,ye,ie] = ode15i(...)

Inputs

func
The system of equations to solve.
tin
The vector of times (or other domain variable) at which to report the solution. If the vector has two elements, then the solver operates in single-step mode and determines the appropriate intermediate steps.
y0
The vector of initial conditions.
yp0
The vector of initial derivative conditions.
options
A struct containing options settings specified via odeset.
The default relative and absolute tolerances are 1.0e-3 and 1.0e-6.
For the option to supply the analytical Jacobian, the function signature should be as follows:
function [dy, dyp] = jacobian(t,y,yp)
where dy and dyp contain the partial derivatives of the system function vector with respect to y and yp, respectively.

Outputs

t
The times at which the solution is computed.
y
The solution matrix, with the solution at each time stored by row.
te
The times at which the 'Events' function recorded a zero value.
ye
The system function values corresponding to each te value.
ie
The index of the event that recorded each zero value.

Example

Solve for the location in a mass spring damper system.

function f = MSD(t,y,yp,v,m,k,c) 
  % y = [x, mD, mS] 
  f = [0, 0, 0]; 
  f(1) = (y(2)-y(3)) - m*yp(1);  % momentum equilibrium        
  f(2) = y(1) - yp(3)/k;         % displacement equilibrium        
  f(3) = (m*v-y(2)) - y(1)*c;    % momentum equilibrium 
end 

m = 1.6; % mass 
v = 1.5; % initial velocity 
k = 1.25; % spring constant      
c = 1.1;  % damping constant 

handle = @(t,y,yp) MSD(t,y,yp,v,m,k,c);      
t = [0:0.2:12]; % time vector      
yi = [0, m*v,0];      
ypi = [v, -c*v, 0.0];      
[t,y] = ode15i(handle,t,yi,ypi);      
x = y(:,1)'
x = [Matrix] 1 x 61
0.00000  0.27883  0.51380  0.70368  0.84867  0.95031  1.01115  1.03459  1.02487
 0.98659  0.92472  0.84408  0.74925  0.64471  0.53465  0.42303  0.31339  0.20877
 0.11150  0.02341  -0.05410  -0.12006  -0.17400  -0.21589  -0.24610  -0.26529
-0.27428  -0.27412  -0.26598  -0.25113  -0.23086  -0.20647  -0.17920  -0.15024
-0.12064  -0.09137  -0.06321  -0.03684  -0.01278  0.00857  0.02693  0.04216
0.05420  0.06310  0.06902  0.07216  0.07280  0.07123  0.06781  0.06288  0.05675
0.04978  0.04225  0.03445  0.02664  0.01905  0.01187  0.00528  -0.00062  -0.00574
-0.01003

Comments

ode15i solves the system using the backward differentiation formula algorithm from the Sundials IDA library.

To pass additional parameters to a function argument, use an anonymous function.

The odeset options and defaults are as follows.
  • RelTol: 1.0e-3
  • AbsTol: 1.0e-6
  • Jacobian: []

The 'Events' function used with the last three output arguments is specified using odeset.