[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:27:13 -0800 |
On Dec 14, 2004, at 6:29 PM, Miroslaw Kwasniak wrote:
On Tue, Dec 14, 2004 at 09:01:24PM -0500, 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
If John will preload function f from file he can use
source("quaderror.m")
or use "force script not function m-file" trick writting for example
0;
function y = f(x)
Hi, Mirek. I changed the function name to "quaderror (x)" in the .m
file, so that it is now
function y = quaderror (x)
y = (cos (x) - 0.5 * (sin (x)).^2 - (cos (x)).^2).^2;
endfunction
Typing "source ..." as you suggested gives me no errors. And I can use
it nicely.
octave:1> source "quaderror.m"
octave:2> [v, ier, nfun, err] = quad ("quaderror", -1, 1)
v = 0.0026418
ier = 0
nfun = 21
err = 2.9201e-16
octave:3> sqrt (v)
ans = 0.051398
Thanks! Now, how do I understand why typing "source ..." gives no
errors when typing "quaderror" or "quaderror (x)" gives errors?
Thanks again.
---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
-------------------------------------------------------------