[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Problem with Octave
From: |
Ted Harding |
Subject: |
RE: Problem with Octave |
Date: |
Mon, 09 Jun 2003 09:53:14 +0100 (BST) |
On 09-Jun-03 Fernando Cerda wrote:
> # Integrate t^2 from t=1 to t=3
> function xdot = f (x, t)
> xdot(1) = t ^ 2;
> endfunction
> x0=1;
> t = linspace (0, 3, 10)';
> x = lsode ("f", x0, t)
> plot(x,t)
>
> I saved it as testing.m. When I type the name of the file in the
> octave command line, it tells me there is and undefined statement.
Try putting a "dummy" expression as the first executable line of the file
(i.e. the "1;" below):
# Integrate t^2 from t=1 to t=3
1;
function xdot = f (x, t)
xdot(1) = t ^ 2;
endfunction
x0=1;
t = linspace (0, 3, 10)';
x = lsode ("f", x0, t)
plot(x,t)
The reason is that a file whose first executable line is "function ... "
is treated as a file which defines a function (and in this case you will
also get a warning that function name does not match file name), and not
as a script to be executed. On the other hand, if the first line is an
octave command (to compute something), then the file is treated as
a script to be executed, and you are also able to define functions
within a script (in fact several functions in one script, while in
a function-definition file you can only define one function).
Since the line "1;" tells octave to compute "1" but not to print it,
it has absolutely no effect on your octave environment, but it does
make octave decide to treat the remainder of the file as a script.
I hope this helps,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <address@hidden>
Fax-to-email: +44 (0)870 167 1972
Date: 09-Jun-03 Time: 09:53:14
------------------------------ XFMail ------------------------------
-------------------------------------------------------------
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
-------------------------------------------------------------