Pulse function in a LSODE system

View: New views
2 Messages — Rating Filter:   Alert me  

Pulse function in a LSODE system

by Emanuele T. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi, i'd like to introduce in my differential equations a parameter that assumes specific value (a function of one or more solution of my sistem) every 5 time step. I attach you my code. I have no clearfull ideas on time step: if I print my variable "t" it returns me some decimal value.
Thanks in advance

E.T.

[esempio.m]

function xdot = f (x, t)
K = 0;
xdot = zeros (3,1);
xdot(1) = 77.27 * (x(2) - x(1)*x(2) + x(1) - 8.375e-06*x(1)^2);
xdot(2) = (x(3) - x(1)*x(2) - x(2)) / 77.27;
xdot(3) = 0.161*(x(1) - x(3)) + K;
if mod(t,5) == 0  % How can i say "every 5 time step" ??
  K = x(3) + 2;
else
  K = 0;
endif
endfunction




t = linspace (0, 1, 100); % Time step is 1 or it changes in reason of algorithm method??

y = lsode ("f", [1;2;1], t);

plot (t,y);
print('esempio.ps', '-deps');


_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: Pulse function in a LSODE system

by Olaf Till :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Nov 06, 2009 at 01:08:44PM +0100, Emanuele T. wrote:
> Hi, i'd like to introduce in my differential equations a parameter that
> assumes specific value (a function of one or more solution of my sistem)
> every 5 time step. I attach you my code. I have no clearfull ideas on time
> step: if I print my variable "t" it returns me some decimal value.
> Thanks in advance
>
> E.T.

Hi Emanuele,

lsode uses adaptive time stepping (I believe there was a similar
thread just a few days ago), so you can't rely on a specific time step
(you give lsode a vector of times, but the solution values for these
will be interpolated, so you do not determine the time step).

You can, however, change the parameter at a certain time (not a
certain time step). Be warned, this will cause methods with adaptive
time stepping to take a long time at each parameter change, while
methods with fixed time stepping will possibly yield bad solutions. It
may be better to change the parameter in a continuous way, e.g. with
some sigmoid function of time.

Regards, Olaf
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave