[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question re function in .m file
From: |
Miquel Cabanas |
Subject: |
Re: Question re function in .m file |
Date: |
Wed, 15 Dec 2004 10:18:48 +0100 |
User-agent: |
Mutt/1.3.28i |
hi,
On Tue, Dec 14, 2004 at 08:15:49PM -0800, John B. Thoo wrote:
>
> octave:1> quaderror
> error: `x' undefined near line 2 column 11
> [...]
as mentioned in a previous reply, since quaderror is a function,
you are expected to pass all required arguments to it. That is,
if you define a function (eg `quaderror()' ) with an argument
(eg `x') you are expected to call it with *one* argument, for
instance,
> octave:1> quaderror (pi / 2)
> ans = 0.25000
that works ok because you are using it right
> Fewer errors when I type "quaderror (x)" in Octave, but still
> errors, yet can still evaluate the function:
>
> octave:2> quaderror (x)
> error: `x' undefined near line 2 column 12
> error: evaluating argument list element number 1
> octave:2> quaderror (pi / 2)
> ans = 0.25000
octave is for numerical calculations [1]. Since you have not
assigned a value to `x' before passing it to quaderror(), octave
warns you that `x' is not defined and that quaderror() can't do
anything with it. Try assigning a numerical value to x before calling
quaderror and you will see that it works,
octave:1> x = pi/2;
octave:2> quaderror(x)
ans = 0.25000
BTW, don't get fooled with `pi'. It is not a symbol, it's a
builtin numerical value,
octave:3> pi
pi = 3.1416
> That seems weird to me (that I can evaluate the function even
> with errors showing), and I am no less confused.
* there are no errors in your function, that's why it works; but
* you are making mistakes when calling it, and those are causing
the error messages displayed by octave.
On the other side, the octave behaviour is perfectly coherent:
1. you define functions with all required arguments,
2. you must pass functions the required arguments,
3. since octave is meant for numerical calculation [1] your
arguments must be numbers or numerical variables.
[1] actually, there's a package interfacing to Ginac, a symbolic
computation program. Visit octave-forge website for further
information.
Miquel
--
Miquel E Cabanas ------------------------------------------------------
SeRMN, Universitat Autonoma de Barcelona (address@hidden)
------------------------------------------o-oo--ooo---ooo--oo-o--------
-------------------------------------------------------------
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
-------------------------------------------------------------