help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ode45 help


From: Thomas Treichl
Subject: Re: Ode45 help
Date: Sun, 15 Feb 2009 10:23:40 +0100
User-agent: Thunderbird 2.0.0.19 (Macintosh/20081209)

Brandon Pye schrieb:
On Saturday 14 February 2009 16:51:15 you wrote:
Brandon Pye schrieb:
Hey guys,

I'm in a class where I need to use ode45. I keep getting an error
syntax when I copy the code from matlab to octave. The function that
contains the differential equations gets its values from a structure
defined in the master .m file. In matlab, when I call ode45 the code
looks like:

[t,y] = ode45(@gene.m, [0 10], y0, [], info);

Where the closed brackets are skipping the tolerance and 'info' is the
structure I need so that the function 'gene.m' can get the values
necessary for the differential equations. When I run that code in
octave, it can't find the values in the structure. Can anyone tell me
where I can put the structure in the code when I call ode45 in octave?
Also, I have matlab for windows. Should I just try to run it with wine?
I took a similar example than the one you sent (a modified version of the
example that comes from "help ode45" at the Octave prompt. I don't know
what the gene function should do but I also cannot see the problem. Can you
post some more information from your session?

Here is my example:

   octave-3.0.3:1> fvdb = @(vt,vy) [vy(2); (1 - vy(1)^2) * vy(2) - vy(1)];
   octave-3.0.3:2> ode45 (fvdb, [0 20], [2 0], [], (struct ('a', 1, 'b',
2)))

Best regards,

   Thomas

The master equation uses the code:
[t,y] = ode45(@gene_iffl1, [0 info.tmax], info.y0, [], info);

with info containing:
info.gen_time = 0.5
info.alpha_y = log(2)/info.gen_time;
info.alpha_z = log(2)/info.gen_time;
info.beta_zhigh = 50;
info.beta_zlow = 2;
info.beta_y = 50;
info.K_yz = 20;
info.tmax = 10;

The function gene_iffl1 is:

function dydt = gene_iffl1(t,y,info)
dydt = zeros(2,1);
dydt(1) = info.beta_y-info.alpha_y*y(1);
dydt(2)=info.beta_zhigh*(1-(info.beta_zhigh-
info.beta_zlow)/info.beta_zhigh*(y(1)>info.K_yz))-info.alpha_z*y(2);

I just need help with translating the syntax essentially.

Everything you do is ok. The only thing that need to be done is that you pass an empty pseudo options handling structure (which is generated with the command 'odeset') as the 4th input argument. In your case, the solver somehow doesn't like an empty 4th input argument if the 5th input argument is a structure, too. I must have a look at the solver function some when I have the time to do it.

Your workaround that works in Matlab and Octave should be

  vopt = odeset ();
  [t,y] = ode45(@gene_iffl1, [0 info.tmax], info.y0, vopt, info);

BTW, take care with your info variable which also is a valid Octave function!

Best regards,

  Thomas


reply via email to

[Prev in Thread] Current Thread [Next in Thread]