help-octave
[Top][All Lists]
Advanced

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

Re: loading script file (function) in octave with script code


From: Jordi Gutiérrez Hermoso
Subject: Re: loading script file (function) in octave with script code
Date: Mon, 9 Jun 2008 19:20:08 -0500

I don't think you meant to reply to me only, so I'll move the
discussion back to the list.

On 09/06/2008, Siddhartha <address@hidden> wrote:
> > heres the code i have in xdot.m script file
>
>  % Must have first line NOT be function when loading script
>  files
>  function xdot = f(x,t)
>  j = 0.25;
>  a=1;
>  k=5;
>  b=0.6667;
>  c=0.667;
>  m=0.1;
>  xdot(1) = (j -k*x(3) +a*x(2));
>  xdot(2) = (b*(( j -k*x(3) +a*x(2)) - x(2)));
>  xdot(3)= (-c*(m -( j -k*x(3) +a*x(2))));
>
>  endfunction
>  x0 = [-0.55,0.6,0.8]
>  t = linspace(0,10,200);
>  x = lsode("f",x0,t);
>  figure;
>  plot(t,x)

Alright, you're putting both a script and a function into the same
file. I think there is a way to make that work, but the semantics of
it confuse me. Put your script into a different file than the function
file. I.e. move everything after "endfunction" above into its own
m-file, (e.g. "foo.m" or whatever) and execute that script instead.

I tried running your script this way, but I couldn't decide what a
proper f for your case. You should also define f.m in its own file.

I think there is a way to break the "one function per file" rule in
Octave, but I stick to my old habits of not doing so.

HTH,
- Jordi G. H.


reply via email to

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