How do I pass out extra parameters using ODE23 or ODE45 from the MATLAB ODE suite?
1 view (last 30 days)
Show older comments
Dear Matlabbers,
If you recognize the title from a tutorial of Mathworks, you are right. The only problem is that I can't get anything working but the example given in this tutorial:
I have tried to output an extra parameter from a slightly adjusted example of the ode45 solver. The code I used is:
function try_plo
clc
options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-5]);
[T,Y] = ode45(@rigid,[0 12],[0 1 1],options);
[dy b] = rigid([], []);
assignin('base','T',T)
assignin('base','Y',Y)
assignin('base','b',b)
assignin('base','dy',dy)
end
function [dy b] = rigid(t,y)
persistent a;
dy = zeros(3,1);
dy(1) = y(2) * y(3);
dy(2) = -y(1) * y(3);
dy(3) = -0.51 * y(1) * y(2);
a = y(1)*23;
a = [a; y(1)];
if nargout>1
b = a;
end
end
To check whether everything works out fine, I used assignin. I think the example given in the link is a bit short about the background of the code they used, could anybody correct my code and explain what I've done wrong or what has been done in the example of the link?
I know what persistent and nargout do, I have read the help files, but I can't see why the input of the function myode in the example can have [], [] as input. Furthermore I don't know why this has to be added:
xv = [xv; x];
yv = [yv; y];
I might be a newby on this subject, but it would be nice if somebody could give some explanations more thoroughly than the short example of the link.
Thanks in advance!
Adriaan
0 Comments
Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!