MATLAB: Do I get a vector and not a structure as an output of the ODE45 function when I specify the ode function name as a string in MATLAB 7.8 (R2009a)

MATLAB

I am solving a system of differential equations defined in the following function 'rigid':
function dy = rigid(t,y)
dy = zeros(3,1); % a column vector
dy(1) = y(2) * y(3);
dy(2) = -y(1) * y(3);
dy(3) = -0.51 * y(1) * y(2);
I am using ODE45 function with the following syntax to solve the differential equations:
options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-5]);
sol = ode45('rigid',[0 12],[0 1 1],options);
I expect the result to be a structure, however, the result is a 1-D array:
>> whos sol
Name Size Bytes Class Attributes
sol 85x1 680 double

Best Answer

To use the ODE45 syntax that returns a structure that you can use with DEVAL to evaluate the solution at any point on the interval [t0,tf], you must pass the first argument to the ODE45 as a function handle:
sol = ode45(@rigid,[0 12],[0 1 1],options);
For more information on the ODE45 function and the syntax it uses, please refer to the documentation by executing the following in the MATLAB command prompt:
doc ode45
For more information on the function handles In MATLAB, please refer to the documentation by executing the following in the MATLAB command prompt:
web([docroot '/techdoc/matlab_prog/f2-38133.html'])
Related Question