This is Info file octave.info, produced by Makeinfo-1.55 from the input
file octave.texi.

   Copyright (C) 1993, 1994, 1995 John W. Eaton.

   Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.

   Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided that
the entire resulting derived work is distributed under the terms of a
permission notice identical to this one.

   Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions.


File: octave.info,  Node: The while Statement,  Next: The for Statement,  Prev: The if Statement,  Up: Statements

The `while' Statement
=====================

   In programming, a "loop" means a part of a program that is (or at
least can be) executed two or more times in succession.

   The `while' statement is the simplest looping statement in Octave.
It repeatedly executes a statement as long as a condition is true.  As
with the condition in an `if' statement, the condition in a `while'
statement is considered true if its value is non-zero, and false if its
value is zero.  If the value of the conditional expression in an `if'
statement is a vector or a matrix, it is considered true only if *all*
of the elements are non-zero.

   Octave's `while' statement looks like this:

     while (CONDITION)
       BODY
     endwhile

Here BODY is a statement or list of statements that we call the "body"
of the loop, and CONDITION is an expression that controls how long the
loop keeps running.

   The first thing the `while' statement does is test CONDITION.  If
CONDITION is true, it executes the statement BODY.  After BODY has been
executed, CONDITION is tested again, and if it is still true, BODY is
executed again.  This process repeats until CONDITION is no longer
true.  If CONDITION is initially false, the body of the loop is never
executed.

   This example creates a variable `fib' that contains the elements of
the Fibonacci sequence.

     fib = ones (1, 10);
     i = 3;
     while (i <= 10)
       fib (i) = fib (i-1) + fib (i-2);
       i++;
     endwhile

Here the body of the loop contains two statements.

   The loop works like this: first, the value of `i' is set to 3.
Then, the `while' tests whether `i' is less than or equal to 10.  This
is the case when `i' equals 3, so the value of the `i'-th element of
`fib' is set to the sum of the previous two values in the sequence.
Then the `i++' increments the value of `i' and the loop repeats.  The
loop terminates when `i' reaches 11.

   A newline is not required between the condition and the body; but
using one makes the program clearer unless the body is very simple.


File: octave.info,  Node: The for Statement,  Next: The break Statement,  Prev: The while Statement,  Up: Statements

The `for' Statement
===================

   The `for' statement makes it more convenient to count iterations of a
loop.  The general form of the `for' statement looks like this:

     for VAR = EXPRESSION
       BODY
     endfor

The assignment expression in the `for' statement works a bit
differently than Octave's normal assignment statement.  Instead of
assigning the complete result of the expression, it assigns each column
of the expression to VAR in turn.  If EXPRESSION is either a row vector
or a scalar, the value of VAR will be a scalar each time the loop body
is executed.  If VAR is a column vector or a matrix, VAR will be a
column vector each time the loop body is executed.

   The following example shows another way to create a vector containing
the first ten elements of the Fibonacci sequence, this time using the
`for' statement:

     fib = ones (1, 10);
     for i = 3:10
       fib (i) = fib (i-1) + fib (i-2);
     endfor

This code works by first evaluating the expression `3:10', to produce a
range of values from 3 to 10 inclusive.  Then the variable `i' is
assigned the first element of the range and the body of the loop is
executed once.  When the end of the loop body is reached, the next
value in the range is assigned to the variable `i', and the loop body
is executed again.  This process continues until there are no more
elements to assign.

   In the `for' statement, BODY stands for any statement or list of
statements.

   Although it is possible to rewrite all `for' loops as `while' loops,
the Octave language has both statements because often a `for' loop is
both less work to type and more natural to think of.  Counting the
number of iterations is very common in loops and it can be easier to
think of this counting as part of looping rather than as something to
do inside the loop.


File: octave.info,  Node: The break Statement,  Next: The continue Statement,  Prev: The for Statement,  Up: Statements

The `break' Statement
=====================

   The `break' statement jumps out of the innermost `for' or `while'
loop that encloses it.  The `break' statement may only be used within
the body of a loop.  The following example finds the smallest divisor
of a given integer, and also identifies prime numbers:

     num = 103;
     div = 2;
     while (div*div <= num)
       if (rem (num, div) == 0)
         break;
       endif
       div++;
     endwhile
     if (rem (num, div) == 0)
       printf ("Smallest divisor of %d is %d\n", num, div)
     else
       printf ("%d is prime\n", num);
     endif

   When the remainder is zero in the first `while' statement, Octave
immediately "breaks out" of the loop.  This means that Octave proceeds
immediately to the statement following the loop and continues
processing.  (This is very different from the `exit' statement which
stops the entire Octave program.)

   Here is another program equivalent to the previous one.  It
illustrates how the CONDITION of a `while' statement could just as well
be replaced with a `break' inside an `if':

     num = 103;
     div = 2;
     while (1)
       if (rem (num, div) == 0)
         printf ("Smallest divisor of %d is %d\n", num, div);
         break;
       endif
       div++;
       if (div*div > num)
         printf ("%d is prime\n", num);
         break;
       endif
     endwhile


File: octave.info,  Node: The continue Statement,  Next: The unwind_protect Statement,  Prev: The break Statement,  Up: Statements

The `continue' Statement
========================

   The `continue' statement, like `break', is used only inside `for' or
`while' loops.  It skips over the rest of the loop body, causing the
next cycle around the loop to begin immediately.  Contrast this with
`break', which jumps out of the loop altogether.  Here is an example:

     # print elements of a vector of random
     # integers that are even.
     
     # first, create a row vector of 10 random
     # integers with values between 0 and 100:
     
     vec = round (rand (1, 10) * 100);
     
     # print what we're interested in:
     
     for x = vec
       if (rem (x, 2) != 0)
         continue;
       endif
       printf ("%d\n", x);
     endfor

   If one of the elements of VEC is an odd number, this example skips
the print statement for that element, and continues back to the first
statement in the loop.

   This is not a practical example of the `continue' statement, but it
should give you a clear understanding of how it works.  Normally, one
would probably write the loop like this:

     for x = vec
       if (rem (x, 2) == 0)
         printf ("%d\n", x);
       endif
     endfor


File: octave.info,  Node: The unwind_protect Statement,  Next: Continuation Lines,  Prev: The continue Statement,  Up: Statements

The `unwind_protect' Statement
==============================

   Octave supports a limited form of exception handling modelled after
the unwind-protect form of Lisp.

   The general form of an `unwind_protect' block looks like this:

     unwind_protect
       BODY
     unwind_protect_cleanup
       CLEANUP
     end_unwind_protect

Where BODY and CLEANUP are both optional and may contain any Octave
expressions or commands.  The statements in CLEANUP are guaranteed to
be executed regardless of how control exits BODY.

   This is useful to protect temporary changes to global variables from
possible errors.  For example, the following code will always restore
the original value of the built-in variable `do_fortran_indexing' even
if an error occurs while performing the indexing operation.

     save_do_fortran_indexing = do_fortran_indexing;
     unwind_protect
       do_fortran_indexing = "true";
       elt = a (idx)
     unwind_protect_cleanup
       do_fortran_indexing = save_do_fortran_indexing;
     end_unwind_protect

   Without `unwind_protect', the value of DO_FORTRAN_INDEXING would not
be restored if an error occurs while performing the indexing operation
because evaluation would stop at the point of the error and the
statement to restore the value would not be executed.


File: octave.info,  Node: Continuation Lines,  Prev: The unwind_protect Statement,  Up: Statements

Continuation Lines
==================

   In the Octave language, most statements end with a newline character
and you must tell Octave to ignore the newline character in order to
continue a statement from one line to the next.  Lines that end with the
characters `...' or `\' are joined with the following line before they
are divided into tokens by Octave's parser.  For example, the lines

     x = long_variable_name ...
         + longer_variable_name \
         - 42

form a single statement.  The backslash character on the second line
above is interpreted a continuation character, *not* as a division
operator.

   For continuation lines that do not occur inside string constants,
whitespace and comments may appear between the continuation marker and
the newline character.  For example, the statement

     x = long_variable_name ...     % comment one
         + longer_variable_name \   % comment two
         - 42                       % last comment

is equivalent to the one shown above.

   In some cases, Octave will allow you to continue lines without
having to specify continuation characters.  For example, it is possible
to write statements like

     if (big_long_variable_name == other_long_variable_name
         || not_so_short_variable_name > 4
         && y > x)
       some (code, here);
     endif

without having to clutter up the if statement with continuation
characters.


File: octave.info,  Node: Functions and Scripts,  Next: Built-in Variables,  Prev: Statements,  Up: Top

Functions and Script Files
**************************

   Complicated Octave programs can often be simplified by defining
functions.  Functions can be defined directly on the command line during
interactive Octave sessions, or in external files, and can be called
just like built-in ones.

* Menu:

* Defining Functions::
* Multiple Return Values::
* Variable-length Argument Lists::
* Variable-length Return Lists::
* Returning From a Function::
* Function Files::
* Script Files::
* Dynamically Linked Functions::
* Organization of Functions::


File: octave.info,  Node: Defining Functions,  Next: Multiple Return Values,  Prev: Functions and Scripts,  Up: Functions and Scripts

Defining Functions
==================

   In its simplest form, the definition of a function named NAME looks
like this:

     function NAME
       BODY
     endfunction

A valid function name is like a valid variable name: a sequence of
letters, digits and underscores, not starting with a digit.  Functions
share the same pool of names as variables.

   The function BODY consists of Octave statements.  It is the most
important part of the definition, because it says what the function
should actually *do*.

   For example, here is a function that, when executed, will ring the
bell on your terminal (assuming that it is possible to do so):

     function wakeup
       printf ("\a");
     endfunction

   The `printf' statement (*note Input and Output::.) simply tells
Octave to print the string `"\a"'.  The special character `\a' stands
for the alert character (ASCII 7).  *Note String Constants::.

   Once this function is defined, you can ask Octave to evaluate it by
typing the name of the function.

   Normally, you will want to pass some information to the functions you
define.  The syntax for passing parameters to a function in Octave is

     function NAME (ARG-LIST)
       BODY
     endfunction

where ARG-LIST is a comma-separated list of the function's arguments.
When the function is called, the argument names are used to hold the
argument values given in the call.  The list of arguments may be empty,
in which case this form is equivalent to the one shown above.

   To print a message along with ringing the bell, you might modify the
`beep' to look like this:

     function wakeup (message)
       printf ("\a%s\n", message);
     endfunction

   Calling this function using a statement like this

     wakeup ("Rise and shine!");

will cause Octave to ring your terminal's bell and print the message
`Rise and shine!', followed by a newline character (the `\n' in the
first argument to the `printf' statement).

   In most cases, you will also want to get some information back from
the functions you define.  Here is the syntax for writing a function
that returns a single value:

     function RET-VAR = NAME (ARG-LIST)
       BODY
     endfunction

The symbol RET-VAR is the name of the variable that will hold the value
to be returned by the function.  This variable must be defined before
the end of the function body in order for the function to return a
value.

   For example, here is a function that computes the average of the
elements of a vector:

     function retval = avg (v)
       retval = sum (v) / length (v);
     endfunction

   If we had written `avg' like this instead,

     function retval = avg (v)
       if (is_vector (v))
         retval = sum (v) / length (v);
       endif
     endfunction

and then called the function with a matrix instead of a vector as the
argument, Octave would have printed an error message like this:

     error: `retval' undefined near line 1 column 10
     error: evaluating index expression near line 7, column 1

because the body of the `if' statement was never executed, and `retval'
was never defined.  To prevent obscure errors like this, it is a good
idea to always make sure that the return variables will always have
values, and to produce meaningful error messages when problems are
encountered.  For example, `avg' could have been written like this:

     function retval = avg (v)
       retval = 0;
       if (is_vector (v))
         retval = sum (v) / length (v);
       else
         error ("avg: expecting vector argument");
       endif
     endfunction

   There is still one additional problem with this function.  What if
it is called without an argument?  Without additional error checking,
Octave will probably print an error message that won't really help you
track down the source of the error.  To allow you to catch errors like
this, Octave provides each function with an automatic variable called
`nargin'.  Each time a function is called, `nargin' is automatically
initialized to the number of arguments that have actually been passed
to the function.  For example, we might rewrite the `avg' function like
this:

     function retval = avg (v)
       retval = 0;
       if (nargin != 1)
         error ("usage: avg (vector)");
       endif
       if (is_vector (v))
         retval = sum (v) / length (v);
       else
         error ("avg: expecting vector argument");
       endif
     endfunction

   Although Octave does not consider it an error if you call a function
with more arguments than were expected, doing so is probably an error,
so we check for that possibility too, and issue the error message if
either too few or too many arguments have been provided.

   The body of a user-defined function can contain a `return'
statement.  This statement returns control to the rest of the Octave
program.  A `return' statement is assumed at the end of every function
definition.


File: octave.info,  Node: Multiple Return Values,  Next: Variable-length Argument Lists,  Prev: Defining Functions,  Up: Functions and Scripts

Multiple Return Values
======================

   Unlike many other computer languages, Octave allows you to define
functions that return more than one value.  The syntax for defining
functions that return multiple values is

     function [RET-LIST] = NAME (ARG-LIST)
       BODY
     endfunction

where NAME, ARG-LIST, and BODY have the same meaning as before, and
RET-LIST is a comma-separated list of variable names that will hold the
values returned from the function.  The list of return values must have
at least one element.  If RET-LIST has only one element, this form of
the `function' statement is equivalent to the form described in the
previous section.

   Here is an example of a function that returns two values, the maximum
element of a vector and the index of its first occurrence in the vector.

     function [max, idx] = vmax (v)
       idx = 1;
       max = v (idx);
       for i = 2:length (v)
         if (v (i) > max)
           max = v (i);
           idx = i;
         endif
       endfor
     endfunction

   In this particular case, the two values could have been returned as
elements of a single array, but that is not always possible or
convenient.  The values to be returned may not have compatible
dimensions, and it is often desirable to give the individual return
values distinct names.

   In addition to setting `nargin' each time a function is called,
Octave also automatically initializes `nargout' to the number of values
that are expected to be returned.  This allows you to write functions
that behave differently depending on the number of values that the user
of the function has requested.  The implicit assignment to the built-in
variable `ans' does not figure in the count of output arguments, so the
value of `nargout' may be zero.

   The `svd' and `lu' functions are examples of built-in functions that
behave differently depending on the value of `nargout'.

   It is possible to write functions that only set some return values.
For example, calling the function

     function [x, y, z] = f ()
       x = 1;
       z = 2;
     endfunction

as

     [a, b, c] = f ()

produces:

     a = 1
     
     b = [](0x0)
     
     c = 2


File: octave.info,  Node: Variable-length Argument Lists,  Next: Variable-length Return Lists,  Prev: Multiple Return Values,  Up: Functions and Scripts

Variable-length Argument Lists
==============================

   Octave has a real mechanism for handling functions that take an
unspecified number of arguments, so it is not necessary to place an
upper bound on the number of optional arguments that a function can
accept.

   Here is an example of a function that uses the new syntax to print a
header followed by an unspecified number of values:

     function foo (heading, ...)
       disp (heading);
       va_start ();
       while (--nargin)
         disp (va_arg ());
       endwhile
     endfunction

   The ellipsis that marks the variable argument list may only appear
once and must be the last element in the list of arguments.

   Calling `va_start()' positions an internal pointer to the first
unnamed argument and allows you to cycle through the arguments more than
once.  It is not necessary to call `va_start()' if you do not plan to
cycle through the arguments more than once.

   The function `va_arg()' returns the value of the next available
argument and moves the internal pointer to the next argument.  It is an
error to call `va_arg()' when there are no more arguments available.

   Sometimes it is useful to be able to pass all unnamed arguments to
another function.  The keyword ALL_VA_ARGS makes this very easy to do.
For example, given the functions

     function f (...)
       while (nargin--)
         disp (va_arg ())
       endwhile
     endfunction
     function g (...)
       f ("begin", all_va_args, "end")
     endfunction

the statement

     g (1, 2, 3)

prints

     begin
     1
     2
     3
     end

   The keyword `all_va_args' always stands for the entire list of
optional argument, so it is possible to use it more than once within the
same function without having to call `var_start ()'.  It can only be
used within functions that take a variable number of arguments.  It is
an error to use it in other contexts.


File: octave.info,  Node: Variable-length Return Lists,  Next: Returning From a Function,  Prev: Variable-length Argument Lists,  Up: Functions and Scripts

Variable-length Return Lists
============================

   Octave also has a real mechanism for handling functions that return
an unspecified number of values, so it is no longer necessary to place
an upper bound on the number of outputs that a function can produce.

   Here is an example of a function that uses the new syntax to produce
N values:

     function [...] = foo (n, x)
       for i = 1:n
         vr_val (i * x);
       endfor
     endfunction

   Each time `vr_val()' is called, it places the value of its argument
at the end of the list of values to return from the function.  Once
`vr_val()' has been called, there is no way to go back to the beginning
of the list and rewrite any of the return values.

   As with variable argument lists, the ellipsis that marks the variable
return list may only appear once and must be the last element in the
list of returned values.


File: octave.info,  Node: Returning From a Function,  Next: Function Files,  Prev: Variable-length Return Lists,  Up: Functions and Scripts

Returning From a Function
=========================

   The body of a user-defined function can contain a `return' statement.
This statement returns control to the rest of the Octave program.  It
looks like this:

     return

   Unlike the `return' statement in C, Octave's `return' statement
cannot be used to return a value from a function.  Instead, you must
assign values to the list of return variables that are part of the
`function' statement.  The `return' statement simply makes it easier to
exit a function from a deeply nested loop or conditional statement.

   Here is an example of a function that checks to see if any elements
of a vector are nonzero.

     function retval = any_nonzero (v)
       retval = 0;
       for i = 1:length (v)
         if (v (i) != 0)
           retval = 1;
           return;
         endif
       endfor
       printf ("no nonzero elements found\n");
     endfunction

   Note that this function could not have been written using the
`break' statement to exit the loop once a nonzero value is found
without adding extra logic to avoid printing the message if the vector
does contain a nonzero element.


File: octave.info,  Node: Function Files,  Next: Script Files,  Prev: Returning From a Function,  Up: Functions and Scripts

Function Files
==============

   Except for simple one-shot programs, it is not practical to have to
define all the functions you need each time you need them.  Instead, you
will normally want to save them in a file so that you can easily edit
them, and save them for use at a later time.

   Octave does not require you to load function definitions from files
before using them.  You simply need to put the function definitions in a
place where Octave can find them.

   When Octave encounters an identifier that is undefined, it first
looks for variables or functions that are already compiled and currently
listed in its symbol table.  If it fails to find a definition there, it
searches the list of directories specified by the built-in variable
`LOADPATH' for files ending in `.m' that have the same base name as the
undefined identifier.(1)  *Note User Preferences:: for a description of
`LOADPATH'.  Once Octave finds a file with a name that matches, the
contents of the file are read.  If it defines a *single* function, it
is compiled and executed.  *Note Script Files::, for more information
about how you can define more than one function in a single file.

   When Octave defines a function from a function file, it saves the
full name of the file it read and the time stamp on the file.  After
that, it checks the time stamp on the file every time it needs the
function.  If the time stamp indicates that the file has changed since
the last time it was read, Octave reads it again.

   Checking the time stamp allows you to edit the definition of a
function while Octave is running, and automatically use the new function
definition without having to restart your Octave session.  Checking the
time stamp every time a function is used is rather inefficient, but it
has to be done to ensure that the correct function definition is used.

   Octave assumes that function files in the
`/usr/local/lib/octave/1.1.1' directory tree will not change, so it
doesn't have to check their time stamps every time the functions
defined in those files are used.  This is normally a very good
assumption and provides a significant improvement in performance for the
function files that are distributed with Octave.

   If you know that your own function files will not change while you
are running Octave, you can improve performance by setting the variable
`ignore_function_time_stamp' to `"all"', so that Octave will ignore the
time stamps for all function files.  Setting it to `"system"' gives the
default behavior.  If you set it to anything else, Octave will check
the time stamps on all function files.

   ---------- Footnotes ----------

   (1)  The `.m' suffix was chosen for compatibility with MATLAB.


File: octave.info,  Node: Script Files,  Next: Dynamically Linked Functions,  Prev: Function Files,  Up: Functions and Scripts

Script Files
============

   A script file is a file containing (almost) any sequence of Octave
commands.  It is read and evaluated just as if you had typed each
command at the Octave prompt, and provides a convenient way to perform a
sequence of commands that do not logically belong inside a function.

   Unlike a function file, a script file must *not* begin with the
keyword `function'.  If it does, Octave will assume that it is a
function file, and that it defines a single function that should be
evaluated as soon as it is defined.

   A script file also differs from a function file in that the variables
named in a script file are not local variables, but are in the same
scope as the other variables that are visible on the command line.

   Even though a script file may not begin with the `function' keyword,
it is possible to define more than one function in a single script file
and load (but not execute) all of them at once.  To do this, the first
token in the file (ignoring comments and other white space) must be
something other than `function'.  If you have no other statements to
evaluate, you can use a statement that has no effect, like this:

     # Prevent Octave from thinking that this
     # is a function file:
     
     1;
     
     # Define function one:
     
     function one ()
       ...

   To have Octave read and compile these functions into an internal
form, you need to make sure that the file is in Octave's `LOADPATH',
then simply type the base name of the file that contains the commands.
(Octave uses the same rules to search for script files as it does to
search for function files.)

   If the first token in a file (ignoring comments) is `function',
Octave will compile the function and try to execute it, printing a
message warning about any non-whitespace characters that appear after
the function definition.

   Note that Octave does not try to lookup the definition of any
identifier until it needs to evaluate it.  This means that Octave will
compile the following statements if they appear in a script file, or
are typed at the command line,

     # not a function file:
     1;
     function foo ()
       do_something ();
     endfunction
     function do_something ()
       do_something_else ();
     endfunction

even though the function `do_something' is not defined before it is
referenced in the function `foo'.  This is not an error because the
Octave does not need to resolve all symbols that are referenced by a
function until the function is actually evaluated.

   Since Octave doesn't look for definitions until they are needed, the
following code will always print `bar = 3' whether it is typed directly
on the command line, read from a script file, or is part of a function
body, even if there is a function or script file called `bar.m' in
Octave's `LOADPATH'.

     eval ("bar = 3");
     bar

   Code like this appearing within a function body could fool Octave if
definitions were resolved as the function was being compiled.  It would
be virtually impossible to make Octave clever enough to evaluate this
code in a consistent fashion.  The parser would have to be able to
perform the `eval ()' statement at compile time, and that would be
impossible unless all the references in the string to be evaluated could
also be resolved, and requiring that would be too restrictive (the
string might come from user input, or depend on things that are not
known until the function is evaluated).


File: octave.info,  Node: Dynamically Linked Functions,  Next: Organization of Functions,  Prev: Script Files,  Up: Functions and Scripts

Dynamically Linked Functions
============================

   On some systems, Octave can dynamically load and execute functions
written in C++ or other compiled languages.  This currently only works
on systems that have a working version of the GNU dynamic linker,
`dld'. Unfortunately, `dld' does not work on very many systems, but
someone is working on making `dld' use the GNU Binary File Descriptor
library, `BFD', so that may soon change.  In any case, it should not be
too hard to make Octave's dynamic linking features work on other
systems using system-specific dynamic linking facilities.

   Here is an example of how to write a C++ function that Octave can
load.

     #include <iostream.h>
     
     #include "defun-dld.h"
     #include "tree-const.h"
     
     DEFUN_DLD ("hello", Fhello, Shello, -1, -1,
       "hello (...)\n\
     \n\
     Print greeting followed by the values of all the arguments passed.\n\
     Returns all the arguments passed.")
     {
       Octave_object retval;
       cerr << "Hello, world!\n";
       int nargin = args.length ();
       for (int i = 1; i < nargin; i++)
         retval (nargin-i-1) = args(i).eval (1);
       return retval;
     }

   Octave's dynamic linking features currently have the following
limitations.

   * Dynamic linking only works on systems that support the GNU dynamic
     linker, `dld'.

   * Clearing dynamically linked functions doesn't work.

   * Configuring Octave with `--enable-lite-kernel' seems to mostly work
     to make nonessential built-in functions dynamically loaded, but
     there also seem to be some problems.  For example, fsolve seems to
     always return `info == 3'.  This is difficult to debug since `gdb'
     won't seem to allow breakpoints to be set inside dynamically loaded
     functions.

   * Octave uses a lot of memory if the dynamically linked functions are
     compiled to include debugging symbols.  This appears to be a
     limitation with `dld', and can be avoided by not using `-g' to
     compile functions that will be linked dynamically.

   If you would like to volunteer to help improve Octave's ability to
dynamically link externally compiled functions, please contact
`bug-octave@che.utexas.edu'.


File: octave.info,  Node: Organization of Functions,  Prev: Dynamically Linked Functions,  Up: Functions and Scripts

Organization of Functions Distributed with Octave
=================================================

   Many of Octave's standard functions are distributed as function
files.  They are loosely organized by topic, in subdirectories of
`OCTAVE_HOME/lib/octave/VERSION/m', to make it easier to find them.

   The following is a list of all the function file subdirectories, and
the types of functions you will find there.

`control'
     Functions for design and simulation of automatic control systems.

`elfun'
     Elementary functions.

`general'
     Miscellaneous matrix manipulations, like `flipud', `rot90', and
     `triu', as well as other basic functions, like `is_matrix',
     `nargchk', etc.

`image'
     Image processing tools.  These functions require the X Window
     System.

`linear-algebra'
     Functions for linear algebra.

`miscellaneous'
     Functions that don't really belong anywhere else.

`plot'
     A set of functions that implement the MATLAB-like plotting
     functions.

`polynomial'
     Functions for manipulating polynomials.

`set'
     Functions for creating and manipulating sets of unique values.

`signal'
     Functions for signal processing applications.

`specfun'
     Special functions.

`special-matrix'
     Functions that create special matrix forms.

`startup'
     Octave's system-wide startup file.

`statistics'
     Statistical functions.

`strings'
     Miscellaneous string-handling functions.

   *Note User Preferences:: for an explanation of the built-in variable
`LOADPATH', and *Note Function Files:: for a description of the way
Octave resolves undefined variable and function names.


File: octave.info,  Node: Built-in Variables,  Next: Arithmetic,  Prev: Functions and Scripts,  Up: Top

Built-in Variables
******************

   Most Octave variables are available for you to use for your own
purposes; they never change except when your program assigns values to
them, and never affect anything except when your program examines them.

   A few variables have special built-in meanings.  Some of them, like
`pi' and `eps' provide useful predefined constant values.  Others, like
`do_fortran_indexing' and `page_screen_output' are examined
automatically by Octave, so that you can to tell Octave how to do
certain things.  There are also two special variables, `ans' and `PWD',
that are set automatically by Octave and carry information from the
internal workings of Octave to your program.

   This chapter documents all the built-in variables of Octave.  Most
of them are also documented in the chapters that describe functions
that use them, or are affected by their values.

* Menu:

* Predefined Constants::
* User Preferences::
* Other Built-in Variables::
* Summary of Preference Variables::


File: octave.info,  Node: Predefined Constants,  Next: User Preferences,  Prev: Built-in Variables,  Up: Built-in Variables

Predefined Constants
====================

`I, i, J, j'
     A pure imaginary number, defined as   `sqrt (-1)'.  The `I' and
     `J' forms are true constants, and cannot be modified.  The `i' and
     `j' forms are like ordinary variables, and may be used for other
     purposes.  However, unlike other variables, they once again assume
     their special predefined values if they are cleared *Note
     Miscellaneous Utilities::.

`Inf, inf'
     Infinity.  This is the result of an operation like 1/0, or an
     operation that results in a floating point overflow.

`NaN, nan'
     Not a number.  This is the result of an operation like `0/0', or
     `Inf - Inf', or any operation with a NaN.

`SEEK_SET'
`SEEK_CUR'
`SEEK_END'
     These variables may be used as the optional third argument for the
     function `fseek'.

`eps'
     The machine precision.  More precisely, `eps' is the smallest value
     such that `1+eps' is not equal to 1.  This number is
     system-dependent.  On machines that support 64 bit IEEE floating
     point arithmetic, `eps' is approximately  2.2204e-16.

`pi'
     The ratio of the circumference of a circle to its diameter.
     Internally, `pi' is computed as `4.0 * atan (1.0)'.

`realmax'
     The largest floating point number that is representable.  The
     actual value is system-dependent.  On machines that support 64 bit
     IEEE floating point arithmetic, `realmax' is approximately
     1.7977e+308

`realmin'
     The smallest floating point number that is representable.  The
     actual value is system-dependent.  On machines that support 64 bit
     IEEE floating point arithmetic, `realmin' is approximately
     2.2251e-308

`stdin'
`stdout'
`stderr'
     These variables are the file numbers corresponding to the standard
     input, standard output, and standard error streams.  These streams
     are preconnected and available when Octave starts.

