Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: ode45 solver and outputfcn
Replies: 3   Last Post: Mar 10, 2015 8:20 AM

 Messages: [ Previous | Next ]
 Red Star Posts: 136 Registered: 6/28/08
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?

Date Subject Author
4/25/11 Red Star
4/25/11 Nasser Abbasi
4/26/11 Red Star
3/10/15 Alexander