help-octave
[Top][All Lists]
Advanced

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

function


From: Steve MC Han
Subject: function
Date: Sat, 8 Nov 2008 14:58:35 -0800 (PST)

Hi,
 
I am a beginner of Octave and I was wondering  if someone could help me.
 
I followed direction described here and typed one by one at the prompt and it works nicely and produce the graph;
 
http://www.delorie.com/gnu/docs/octave/octave_11.html
octave:8> 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
x0 = [1; 2];
t = linspace (0, 50, 200)';
x = lsode ("f", x0, t);
plot(t,x);
 
But if I make script file exactly the same then it produce a lot of error
messages
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
 

x0 = [1; 2];
 
t = linspace (0, 50, 200)';
x = lsode ("f", x0, t);
 plot(t,x);
The error messages are:
 
error 'x' udefined near line 15 column 14
error evaluating binary operator '*' near line 15 column 13
---- etc
 
Can someone figure out what's going on?
 
Thanks,


reply via email to

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