I want to save some parameter values inside the ODE function. For instance, I would like to save parameter "u" which is inside the ODE function for future use. I define the global "u", and also a counter "COUNT".
As I know, ode45 is essentially a "loop", it integrates the ODE function as an adaptive stepsize or a pre-defined fixed step size. The functions are given as below (The following codes are only for the purpose of testing):
a = 0.01; b = 0.1; ydot (1) = -a*y(1)*y(2); ydot (2) = b*y(1)*y(2)-b*y(2); ydot (3) = b*y(2);
u(COUNT) = y(1)+y(2)+y(3);
ydot = [ydot (1) ydot (2) ydot (3)]';
The code can be ran without errors or warnings. But the things is, when I checked the workspace, "COUNT = 61", but "length(y) = 41". I think these two values should be the same. I also tried using a fixed stepsize, but they're still different. How come they're different?