help-octave
[Top][All Lists]
Advanced

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

Re: Functions and handles


From: Fausto Arinos de A. Barbuto
Subject: Re: Functions and handles
Date: Fri, 6 Jun 2014 14:00:34 -0700 (PDT)


On Friday, June 6, 2014 5:42:36 PM, Juan Pablo Carbajal <address@hidden> wrote:

>
>
>On Fri, Jun 6, 2014 at 7:33 PM, Fausto Arinos de A. Barbuto
><address@hidden> wrote:
>> function xdot = f(x,t)
>>     r = 0.25;
>>     k = 1.4;
>>     a = 1.5;
>>     b = 0.16;
>>     c = 0.9;
>>     d = 0.8;
>>     xdot(1) = r*x(1)*(1 - x(1)/k) - a*x(1)*x(2)/(1 + b*x(1));
>>     xdot(2) = c*a*x(1)*x(2)/(1 + b*x(1)) - d*x(2);
>> endfunction
>
>r = 0.25;
>k = 1.4;
>a = 1.5;
>b = 0.16;
>c = 0.9;
>d = 0.8;
>f = @(x,t) [r*x(1)*(1 - x(1)/k) - a*x(1)*x(2)/(1 + b*x(1)); xdot(2) =
>
>c*a*x(1)*x(2)/(1 + b*x(1)) - d*x(2)];
>
>Does that suits you?
>

Yes, I think it does (haven't tried it), but suppose that "r", or "k",
or "a" are functions of "x" and/or "t" and f() is a function to be
called by ode45.  Will that work?  I'm afraid it won't.

The example I provided in my original post is not exactly the best.  I
have a better one home, but I'm working now.  Also, I forgot to mention
the "ode45" issue.  My bad.

All this because I don't seem to be able to call a function from within
an Octave script.  Apparently, to be callable, functions must be saved
as separate *.m files and I want it to be in the body of the said script.
Otherwise, I'm goofing terribly somewhere.

Thanks for your reply, JP, much appreciated.

Fausto




reply via email to

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