
ode45 solver and outputfcn
Posted:
Apr 25, 2011 5:19 PM


I often solved my ODEs by the sintax:
[T,Y] = ode15s(@vdp1000,[0 3000],[2 0]);
and let's say the problem was:
function dy = vdp1000(t,y) dy = zeros(2,1); % a column vector dy(1) = y(2); dy(2) = 1000*(1  y(1)^2)*y(2)  y(1);
it works fine.
Now let's suppose my ODEs is
function dy = vdp1000(t,y) dy = zeros(2,1); % a column vector % K the new value K = newvalue(t,y) dy(1) = y(2); dy(2) = 1000*(1  y(1)^2)*y(2)  y(1) + K;
It means there is a K value computed at each time by a function called newvalue. I would have this value T in output at each output time. For example: [T,Y, K] = ode15s(@vdp1000,[0 3000],[2 0]);
Untill now, at the end of my simulation, I "rebuild" T, but it is a time consuming procedure and dumb. I mean that: [T,Y] = ode15s(@vdp1000,[0 3000],[2 0]); for i=1:length(T) K(i) = newvalue(T(i), Y(i,:) ) end
I suspect the option 'outputfcn ' could help me. Someone knows a better method?

