# ode45

Solve a system of non-stiff differential equations.

## Syntax

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

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

[t,y] = ode45(...)

## 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.
`options`- A struct containing options settings specified via odeset.

## Outputs

- t
- The times at which the solution is computed.
- y
- The solution matrix, with the solution at each time stored by row.

## Example

Find the location in a mass spring damper system:

```
function dy = MSD(t,y,m,k,c)
% y = [x, dx/dt]
dy = [0, 0];
dy(1) = y(2);
dy(2) = -y(1)*(k/m) - y(2)*(c/m);
end
v = 1.5; % initial velocity
m = 1.6; % mass
k = 1.25; % spring constant
c = 1.1; % damping constant
handle = @(t,y) MSD(t,y,m,k,c);
t = [0:0.2:12]; % time vector
yi = [0, v];
[t,y] = ode45(handle,t,yi);
x = y(:,1)'
```

```
x = [Matrix] 1 x 61
0.00000 0.27883 0.51372 0.70348 0.84837 0.94995 1.01081 1.03442 1.02487
0.98670 0.92470 0.84374 0.74861 0.64390 0.53389 0.42247 0.31306 0.20858
0.11146 0.02356 -0.05373 -0.11952 -0.17338 -0.21528 -0.24552 -0.26473
-0.27376 -0.27366 -0.26560 -0.25085 -0.23068 -0.20639 -0.17921 -0.15030
-0.12072 -0.09144 -0.06325 -0.03684 -0.01275 0.00862 0.02699 0.04221 0.05425
0.06316 0.06909 0.07225 0.07289 0.07133 0.06790 0.06292 0.05676 0.04973
0.04216 0.03433 0.02651 0.01892 0.01176 0.00517 -0.00072 -0.00583
-0.01012
```

## Comments

ode45 solves the system with the Runge-Kutta-Fehlberg 45 method.

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