home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / octave-1.1.1p1-bin.lha / info / octave.info-7 (.txt) < prev    next >
GNU Info File  |  1996-10-12  |  50KB  |  1,020 lines

  1. This is Info file octave.info, produced by Makeinfo-1.64 from the input
  2. file octave.texi.
  3.    Copyright (C) 1993, 1994, 1995 John W. Eaton.
  4.    Permission is granted to make and distribute verbatim copies of this
  5. manual provided the copyright notice and this permission notice are
  6. preserved on all copies.
  7.    Permission is granted to copy and distribute modified versions of
  8. this manual under the conditions for verbatim copying, provided that
  9. the entire resulting derived work is distributed under the terms of a
  10. permission notice identical to this one.
  11.    Permission is granted to copy and distribute translations of this
  12. manual into another language, under the above conditions for modified
  13. versions.
  14. File: octave.info,  Node: Rearranging Matrices,  Prev: Finding Elements and Checking Conditions,  Up: Matrix Manipulation
  15. Rearranging Matrices
  16. ====================
  17.    The function `fliplr' reverses the order of the columns in a matrix,
  18. and `flipud' reverses the order of the rows.  For example,
  19.      octave:13> fliplr ([1, 2; 3, 4])
  20.      ans =
  21.      
  22.        2  1
  23.        4  3
  24.      
  25.      octave:13> flipud ([1, 2; 3, 4])
  26.      ans =
  27.      
  28.        3  4
  29.        1  2
  30.    The function `rot90 (A, N)' rotates a matrix counterclockwise in
  31. 90-degree increments.  The second argument is optional, and specifies
  32. how many 90-degree rotations are to be applied (the default value is
  33. 1).  Negative values of N rotate the matrix in a clockwise direction.
  34. For example,
  35.      rot90 ([1, 2; 3, 4], -1)
  36.      ans =
  37.      
  38.        3  1
  39.        4  2
  40. rotates the given matrix clockwise by 90 degrees.  The following are all
  41. equivalent statements:
  42.      rot90 ([1, 2; 3, 4], -1)
  43.      rot90 ([1, 2; 3, 4], 3)
  44.      rot90 ([1, 2; 3, 4], 7)
  45.    The function `reshape (A, M, N)' returns a matrix with M rows and N
  46. columns whose elements are taken from the matrix A.  To decide how to
  47. order the elements, Octave pretends that the elements of a matrix are
  48. stored in column-major order (like Fortran arrays are stored).
  49.    For example,
  50.      octave:13> reshape ([1, 2, 3, 4], 2, 2)
  51.      ans =
  52.      
  53.        1  3
  54.        2  4
  55.    If the variable `do_fortran_indexing' is `"true"', the `reshape'
  56. function is equivalent to
  57.      retval = zeros (m, n);
  58.      retval (:) = a;
  59. but it is somewhat less cryptic to use `reshape' instead of the colon
  60. operator.  Note that the total number of elements in the original
  61. matrix must match the total number of elements in the new matrix.
  62.    The function `sort' can be used to arrange the elements of a vector
  63. in increasing order.  For matrices, `sort' orders the elements in each
  64. column.
  65.    For example,
  66.      octave:13> sort (rand (4))
  67.      ans =
  68.      
  69.        0.065359  0.039391  0.376076  0.384298
  70.        0.111486  0.140872  0.418035  0.824459
  71.        0.269991  0.274446  0.421374  0.938918
  72.        0.580030  0.975784  0.562145  0.954964
  73.    The `sort' function may also be used to produce a matrix containing
  74. the original row indices of the elements in the sorted matrix.  For
  75. example,
  76.      s =
  77.      
  78.        0.051724  0.485904  0.253614  0.348008
  79.        0.391608  0.526686  0.536952  0.600317
  80.        0.733534  0.545522  0.691719  0.636974
  81.        0.986353  0.976130  0.868598  0.713884
  82.      
  83.      i =
  84.      
  85.        2  4  2  3
  86.        4  1  3  4
  87.        1  2  4  1
  88.        3  3  1  2
  89. These values may be used to recover the original matrix from the sorted
  90. version.  For example,
  91.    The `sort' function does not allow sort keys to be specified, so it
  92. can't be used to order the rows of a matrix according to the values of
  93. the elements in various columns(1) in a single call.  Using the second
  94. output, however, it is possible to sort all rows based on the values in
  95. a given column.  Here's an example that sorts the rows of a matrix
  96. based on the values in the third column.
  97.      octave:13> a = rand (4)
  98.      a =
  99.      
  100.        0.080606  0.453558  0.835597  0.437013
  101.        0.277233  0.625541  0.447317  0.952203
  102.        0.569785  0.528797  0.319433  0.747698
  103.        0.385467  0.124427  0.883673  0.226632
  104.      
  105.      octave:14> [s, i] = sort (a (:, 3));
  106.      octave:15> a (i, :)
  107.      ans =
  108.      
  109.        0.569785  0.528797  0.319433  0.747698
  110.        0.277233  0.625541  0.447317  0.952203
  111.        0.080606  0.453558  0.835597  0.437013
  112.        0.385467  0.124427  0.883673  0.226632
  113.    The functions `triu (A, K)' and `tril (A, K)' extract the upper or
  114. lower triangular part of the matrix A, and set all other elements to
  115. zero.  The second argument is optional, and specifies how many
  116. diagonals above or below the main diagonal should also be set to zero.
  117.    The default value of K is zero, so that `triu' and `tril' normally
  118. include the main diagonal as part of the result matrix.
  119.    If the value of K is negative, additional elements above (for
  120. `tril') or below (for `triu') the main diagonal are also selected.
  121.    The absolute value of K must not be greater than the number of sub-
  122. or super-diagonals.
  123.    For example,
  124.      octave:13> tril (rand (4), 1)
  125.      ans =
  126.      
  127.        0.00000  0.00000  0.00000  0.00000
  128.        0.09012  0.00000  0.00000  0.00000
  129.        0.01215  0.34768  0.00000  0.00000
  130.        0.00302  0.69518  0.91940  0.00000
  131. forms a lower triangular matrix from a random 4 by 4 matrix, omitting
  132. the main diagonal, and
  133.      octave:13> tril (rand (4), -1)
  134.      ans =
  135.      
  136.        0.06170  0.51396  0.00000  0.00000
  137.        0.96199  0.11986  0.35714  0.00000
  138.        0.16185  0.61442  0.79343  0.52029
  139.        0.68016  0.48835  0.63609  0.72113
  140. forms a lower triangular matrix from a random 4 by 4 matrix, including
  141. the main diagonal and the first super-diagonal.
  142.    ---------- Footnotes ----------
  143.    (1)  For example, to first sort based on the values in column 1, and
  144. then, for any values that are repeated in column 1, sort based on the
  145. values found in column 2, etc.
  146. File: octave.info,  Node: String Functions,  Next: System Utilities,  Prev: Matrix Manipulation,  Up: Top
  147. String Functions
  148. ****************
  149.    Octave currently has a limited ability to work with strings.
  150.    The function `strcmp (S1, S2)' compares two strings, returning 1 if
  151. they are the same, and 0 otherwise.
  152.    *Note: For compatibility with MATLAB, Octave's strcmp function
  153. returns 1 if the strings are equal, and 0 otherwise.  This is just the
  154. opposite of the corresponding C library function.*
  155.    The functions `int2str' and `num2str' convert a numeric argument to
  156. a string.  These functions are not very flexible, but are provided for
  157. compatibility with MATLAB.  For better control over the results, use
  158. `sprintf' (*note Formatted Output::.).
  159.    The function `setstr' can be used to convert a vector to a string.
  160. Each element of the vector is converted to the corresponding ASCII
  161. character.  For example,
  162.      setstr ([97, 98, 99])
  163. creates the string
  164.      abc
  165.    The function `undo_string_escapes (STRING)' converts special
  166. characters in strings back to their escaped forms.  For example, the
  167. expression
  168.      bell = "\a";
  169. assigns the value of the alert character (control-g, ASCII code 7) to
  170. the string variable BELL.  If this string is printed, the system will
  171. ring the terminal bell (if it is possible).  This is normally the
  172. desired outcome.  However, sometimes it is useful to be able to print
  173. the original representation of the string, with the special characters
  174. replaced by their escape sequences.  For example,
  175.      octave:13> undo_string_escapes (bell)
  176.      ans = \a
  177. replaces the unprintable alert character with its printable
  178. representation.  *Note String Constants::, for a description of string
  179. escapes.
  180. File: octave.info,  Node: System Utilities,  Next: Command History Functions,  Prev: String Functions,  Up: Top
  181. System Utilities
  182. ****************
  183.    This chapter describes the functions that are available to allow you
  184. to get information about what is happening outside of Octave, while it
  185. is still running, and use this information in your program.  For
  186. example, you can get information about environment variables, the
  187. current time, and even start other programs from the Octave prompt.
  188. * Menu:
  189. * Timing Utilities::
  190. * Interacting with the OS::
  191. * System Information::
  192. * Other Functions::
  193. File: octave.info,  Node: Timing Utilities,  Next: Interacting with the OS,  Prev: System Utilities,  Up: System Utilities
  194. Timing Utilities
  195. ================
  196.    The function `clock' returns a vector containing the current year,
  197. month (1-12), day (1-31), hour (0-23), minute (0-59) and second (0-60).
  198. For example,
  199.      octave:13> clock
  200.      ans =
  201.      
  202.        1993     8    20     4    56     1
  203.    The function clock is more accurate on systems that have the
  204. `gettimeofday' function.
  205.    To get the date as a character string in the form DD-MMM-YY, use the
  206. command `date'.  For example,
  207.      octave:13> date
  208.      ans = 20-Aug-93
  209.    Octave also has functions for computing time intervals and CPU time
  210. used.  The functions `tic' and `toc' can be used to set and check a
  211. wall-clock timer.  For example,
  212.      tic ();
  213.      # many computations later...
  214.      elapsed_time = toc ();
  215. will set the variable `elapsed_time' to the number of seconds since the
  216. most recent call to the function `tic'.
  217.    The function `etime' provides another way to get elapsed wall-clock
  218. time by returning the difference (in seconds) between two time values
  219. returned from `clock'.  For example:
  220.      t0 = clock ();
  221.      # many computations later...
  222.      elapsed_time = etime (clock (), t0);
  223. will set the variable `elapsed_time' to the number of seconds since the
  224. variable `t0' was set.
  225.    The function `cputime' allows you to obtain information about the
  226. amount of CPU time your Octave session is using.  For example,
  227.      [total, user, system] = cputime ();
  228. returns the CPU time used by your Octave session.  The first output is
  229. the total time spent executing your process and is equal to the sum of
  230. second and third outputs, which are the number of CPU seconds spent
  231. executing in user mode and the number of CPU seconds spent executing in
  232. system mode, respectively.
  233.    Finally, Octave's function `is_leap_year' returns 1 if the given
  234. year is a leap year and 0 otherwise.  If no arguments are provided,
  235. `is_leap_year' will use the current year.  For example,
  236.      octave:13> is_leap_year (2000)
  237.      ans = 1
  238. Contrary to what many people who post misinformation to Usenet
  239. apparently believe, Octave knows that the year 2000 will be a leap year.
  240. File: octave.info,  Node: Interacting with the OS,  Next: System Information,  Prev: Timing Utilities,  Up: System Utilities
  241. Interacting with the OS
  242. =======================
  243.    You can execute any shell command using the function `system (CMD,
  244. FLAG)'.  The second argument is optional.  If it is present, the output
  245. of the command is returned by `system' as a string.  If it is not
  246. supplied, any output from the command is printed, with the standard
  247. output filtered through the pager.  For example,
  248.      users = system ("finger", 1)
  249. places the output of the command `finger' in the variable `users'.
  250.    If you want to execute a shell command and have it behave as if it
  251. were typed directly from the shell prompt, you may need to specify extra
  252. arguments for the command.  For example, to get `bash' to behave as an
  253. interactive shell, you can type
  254.      system ("bash -i >/dev/tty");
  255.    The first argument, `-i', tells `bash' to behave as an interactive
  256. shell, and the redirection of the standard output stream prevents any
  257. output produced by `bash' from being sent back to Octave, where it
  258. would be buffered until Octave displays another prompt.
  259.    The `system' function can return two values.  The first is any
  260. output from the command that was written to the standard output stream,
  261. and the second is the output status of the command.  For example,
  262.      [output, status] = system ("echo foo; exit 2");
  263. will set the variable `output' to the string `foo', and the variable
  264. `status' to the integer `2'.
  265.    The name `shell_cmd' exists for compatibility with earlier versions
  266. of Octave.
  267.    You can find the values of environment variables using the function
  268. `getenv'.  For example,
  269.      getenv ("PATH")
  270. returns a string containing the value of your path.
  271.    The functions `clc', and `home' clear your terminal screen and move
  272. the cursor to the upper left corner.
  273.    You can change the current working directory using the `cd' command.
  274. Tilde expansion is performed on the path.  For example,
  275.      cd ~/octave
  276. Changes the current working directory to `~/octave'.  If the directory
  277. does not exist, an error message is printed and the working directory
  278. is not changed.
  279.    The name `chdir' is an alias for `cd'.
  280.    The command `pwd' prints the current working directory.
  281.    The functions `dir' and `ls' list directory contents.  For example,
  282.      octave:13> ls -l
  283.      total 12
  284.      -rw-r--r--   1 jwe      users        4488 Aug 19 04:02 foo.m
  285.      -rw-r--r--   1 jwe      users        1315 Aug 17 23:14 bar.m
  286.    The `dir' and `ls' commands are implemented by calling your system's
  287. directory listing command, so the available options may vary from
  288. system to system.
  289. File: octave.info,  Node: System Information,  Next: Other Functions,  Prev: Interacting with the OS,  Up: System Utilities
  290. System Information
  291. ==================
  292.    If possible, `computer' prints a string of the form CPU-VENDOR-OS
  293. that identifies the kind of computer Octave is running on.  For example,
  294.      octave:13> computer
  295.      sparc-sun-sunos4.1.2
  296.    The function `isieee' returns 1 if your computer claims to conform
  297. to the IEEE standard for floating point calculations.
  298.    The function `version' returns Octave's version number as a string.
  299. This is also the value of the built-in variable `OCTAVE_VERSION'.
  300. *Note Built-in Variables::.
  301. File: octave.info,  Node: Other Functions,  Prev: System Information,  Up: System Utilities
  302. Other Functions
  303. ===============
  304.    The function `pause' allows you to suspend the execution of a
  305. program.  If invoked without any arguments, Octave waits until you type
  306. a character.  With a numeric argument, it pauses for the given number of
  307. seconds.  For example, the following statement prints a message and then
  308. waits 5 seconds before clearing the screen.
  309.      fprintf (stderr, "wait please...\n"), pause (5), clc
  310. File: octave.info,  Node: Command History Functions,  Next: Help,  Prev: System Utilities,  Up: Top
  311. Command History Functions
  312. *************************
  313.    Octave provides three functions for viewing, editing, and re-running
  314. chunks of commands from the history list.
  315.    The function `history' displays a list of commands that you have
  316. executed.  It also allows you to write the current history to a file for
  317. safe keeping, and to replace the history list with the commands stored
  318. in a named file.  Valid arguments are:
  319. `-w file'
  320.      Write the current history to the named file.  If the name is
  321.      omitted, use the default history file (normally `~/.octave_hist').
  322. `-r file'
  323.      Read the named file, replacing the current history list with its
  324.      contents.  If the name is omitted, use the default history file
  325.      (normally `~/.octave_hist').
  326.      Only display the most recent `N' lines of history.
  327.      Don't number the displayed lines of history.  This is useful for
  328.      cutting and pasting commands if you are using the X Window System.
  329.    For example, to display the five most recent commands that you have
  330. typed without displaying line numbers, use the command `history -q 5'.
  331.    The function `edit_history' allows you to edit a block of commands
  332. from the history list using the editor named by the environment
  333. variable `EDITOR', or the default editor (normally `vi').  It is often
  334. more convenient to use `edit_history' to define functions rather than
  335. attempting to enter them directly on the command line.  By default, the
  336. block of commands is executed as soon as you exit the editor.  To avoid
  337. executing any commands, simply delete all the lines from the buffer
  338. before exiting the editor.
  339.    The `edit_history' command takes two optional arguments specifying
  340. the history numbers of first and last commands to edit.  For example,
  341. the command
  342.      edit_history 13
  343. extracts all the commands from the 13th through the last in the history
  344. list.  The command
  345.      edit_history 13 169
  346. only extracts commands 13 through 169.  Specifying a larger number for
  347. the first command than the last command reverses the list of commands
  348. before placing them in the buffer to be edited.  If both arguments are
  349. omitted, the previous command in the history list is used.
  350.    The command `run_history' is like `edit_history', except that the
  351. editor is not invoked, and the commands are simply executed as they
  352. appear in the history list.
  353.    The `diary' command allows you to create a list of all commands
  354. *and* the output they produce, mixed together just as you see them on
  355. your terminal.
  356.    For example, the command
  357.      diary on
  358. tells Octave to start recording your session in a file called `diary'
  359. in your current working directory.  To give Octave the name of the file
  360. write to, use the a command like
  361.      diary my-diary.txt
  362. Then Octave will write all of your commands to the file `my-diary.txt'.
  363.    To stop recording your session, use the command
  364.      diary off
  365. Without any arguments, `diary' toggles the current diary state.
  366. File: octave.info,  Node: Help,  Next: Programming Utilities,  Prev: Command History Functions,  Up: Top
  367.    Octave's `help' command can be used to print brief usage-style
  368. messages, or to display information directly from an on-line version of
  369. the printed manual, using the GNU Info browser.  If invoked without any
  370. arguments, `help' prints a list of all the available operators,
  371. functions, and built-in variables.  If the first argument is `-i', the
  372. `help' command searches the index of the on-line version of this manual
  373. for the given topics.
  374.    For example, the command
  375.      help help
  376. prints a short message describing the `help' command, and
  377.      help -i help
  378. starts the GNU Info browser at this node in the on-line version of the
  379. manual.
  380.    *Note Using Info::, for complete details about how to use the GNU
  381. Info browser to read the on-line version of the manual.
  382. File: octave.info,  Node: Programming Utilities,  Next: Amusements,  Prev: Help,  Up: Top
  383. Programming Utilities
  384. *********************
  385. * Menu:
  386. * Evaluating Strings as Commands::
  387. * Miscellaneous Utilities::
  388. File: octave.info,  Node: Evaluating Strings as Commands,  Next: Miscellaneous Utilities,  Prev: Programming Utilities,  Up: Programming Utilities
  389. Evaluating Strings as Commands
  390. ==============================
  391.    It is often useful to evaluate a string as if it were an Octave
  392. program, or use a string as the name of a function to call.  These
  393. functions are necessary in order to evaluate commands that are not
  394. known until run time, or to write functions that will need to call
  395. user-supplied functions.
  396.    The function `eval (COMMAND)' parses COMMAND and evaluates it as if
  397. it were an Octave program, returning the last value computed.  The
  398. COMMAND is evaluated in the current context, so any results remain
  399. available after `eval' returns.  For example,
  400.      octave:13> a
  401.      error: `a' undefined
  402.      octave:14> eval ("a = 13")
  403.      a = 13
  404.      ans = 13
  405.      octave:15> a
  406.      a = 13
  407.    In this case, two values are printed:  one for the expression that
  408. was evaluated, and one for the value returned from `eval'.  Just as
  409. with any other expression, you can turn printing off by ending the
  410. expression in a semicolon.  For example,
  411.      octave:13> a
  412.      error: `a' undefined
  413.      octave:14> eval ("a = 13;")
  414.      ans = 13
  415.      octave:15> a
  416.      a = 13
  417.    The function `feval (NAME, ...)' can be used to evaluate the
  418. function named NAME.  Any arguments after the first are passed on to
  419. the named function.  For example,
  420.      octave:12> feval ("acos", -1)
  421.      ans = 3.1416
  422. calls the function `acos' with the argument `-1'.
  423.    The function `feval' is necessary in order to be able to write
  424. functions that call user-supplied functions, because Octave does not
  425. have a way to declare a pointer to a function (like C) or to declare a
  426. special kind of variable that can be used to hold the name of a function
  427. (like `EXTERNAL' in Fortran).  Instead, you must refer to functions by
  428. name, and use `feval' to call them.
  429.    For example, here is a simple-minded function for finding the root
  430. of a function of one variable:
  431.      function result = newtroot (fname, x)
  432.      
  433.      # usage: newtroot (fname, x)
  434.      #
  435.      #   fname : a string naming a function f(x).
  436.      #   x     : initial guess
  437.      
  438.        delta = tol = sqrt (eps);
  439.        maxit = 200;
  440.        fx = feval (fname, x);
  441.        for i = 1:maxit
  442.          if (abs (fx) < tol)
  443.            result = x;
  444.            return;
  445.          else
  446.            fx_new = feval (fname, x + delta);
  447.            deriv = (fx_new - fx) / delta;
  448.            x = x - fx / deriv;
  449.            fx = fx_new;
  450.          endif
  451.        endfor
  452.      
  453.        result = x;
  454.      
  455.      endfunction
  456.    Note that this is only meant to be an example of calling
  457. user-supplied functions and should not be taken too seriously.  In
  458. addition to using a more robust algorithm, any serious code would check
  459. the number and type of all the arguments, ensure that the supplied
  460. function really was a function, etc.
  461. File: octave.info,  Node: Miscellaneous Utilities,  Prev: Evaluating Strings as Commands,  Up: Programming Utilities
  462. Miscellaneous Utilities
  463. =======================
  464.    The following functions allow you to determine the size of a
  465. variable or expression, find out whether a variable exists, print error
  466. messages, or delete variable names from the symbol table.
  467. `columns (A)'
  468.      Return the number of columns of A.
  469. `rows (A)'
  470.      Return the number of rows of A.
  471. `length (A)'
  472.      Return the number of rows of A or the number of columns of A,
  473.      whichever is larger.
  474. `size (A [, N])'
  475.      Return the number rows and columns of A.
  476.      With one input argument and one output argument, the result is
  477.      returned in a 2 element row vector.  If there are two output
  478.      arguments, the number of rows is assigned to the first, and the
  479.      number of columns to the second.  For example,
  480.           octave:13> size ([1, 2; 3, 4; 5, 6])
  481.           ans =
  482.           
  483.             3  2
  484.           
  485.           octave:14> [nr, nc] = size ([1, 2; 3, 4; 5, 6])
  486.           nr = 3
  487.           
  488.           nc = 2
  489.      If given a second argument of either 1 or 2, `size' will return
  490.      only the row or column dimension.  For example
  491.           octave:15> size ([1, 2; 3, 4; 5, 6], 2)
  492.           ans = 2
  493.      returns the number of columns in the given matrix.
  494. `is_global (A)'
  495.      Return 1 if A is globally visible.  Otherwise, return 0.
  496. `is_matrix (A)'
  497.      Return 1 if A is a matrix.  Otherwise, return 0.
  498. `is_vector (A)'
  499.      Return 1 if A is a vector.  Otherwise, return 0.
  500. `is_scalar (A)'
  501.      Return 1 if A is a scalar.  Otherwise, return 0.
  502. `is_square (X)'
  503.      If X is a square matrix, then return the dimension of X.
  504.      Otherwise, return 0.
  505. `is_symmetric (X, TOL)'
  506.      If X is symmetric within the tolerance specified by TOL, then
  507.      return the dimension of X.  Otherwise, return 0.  If TOL is
  508.      omitted, use a tolerance equal to the machine precision.
  509. `isstr (A)'
  510.      Return 1 if A is a string.  Otherwise, return 0.
  511. `isempty (A)'
  512.      Return 1 if A is an empty matrix (either the number of rows, or
  513.      the number of columns, or both are zero).  Otherwise, return 0.
  514. `clear PATTERN ...'
  515.      Delete the names matching the given patterns from the symbol
  516.      table.  The pattern may contain the following special characters:
  517.     `?'
  518.           Match any single character.
  519.     `*'
  520.           Match zero or more characters.
  521.     `[ LIST ]'
  522.           Match the list of characters specified by LIST.  If the first
  523.           character is `!' or `^', match all characters except those
  524.           specified by LIST.  For example, the pattern `[a-zA-Z]' will
  525.           match all lower and upper case alphabetic characters.
  526.      For example, the command
  527.           clear foo b*r
  528.      clears the name `foo' and all names that begin with the letter `b'
  529.      and end with the letter `r'.
  530.      If `clear' is called without any arguments, all user-defined
  531.      variables (local and global) are cleared from the symbol table.  If
  532.      `clear' is called with at least one argument, only the visible
  533.      names matching the arguments are cleared.  For example, suppose
  534.      you have defined a function `foo', and then hidden it by
  535.      performing the assignment `foo = 2'.  Executing the command `clear
  536.      foo' once will clear the variable definition and restore the
  537.      definition of `foo' as a function.  Executing `clear foo' a second
  538.      time will clear the function definition.
  539.      This command may not be used within a function body.
  540. `who OPTIONS PATTERN ...'
  541.      List currently defined symbols matching the given patterns.  The
  542.      following are valid options.  They may be shortened to one
  543.      character but may not be combined.
  544.     `-all'
  545.           List all currently defined symbols.
  546.     `-builtins'
  547.           List built-in variables and functions.  This includes all
  548.           currently compiled function files, but does not include all
  549.           function files that are in the `LOADPATH'.
  550.     `-functions'
  551.           List user-defined functions.
  552.     `-long'
  553.           Print a long listing including the type and dimensions of any
  554.           symbols.  The symbols in the first column of output indicate
  555.           whether it is possible to redefine the symbol, and whether it
  556.           is possible for it to be cleared.
  557.     `-variables'
  558.           List user-defined variables.
  559.      Valid patterns are the same as described for the `clear' command
  560.      above.  If no patterns are supplied, all symbols from the given
  561.      category are listed.  By default, only user defined functions and
  562.      variables visible in the local scope are displayed.
  563.      The command `whos' is equivalent to `who -long'.
  564. `exist (NAME)'
  565.      Return 1 if the name exists as a variable, and 2 if the name (after
  566.      appending `.m') is a function file in the path.  Otherwise, return
  567.      0.
  568. `error (MSG)'
  569.      Print the message MSG, prefixed by the string `error: ', and set
  570.      Octave's internal error state such that control will return to the
  571.      top level without evaluating any more commands.  This is useful for
  572.      aborting from functions.
  573.      If MSG does not end with a new line character, Octave will print a
  574.      traceback of all the function calls leading to the error.  For
  575.      example,
  576.           function f () g () end
  577.           function g () h () end
  578.           function h () nargin == 1 || error ("nargin != 1"); end
  579.           f ()
  580.           error: nargin != 1
  581.           error: evaluating index expression near line 1, column 30
  582.           error: evaluating binary operator `||' near line 1, column 27
  583.           error: called from `h'
  584.           error: called from `g'
  585.           error: called from `f'
  586.      produces a list of messages that can help you to quickly locate the
  587.      exact location of the error.
  588.      If MSG ends in a new line character, Octave will only print MSG
  589.      and will not display any traceback messages as it returns control
  590.      to the top level.  For example, modifying the error message in the
  591.      previous example to end in a new line causes Octave to only print
  592.      a single message:
  593.           function h () nargin == 1 || error ("nargin != 1\n"); end
  594.           f ()
  595.           error: nargin != 1
  596. `warning (MSG)'
  597.      Print the message MSG prefixed by the string `warning: '.
  598. `usage (MSG)'
  599.      Print the message MSG, prefixed by the string `usage: ', and set
  600.      Octave's internal error state such that control will return to the
  601.      top level without evaluating any more commands.  This is useful for
  602.      aborting from functions.
  603.      After `usage' is evaluated, Octave will print a traceback of all
  604.      the function calls leading to the usage message.
  605. `perror (NAME, NUM)'
  606.      Print the error message for function NAME corresponding to the
  607.      error number NUM.  This function is intended to be used to print
  608.      useful error messages for those functions that return numeric error
  609.      codes.
  610. `menu (TITLE, OPT1, ...)'
  611.      Print a title string followed by a series of options.  Each option
  612.      will be printed along with a number.  The return value is the
  613.      number of the option selected by the user.  This function is
  614.      useful for interactive programs.  There is no limit to the number
  615.      of options that may be passed in, but it may be confusing to
  616.      present more than will fit easily on one screen.
  617. `document SYMBOL TEXT'
  618.      Set the documentation string for SYMBOL to TEXT.
  619. `file_in_path (PATH, FILE)'
  620.      Return the absolute name name of FILE if it can be found in PATH.
  621.      The value of PATH should be a colon-separated list of directories
  622.      in the format described for the built-in variable `LOADPATH'.
  623.      If the file cannot be found in the path, an empty matrix is
  624.      returned.  For example,
  625.           octave:13> file_in_path (LOADPATH, "nargchk.m")
  626.           ans = /usr/local/lib/octave/1.1.0/m/general/nargchk.m
  627. `nargchk (NARGIN_MIN, NARGIN_MAX, N)'
  628.      If N is in the range NARGIN_MIN through NARGIN_MAX inclusive,
  629.      return the empty matrix.  Otherwise, return a message indicating
  630.      whether N is too large or too small.
  631.      This is useful for checking to see that the number of arguments
  632.      supplied to a function is within an acceptable range.
  633. `octave_tmp_file_name'
  634.      Return a unique temporary file name.
  635.      Since the named file is not opened, by `octave_tmp_file_name', it
  636.      is possible (though relatively unlikely) that it will not be
  637.      available by the time your program attempts to open it.
  638. `type NAME ...'
  639.      Display the definition of each NAME that refers to a function.
  640.      Currently, Octave can only display functions that can be compiled
  641.      cleanly, because it uses its internal representation of the
  642.      function to recreate the program text.
  643.      Comments are not displayed because Octave's currently discards
  644.      them as it converts the text of a function file to its internal
  645.      representation.  This problem may be fixed in a future release.
  646. `which NAME ...'
  647.      Display the type of each NAME.  If NAME is defined from a function
  648.      file, the full name of the file is also displayed.
  649. File: octave.info,  Node: Amusements,  Next: Installation,  Prev: Programming Utilities,  Up: Top
  650. Amusements
  651. **********
  652.    Octave cannot promise that you will actually win the lotto, but it
  653. can pick your numbers for you.  The function `texas_lotto' will select
  654. six numbers between 1 and 50.
  655.    The function `list_primes (N)' uses a brute-force algorithm to
  656. compute the first N primes.
  657.    Other amusing functions include `casesen', `flops', `sombrero',
  658. `exit', and `quit'.
  659. File: octave.info,  Node: Installation,  Next: Trouble,  Prev: Amusements,  Up: Top
  660. Installing Octave
  661. *****************
  662.    Here is the procedure for installing Octave from scratch on a Unix
  663. system.  For instructions on how to install the binary distributions of
  664. Octave, see *Note Binary Distributions::.
  665.    * Run the shell script `configure'.  This will determine the features
  666.      your system has (or doesn't have) and create a file named Makefile
  667.      from each of the files named Makefile.in.
  668.      Here is a summary of the configure options that are most
  669.      frequently used when building Octave:
  670.     `--prefix=PREFIX'
  671.           Install Octave in subdirectories below PREFIX.  The default
  672.           value of PREFIX is `/usr/local'.
  673.     `--srcdir=DIR'
  674.           Look for Octave sources in the directory DIR.
  675.     `--with-f2c'
  676.           Use f2c even if Fortran compiler is available.
  677.     `--enable-dld'
  678.           Use DLD to make Octave capable of dynamically linking
  679.           externally compiled functions.  This only works on systems
  680.           that have a working port of DLD.
  681.     `--enable-lite-kernel'
  682.           Compile smaller kernel.  This currently requires DLD so that
  683.           Octave can load functions at run time that are not loaded at
  684.           compile time.
  685.     `--help'
  686.           Print a summary of the options recognized by the configure
  687.           script.
  688.      See the file INSTALL for more information about the command line
  689.      options used by configure.  That file also contains instructions
  690.      for compiling in a directory other than where the source is
  691.      located.
  692.    * Run make.
  693.      You will need a recent version of GNU make.  Modifying Octave's
  694.      Makefiles to work with other make programs is probably not worth
  695.      your time.  We recommend you get and compile GNU make instead.
  696.      For plotting, you will need to have gnuplot installed on your
  697.      system.  Gnuplot is a command-driven interactive function plotting
  698.      program.  Gnuplot is copyrighted, but freely distributable.  The
  699.      `gnu' in gnuplot is a coincidence--it is not related to the GNU
  700.      project or the FSF in any but the most peripheral sense.
  701.      For version 1.1.1, you must have the GNU C++ compiler (gcc)
  702.      version 2.6.3 or later to compile Octave.  You will also need
  703.      version 2.6.1 of the GNU C++ class library (libg++).  If you plan
  704.      to modify the parser you will also need GNU bison and fles.  If
  705.      you modify the documentation, you will need GNU Texinfo, along
  706.      with the patch for the makeinfo program that is distributed with
  707.      Octave.
  708.      GNU make, gcc, and libg++, gnuplot, bison, flex, and Texinfo are
  709.      all available from many anonymous ftp archives, including
  710.      ftp.che.utexas.edu, ftp.uu.net, prep.ai.mit.edu, and
  711.      wuarchive.wustl.edu.
  712.      If you don't have a Fortran compiler, or if your Fortran compiler
  713.      doesn't work like the traditional Unix f77, you will need to have
  714.      the Fortran to C translator f2c.  You can get f2c from any number
  715.      of anonymous ftp archives.  The most recent version of f2c is
  716.      always available from research.att.com.
  717.      On an otherwise idle SPARCstation II, it will take somewhere
  718.      between 60 and 90 minutes to compile everything, depending on
  719.      whether you are compiling the Fortran libraries with f2c or using
  720.      the Fortran compiler directly.  You will need about 50 megabytes
  721.      of disk storage to work with (considerably less if you don't
  722.      compile with debugging symbols).  To do that, use the command
  723.           make CFLAGS=-O CXXFLAGS=-O LDFLAGS=
  724.      instead of just `make'.
  725.    * If you encounter errors while compiling Octave, first check the
  726.      list of known problems below to see if there is a workaround or
  727.      solution for your problem.  If not, see *Note Trouble::, for
  728.      information about how to report bugs.
  729.    * Once you have successfully compiled Octave, run `make install'.
  730.      This will install a copy of octave, its libraries, and its
  731.      documentation in the destination directory.  As distributed,
  732.      Octave is installed in the following directories:
  733.     `PREFIX/bin'
  734.           Octave and other binaries that people will want to run
  735.           directly.
  736.     `PREFIX/lib'
  737.           Libraries like libcruft.a and liboctave.a.
  738.     `PREFIX/include/octave'
  739.           Include files distributed with Octave.
  740.     `PREFIX/man/man1'
  741.           Unix-style man pages describing Octave.
  742.     `PREFIX/info'
  743.           Info files describing Octave.
  744.     `PREFIX/lib/octave/VERSION/m'
  745.           Function files distributed with Octave.  This includes the
  746.           Octave version, so that multiple versions of Octave may be
  747.           installed at the same time.
  748.     `PREFIX/lib/octave/VERSION/exec/HOST_TYPE'
  749.           Executables to be run by Octave rather than the user.
  750.     `PREFIX/lib/octave/VERSION/oct/HOST_TYPE'
  751.           Object files that will be dynamically loaded.
  752.     `PREFIX/lib/octave/VERSION/imagelib'
  753.           Image files that are distributed with Octave.
  754.      where PREFIX defaults to `/usr/local', VERSION stands for the
  755.      current version number of the interpreter, and HOST_TYPE is the
  756.      type of computer on which Octave is installed (for example,
  757.      `i486-unknown-gnu').
  758. * Menu:
  759. * Installation Problems::
  760. * Binary Distributions::
  761. File: octave.info,  Node: Installation Problems,  Next: Binary Distributions,  Prev: Installation,  Up: Installation
  762. Installation Problems
  763. =====================
  764.    This section contains a list of problems (and some apparent problems
  765. that don't really mean anything is wrong) that may show up during
  766. installation of Octave.
  767.    * On AIX (and possibly other) systems, GCC 2.6.2 generates invalid
  768.      assembly code when compiling some parts of Octave.  On AIX
  769.      systems, it is possible to get a working binary by not using the
  770.      compiler flag `-fno-implicit-templates'.  You can specify this as
  771.      an option to make by using a command like
  772.           make NO_IMPLICIT_TEMPLATES=
  773.    * You may need to edit some files in the gcc include subdirectory to
  774.      add prototypes for functions there.  For example, Ultrix 4.2 needs
  775.      proper declarations for the `signal()' and the `SIG_IGN' macro in
  776.      the file `signal.h'.
  777.      On some systems the `SIG_IGN' macro is defined to be something like
  778.      this:
  779.           #define  SIG_IGN  (void (*)())1
  780.      when it should really be something like:
  781.           #define  SIG_IGN  (void (*)(int))1
  782.      to match the prototype declaration for `signal()'.
  783.      The gcc fixincludes/fixproto script should probably fix this when
  784.      gcc installs its modified set of header files, but I don't think
  785.      that's been done yet.
  786.    * There is a bug with the makeinfo program that is distributed with
  787.      texinfo-3.1 that causes the indices in Octave's on-line manual to
  788.      be generated incorrectly.  If you need to recreate the on-line
  789.      documentation, you should get the makeinfo program that is
  790.      distributed with texinfo-3.1 and apply the patch for makeinfo that
  791.      is distributed with Octave.  See the file MAKEINFO.PATCH for more
  792.      details.
  793.    * If you don't have NPSOL but you still want to be able to solve
  794.      NLPs, or if you don't have QPSOL but you still want to solve QPs,
  795.      you'll need to find replacements or order them from Stanford.  If
  796.      you know of a freely redistributable replacement, please let us
  797.      know--we might be interested in distributing it with Octave.
  798.      You can get more information about NPSOL and QPSOL from
  799.           Stanford University
  800.           Office of Technology Licensing
  801.           857 Serra Street
  802.           Stanford CA 94305-6225
  803.           Tel: (415) 723-0651
  804.           Fax: (415) 725-7295
  805.      Octave may soon support FSQP, an NLP solver from Andre Tits
  806.      (andre@src.umd.edu) of the University of Maryland.  FSQP is
  807.      available free of charge to academic sites, but can not be
  808.      redistributed to third parties.
  809.    * Some of the Fortran subroutines may fail to compile with older
  810.      versions of the Sun Fortran compiler.  If you get errors like
  811.           zgemm.f:
  812.               zgemm:
  813.           warning: unexpected parent of complex expression subtree
  814.           zgemm.f, line 245: warning: unexpected parent of complex expression subtree
  815.           warning: unexpected parent of complex expression subtree
  816.           zgemm.f, line 304: warning: unexpected parent of complex expression subtree
  817.           warning: unexpected parent of complex expression subtree
  818.           zgemm.f, line 327: warning: unexpected parent of complex expression subtree
  819.           pcc_binval: missing IR_CONV in complex op
  820.           make[2]: *** [zgemm.o] Error 1
  821.      when compiling the Fortran subroutines in the `libcruft'
  822.      subdirectory, you should either upgrade your compiler or try
  823.      compiling with optimization turned off.
  824.    * On NeXT systems, if you get errors like this:
  825.           /usr/tmp/cc007458.s:unknown:Undefined local symbol LBB7656
  826.           /usr/tmp/cc007458.s:unknown:Undefined local symbol LBE7656
  827.      when compiling `Array.cc' and `Matrix.cc', try recompiling these
  828.      files without `-g'.
  829.    * Some people have reported that calls to shell_cmd and the pager do
  830.      not work on SunOS systems.  This is apparently due to having
  831.      `G_HAVE_SYS_WAIT' defined to be 0 instead of 1 when compiling
  832.      libg++.
  833.    * On NeXT systems, linking to `libsys_s.a' may fail to resolve the
  834.      following functions
  835.           _tcgetattr
  836.           _tcsetattr
  837.           _tcflow
  838.      which are part of `libposix.a'.  Unfortunately, linking Octave with
  839.      `-posix' results in the following undefined symbols.
  840.           .destructors_used
  841.           .constructors_used
  842.           _objc_msgSend
  843.           _NXGetDefaultValue
  844.           _NXRegisterDefaults
  845.           .objc_class_name_NXStringTable
  846.           .objc_class_name_NXBundle
  847.      One kludge around this problem is to extract `termios.o' from
  848.      `libposix.a', put it in Octave's `src' directory, and add it to
  849.      the list of files to link together in the Makefile.  Suggestions
  850.      for better ways to solve this problem are welcome!
  851.    * With g++ 2.6.3 (and possibly other 2.6.x versions) on some Intel
  852.      x86 systems, compiling `Array-d.cc' fails with the messages like
  853.           as: /tmp/cc005254.s:4057: Local symbol LBB103 never defined.
  854.           as: /tmp/cc005254.s:4057: Local symbol LBE103 never defined.
  855.      A possible workaround for this is to compile without `-g'.
  856.    * If Octave crashes immediately with a floating point exception, it
  857.      is likely that it is failing to initialize the IEEE floating point
  858.      values for infinity and NaN.
  859.      If your system actually does support IEEE arithmetic, you should
  860.      be able to fix this problem by modifying the function
  861.      `octave_ieee_init' in the file `sysdep.cc' to correctly initialize
  862.      Octave's internal infinity and NaN variables.
  863.      If your system does not support IEEE arithmetic but Octave's
  864.      configure script incorrectly determined that it does, you can work
  865.      around the problem by editing the file `config.h' to not define
  866.      `HAVE_ISINF', `HAVE_FINITE', and `HAVE_ISNAN'.
  867.      In any case, please report this as a bug since it might be
  868.      possible to modify Octave's configuration script to automatically
  869.      determine the proper thing to do.
  870. File: octave.info,  Node: Binary Distributions,  Prev: Installation Problems,  Up: Installation
  871. Binary Distributions
  872. ====================
  873.    This section contains instructions for creating and installing a
  874. binary distribution.
  875. * Menu:
  876. * Installing Octave from a Binary Distribution::
  877. * Creating a Binary Distribution::
  878. File: octave.info,  Node: Installing Octave from a Binary Distribution,  Next: Creating a Binary Distribution,  Prev: Binary Distributions,  Up: Binary Distributions
  879. Installing Octave from a Binary Distribution
  880. --------------------------------------------
  881.    * To install Octave from a binary distribution, execute the command
  882.           sh ./doinstall.sh
  883.      in the top level directory of the distribution.
  884.      Binary distributions are normally compiled assuming that Octave
  885.      will be installed in the following subdirectories of `/usr/local'.
  886.     `bin'
  887.           Octave and other binaries that people will want to run
  888.           directly.
  889.     `man/man1'
  890.           Unix-style man pages describing Octave.
  891.     `info'
  892.           Info files describing Octave.
  893.     `lib/octave/VERSION/m'
  894.           Function files distributed with Octave.  This includes the
  895.           Octave version, so that multiple versions of Octave may be
  896.           installed at the same time.
  897.     `lib/octave/VERSION/exec/HOST_TYPE'
  898.           Executables to be run by Octave rather than the user.
  899.     `lib/octave/VERSION/imagelib'
  900.           Image files that are distributed with Octave.
  901.      where VERSION stands for the current version number of the
  902.      interpreter, and HOST_TYPE is the type of computer on which Octave
  903.      is installed (for example, `i486-unknown-gnu').
  904.      If these directories don't exist, the script `doinstall.sh' will
  905.      create them for you.
  906.      If this is possible for you to install Octave in `/usr/local', or
  907.      if you would prefer to install it in a different directory, you can
  908.      specify the name of the top level directory as an argument to the
  909.      doinstall.sh script.  For example:
  910.           sh ./doinstall.sh /some/other/directory
  911.      Octave will then be installed in subdirectories of the directory
  912.      `/some/other/directory'
  913. File: octave.info,  Node: Creating a Binary Distribution,  Prev: Installing Octave from a Binary Distribution,  Up: Binary Distributions
  914. Creating a Binary Distribution
  915. ------------------------------
  916.    Here is how to build a binary distribution for others.
  917.    * Build Octave in the same directory as the source.  This is required
  918.      since the `binary-dist' targets in the Makefiles will not work if
  919.      you compile outside the source tree.
  920.    * Use `CFLAGS=-O CXXFLAGS=-O LDFLAGS=' as arguments for Make because
  921.      most people who get the binary distributions are probably not
  922.      going to be interested in debugging Octave.
  923.    * Type `make binary-dist'.  This will build everything and then pack
  924.      it up for distribution.
  925. File: octave.info,  Node: Trouble,  Next: Command Line Editing,  Prev: Installation,  Up: Top
  926. Known Causes of Trouble with Octave
  927. ***********************************
  928.    This section describes known problems that affect users of Octave.
  929. Most of these are not Octave bugs per se--if they were, we would fix
  930. them.  But the result for a user may be like the result of a bug.
  931.    Some of these problems are due to bugs in other software, some are
  932. missing features that are too much work to add, and some are places
  933. where people's opinions differ as to what is best.
  934. * Menu:
  935. * Actual Bugs::                 Bugs we will fix later.
  936. * Reporting Bugs::
  937. * Bug Criteria::
  938. * Bug Lists::
  939. * Bug Reporting::
  940. * Sending Patches::
  941. * Service::
  942. File: octave.info,  Node: Actual Bugs,  Next: Reporting Bugs,  Prev: Trouble,  Up: Trouble
  943. Actual Bugs We Haven't Fixed Yet
  944. ================================
  945.    * Output that comes directly from Fortran functions is not sent
  946.      through the pager and may appear out of sequence with other output
  947.      that is sent through the pager.  One way to avoid this is to force
  948.      pending output to be flushed before calling a function that will
  949.      produce output from within Fortran functions.  To do this, use the
  950.      command
  951.           fflush (stdout)
  952.      Another possible workaround is to use the command
  953.           page_screen_output = "false"
  954.      to turn the pager off.
  955.    * Control-C doesn't work properly in the pager on DEC Alpha systems
  956.      running OSF/1 3.0.
  957.      This appears to be a bug in the OSF/1 3.0 Bourne shell.  The
  958.      problem doesn't appear on systems running OSF/1 1.3.
  959.    * If you get messages like
  960.           Input line too long
  961.      when trying to plot many lines on one graph, you have probably
  962.      generated a plot command that is too larger for `gnuplot''s
  963.      fixed-length buffer for commands.  Splitting up the plot command
  964.      doesn't help because replot is implemented in gnuplot by simply
  965.      appending the new plotting commands to the old command line and
  966.      then evaluating it again.
  967.      You can demonstrate this `feature' by running gnuplot and doing
  968.      something like
  969.             plot sin (x), sin (x), sin (x), ... lots more ..., sin (x)
  970.      and then
  971.             replot sin (x), sin (x), sin (x), ... lots more ..., sin (x)
  972.      after repeating the replot command a few times, gnuplot will give
  973.      you an error.
  974.      Also, it doesn't help to use backslashes to enter a plot command
  975.      over several lines, because the limit is on the overall command
  976.      line length, once the backslashed lines are all pasted together.
  977.      Because of this, Octave tries to use as little of the command-line
  978.      length as possible by using the shortest possible abbreviations for
  979.      all the plot commands and options.  Unfortunately, the length of
  980.      the temporary file names is probably what is taking up the most
  981.      space on the command line.
  982.      You can buy a little bit of command line space by setting the
  983.      environment variable `TMPDIR' to be "." before starting Octave, or
  984.      you can increase the maximum command line length in gnuplot by
  985.      changing the following limits in the file plot.h in the gnuplot
  986.      distribution and recompiling gnuplot.
  987.           #define MAX_LINE_LEN 32768  /* originally 1024 */
  988.           #define MAX_TOKENS 8192     /* originally 400 */
  989.      Of course, this doesn't really fix the problem, but it does make it
  990.      much less likely that you will run into trouble unless you are
  991.      putting a very large number of lines on a given plot.
  992.    * String handling could use some work.
  993.    A list of ideas for future enhancements is distributed with Octave.
  994. See the file `PROJECTS' in the top level directory in the source
  995. distribution.
  996. File: octave.info,  Node: Reporting Bugs,  Next: Bug Criteria,  Prev: Actual Bugs,  Up: Trouble
  997. Reporting Bugs
  998. ==============
  999.    Your bug reports play an essential role in making Octave reliable.
  1000.    When you encounter a problem, the first thing to do is to see if it
  1001. is already known.  *Note Trouble::.  If it isn't known, then you should
  1002. report the problem.
  1003.    Reporting a bug may help you by bringing a solution to your problem,
  1004. or it may not.  In any case, the principal function of a bug report is
  1005. to help the entire community by making the next version of Octave work
  1006. better.  Bug reports are your contribution to the maintenance of Octave.
  1007.    In order for a bug report to serve its purpose, you must include the
  1008. information that makes it possible to fix the bug.
  1009.    If you have Octave working at all, the easiest way to prepare a
  1010. complete bug report is to use the Octave function `bug_report'.  When
  1011. you execute this function, Octave will prompt you for a subject and then
  1012. invoke the editor on a file that already contains all the configuration
  1013. information.  When you exit the editor, Octave will mail the bug report
  1014. for you.
  1015. * Menu:
  1016. * Bug Criteria::
  1017. * Where: Bug Lists.             Where to send your bug report.
  1018. * Reporting: Bug Reporting.     How to report a bug effectively.
  1019. * Patches: Sending Patches.     How to send a patch for Octave.
  1020.