help-octave
[Top][All Lists]
Advanced

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

Re: Question re function in .m file


From: John B. Thoo
Subject: Re: Question re function in .m file
Date: Tue, 14 Dec 2004 20:15:49 -0800

Paul---

Hi. Paul Laub suggested that I rename the function "quaderror", which I did. Now there is no warning about 'function name `f' does not agree with function file name' when I load the file, but there are still errors. Yet, I seem to be able to evaluate the function anyway.

octave:1> quaderror
error: `x' undefined near line 2 column 11
error: evaluating argument list element number 1
error: evaluating binary operator `-' near line 2, column 14
error: evaluating binary operator `-' near line 2, column 35
error: evaluating binary operator `.^' near line 2, column 50
error: evaluating assignment expression near line 2, column 3
error: called from `quaderror' in file `/Users/jbthoo/Documents/Work/CompletedWork/Reviews/PRIMUSreview200412/ quaderror.m'
octave:1> quaderror (pi / 2)
ans = 0.25000


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


That seems weird to me (that I can evaluate the function even with errors showing), and I am no less confused.

Thanks.
---John.


On Dec 14, 2004, at 6:01 PM, Paul Kienzle wrote:

These are expected errors.

When you type the function f directly into octave it
defines the function f.  When you put it into quaderror.m
it defines the function quaderror.m, which when loaded finds
that it is named f and warns you.

The x undefined error is because you didn't use
quaderror(x), but instead called it without any
arguments.  If you said 'f' on the command line
after defining f directly on the command line you
would have seen a similar error.

- Paul

On Dec 14, 2004, at 6:44 PM, John B. Thoo wrote:

Hi. I apologize if this is a FAQ. I put the following in a file I named "quaderror.m".

function y = f(x)
y = (cos (x) - 0.5 * (sin (x)).^2 - (cos (x)).^2).^2;
endfunction

But when I type "quaderror" in Octave, I get this:

octave:9> quaderror
warning: near line 9, column 1:

>>> quaderror


warning: function name `f' does not agree with function file name `/Users/jbthoo/Documents/Work/CompletedWork/Reviews/ PRIMUSreview200412/quaderror.m'
error: `x' undefined near line 2 column 11
error: evaluating argument list element number 1
error: evaluating binary operator `-' near line 2, column 14
error: evaluating binary operator `-' near line 2, column 35
error: evaluating binary operator `.^' near line 2, column 50
error: evaluating assignment expression near line 2, column 3
error: called from `quaderror' in file `/Users/jbthoo/Documents/Work/CompletedWork/Reviews/ PRIMUSreview200412/quaderror.m'

I don't understand the error messages. When I type the function directly in Octave, I do not get an error. What am I missing?

TIA.
---John.



-------------------------------------------------------------
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
-------------------------------------------------------------



reply via email to

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