help-octave
[Top][All Lists]
Advanced

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

Re: passing parameters to lsode


From: address@hidden
Subject: Re: passing parameters to lsode
Date: Thu, 27 Sep 2007 08:21:46 +0200

-----Original Message-----
Date: Thu, 27 Sep 2007 08:04:46 +0200
Subject: Re: passing parameters to lsode
From: Søren Hauberg 
To: "address@hidden" 

address@hidden skrev:
> Hi -
> this is my first message here. Hope I do this right ;) Question: How
do 
> I pass parameters to a differential equation? lsode wants me to
declare 
> the diff. eq. as function xdot = something(x,t). i would rather like
to 
> declare this as xdot=something(x,t,parameter1,...). I help myself by 
> declaring global variables for every parameter. This doesn't look very

> elegant and transparent to me.
Welcome to the list :-)
I don't remember exactly how to call 'lsode', but the answer to your 
question is to create a local function. That is, you can do something 
like this:

   a = 2; b = 1;
   f = @(x, t) sin(a*x + b);
   lsode(f, 0, linspace(0, 5, 20))

Does that help/make sense?

-------------------------------------------------------

[Sorry for posting that way (I have to use a web client, hopefully the
html-style is disabled now)].

 Thank you, but that's not what I want. The function definition for f
sits in an .m-file. I do not want to "hide" the parameters to the
outside. It should be clear (made transparent) that the parameters,
which are declared in the main program, are used in solving the diff.
eq. With global variables this becomes obscure. It would be nice to pass
those parameters from the main program to lsode which then evaluates
them by calling f.

Thomas Nordhaus





reply via email to

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