The Math Forum

Search All of the Math Forum:

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

Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Red Star

Posts: 136
Registered: 6/28/08
ode45 solver and outputfcn
Posted: Apr 25, 2011 5:19 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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
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,:) )

I suspect the option 'outputfcn ' could help me.
Someone knows a better method?

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.