The ode45 function is designed to solve a set of differential equations for any number of variables.
[T, Y]? (http://escwiki.esc.auckland.ac.nz/courses/enggen131s2c/student-wiki/TheOde45Function/createform?page=T%2C%20Y) = ode45(odefun, tspan, y0)
Inputs in function:
odefun - a user defined matlab function which defines the Right Hand Side of the ordinary differential equation. This function has an output of [f]? (http://escwiki.esc.auckland.ac.nz/courses/enggen131s2c/student-wiki/TheOde45Function/createform?page=f) and an input of time and the variables (t,y).
This function should evaluate all the variables and the functions, for examplefunction [f]? (http://escwiki.esc.auckland.ac.nz/courses/enggen131s2c/student-wiki/TheOde45Function/createform?page=f) = reactorfunc(t,y)
% set up constants
E = some number;
R = 8.314;
k = another number;
h = some other number;
% evaluate the right hand side of the equation
% in this example, there are two variables, so two differential equations. These are put into a matrix named 'f' where the first row is the first variable, the second row is the second variable.
f(1) = k*y(1).*exp(-E/R/y(2));
f(2) = h*k*y(1).*exp(-E/R/y(2));
% The 'f' matrix must be transposed when there are two variables, as the ode45 function takes the matrix in the transposed form.
f = f';
return;
tspan - an array that states the time range. ie. tspan (1) = intial time;
tspan(2) = final time;
y0 - an array that sets up the initial conditions of the variables.ie. y0(1) = initial value for variable one.
y0(2) = initial value for variable two.
Output of function:
The ode45 function returns two arrays [T, Y]? (http://escwiki.esc.auckland.ac.nz/courses/enggen131s2c/student-wiki/TheOde45Function/createform?page=T%2C%20Y)
The T array is a range of times,
The Y array is the valuesof the variables, that correspond to the time array.
rpul013