[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: How do script commands differ from term commands?
From: |
Hall, Benjamin |
Subject: |
RE: How do script commands differ from term commands? |
Date: |
Thu, 7 Apr 2005 08:09:49 -0400 |
How are you using your function "f"? Remember, Octave is designed for
numerical computations, so you have to explicitly give numeric values to the
function. For example:
octave:1> function y = f(x)
> y = cos(x/2)+x;
> end
octave:2> f(3)
ans = 3.0707
octave:4> x = [37 33 20 19];
octave:5> f(x)
ans =
37.940 32.298 19.161 18.003
But trying to run the function by itself doesn't work:
octave:3> f
error: `x' undefined near line 2 column 9
error: evaluating binary operator `/' near line 2, column 10
error: evaluating argument list element number 1
error: evaluating binary operator `+' near line 2, column 13
error: evaluating assignment expression near line 2, column 3
error: called from `f'
octave:3>
Does that help?
-----Original Message-----
From: Peder Møller [mailto:address@hidden
Sent: Wednesday, April 06, 2005 7:40 AM
To: octave help mailing list
Subject: Re: How do script commands differ from term commands?
Hmm...
I figure it is not a command problem, but rather an installation
problem since a simple file with the commands below does not work
either.
function y = f (x)
y = cos(x/2)+x;
end
Any ideas what the problem might be? The error message is:
error: `x' undefined near line 2 column 9
error: evaluating binary operator `/' near line 2, column 10
error: evaluating argument list element number 1
error: evaluating binary operator `+' near line 2, column 13
error: evaluating assignment expression near line 2, column 3
error: called from `f' in file `/octave_files/f.m'
Sorry for spamming in this way...
- Peder
On Apr 6, 2005 12:52 PM, Peder Møller <address@hidden> wrote:
> Hi,
>
> How do script commands differ from term commands?
>
> The lines below work fine if typed into the command term of Octave,
> however, they do NOT work if typed as they are into a .m file. What
> should I change?
>
> - Peder
>
> 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)
>
>
> --
> Something unknown is doing we don't know what;
>
> Sir Arthur Eddington (1882 - 1944)
>
--
Something unknown is doing we don't know what;
Sir Arthur Eddington (1882 - 1944)
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------