help-octave
[Top][All Lists]
Advanced

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

Re: problem solving ODE


From: Juan Pablo Carbajal
Subject: Re: problem solving ODE
Date: Thu, 17 Nov 2011 05:41:33 +0100

On Thu, Nov 17, 2011 at 4:49 AM, Doug Stewart <address@hidden> wrote:
>
>
>
> On Wed, Nov 16, 2011 at 10:26 PM, Denise Estrada <address@hidden>
> wrote:
>>
>> Hi, I'm new to Octave and I've been trying to learn by doing some
>> examples I found in the Octave-help manual.
>> The problem is that I get the same error all the time:
>>
>> function xdot = f (x, t)
>>
>>        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));
>>
>>      endfunction
>>  t = linspace (0, 500, 1000);
>>
>>      y = lsode ("f", x0, t);
>>
>> warning: function name `f' does not agree with function file name
>> `/home/den
>>
>> ise/Simoctave/otroejemplo2.m'
>>
>> parse error near line 11 of file /home/denise/Simoctave/otroejemplo2.m
>>
>> syntax error
>>
>> >>> t = linspace (0, 500, 1000);
>>
>> ^
>>
>> Thank's in advance
>>
>> _______________________________________________
>> Help-octave mailing list
>> address@hidden
>> https://mailman.cae.wisc.edu/listinfo/help-octave
>>
>
>
> Hi
> Tthis part of your program should be in a file by itself named  f.m
>
> function xdot = f (x, t)
>
>        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));
>
>      endfunction
>
> then from the prompt in Octave you can trt:
>
>  t = linspace (0, 500, 1000);
>
>      y = lsode ("f", x0, t);
>
>
> HTH
> Doug
> --
> DAS
> https://linuxcounter.net/user/206392.html
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
>
>

Hi,

As Doug said, the functions and the file containing it should have the
same name.

Otherwise you can pass a "function handle" instead the name of the
function, so your code would look like

function xdot = f (x, t)

       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));

endfunction

t = linspace (0, 500, 1000);

y = lsode (@f, x0, t);


to learn more about function handles chek the manual here
http://www.gnu.org/software/octave/doc/interpreter/Function-Handles-Inline-Functions-and-Anonymous-Functions.html


-- 
M. Sc. Juan Pablo Carbajal
-----
PhD Student
University of Zürich
http://ailab.ifi.uzh.ch/carbajal/


reply via email to

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