On Tue, Dec 14, 2004 at 08:27:13PM -0800, John B. Thoo wrote:
Thanks! Now, how do I understand why typing "source ..." gives no
errors when typing "quaderror" or "quaderror (x)" gives errors?
Paul described function-type m-file implications. "source" does
nearly the
same as keyboard input.
In your case - you use Paul suggested modification - it isn't
necessary to
do explicite "source" or quaderror call. Simply the single:
[v, ier, nfun, err] = quad ("quaderror", -1, 1)
must work because quad evaluating it first argument will call quaderror
function - if it isn't already definied octave search file
"quaderror.m" and
will signal a warnig in case function name mismatch (as in your case)
or
error if file "quaderror.m" is missing or it isn't function-type file
but a
script or whatever else.
function-type m-file is simply a file that have first statement
"function"
Mirek
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--------