home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / doc / octave.INF (.txt) < prev    next >
Encoding:
OS/2 Help File  |  1999-05-13  |  448.2 KB  |  15,878 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. Title page ΓòÉΓòÉΓòÉ
  3.  
  4.                                    GNU Octave
  5.  
  6.           A high-level interactive language for numerical computations
  7.  
  8.                        Edition 3 for Octave version 2.1.14
  9.  
  10.                                   February 1997
  11.  
  12.                                   John W. Eaton
  13.  
  14. Copyright (C) 1996, 1997 John W. Eaton. 
  15.  
  16. This is the third edition of the Octave documentation, and is consistent with 
  17. version 2.1.14 of Octave. 
  18.  
  19. Permission is granted to make and distribute verbatim copies of this manual 
  20. provided the copyright notice and this permission notice are preserved on all 
  21. copies. 
  22.  
  23. Permission is granted to copy and distribute modified versions of this manual 
  24. under the conditions for verbatim copying, provided that the entire resulting 
  25. derived work is distributed under the terms of a permission notice identical to 
  26. this one. 
  27.  
  28. Permission is granted to copy and distribute translations of this manual into 
  29. another language, under the same conditions as for modified versions. 
  30.  
  31. Portions of this document have been adapted from the gawk, readline, gcc, and C 
  32. library manuals, published by the Free Software Foundation, 59 Temple 
  33. Place---Suite 330, Boston, MA 02111--1307, USA. 
  34.  
  35.  
  36. ΓòÉΓòÉΓòÉ 2. Top ΓòÉΓòÉΓòÉ
  37.  
  38. This manual documents how to run, install and port GNU Octave, as well as its 
  39. new features and incompatibilities, and how to report bugs. It corresponds to 
  40. GNU Octave version 2.1.14. 
  41.  
  42.  Preface 
  43.  Introduction                            A brief introduction to Octave. 
  44.  Getting Started 
  45.  Data Types 
  46.  Numeric Data Types 
  47.  Strings 
  48.  Data Structures 
  49.  Variables 
  50.  Expressions                             Expressions. 
  51.  Evaluation 
  52.  Statements                              Looping and program flow control. 
  53.  Functions and Scripts 
  54.  Error Handling 
  55.  Input and Output 
  56.  Plotting 
  57.  Matrix Manipulation 
  58.  Arithmetic 
  59.  Linear Algebra 
  60.  Nonlinear Equations 
  61.  Quadrature 
  62.  Differential Equations 
  63.  Optimization 
  64.  Statistics 
  65.  Sets 
  66.  Polynomial Manipulations 
  67.  Control Theory 
  68.  Signal Processing 
  69.  Image Processing 
  70.  Audio Processing 
  71.  System Utilities 
  72.  Tips 
  73.  Trouble                                 If you have trouble installing Octave. 
  74.  Installation                            How to configure, compile and install 
  75.                                          Octave. 
  76.  Emacs 
  77.  Grammar 
  78.  Copying                                 The GNU General Public License. 
  79.  Concept Index                           An item for each concept. 
  80.  Variable Index                          An item for each documented variable. 
  81.  Function Index                          An item for each documented function. 
  82.  Operator Index                          An item for each documented operator. 
  83.  
  84.   --- The Detailed Node Listing --- 
  85.  
  86.  Preface 
  87.  
  88.  Acknowledgements 
  89.  How You Can Contribute to Octave 
  90.  Distribution 
  91.  
  92.  A Brief Introduction to Octave 
  93.  
  94.  Running Octave 
  95.  Simple Examples 
  96.  Conventions 
  97.  
  98.  Conventions 
  99.  
  100.  Fonts 
  101.  Evaluation Notation 
  102.  Printing Notation 
  103.  Error Messages 
  104.  Format of Descriptions 
  105.  
  106.  Format of Descriptions 
  107.  
  108.  A Sample Function Description 
  109.  A Sample Command Description 
  110.  A Sample Variable Description 
  111.  
  112.  Getting Started 
  113.  
  114.  Invoking Octave 
  115.  Quitting Octave 
  116.  Getting Help 
  117.  Command Line Editing 
  118.  Errors 
  119.  Executable Octave Programs 
  120.  Comments 
  121.  
  122.  Invoking Octave 
  123.  
  124.  Command Line Options 
  125.  Startup Files 
  126.  
  127.  Command Line Editing 
  128.  
  129.  Cursor Motion 
  130.  Killing and Yanking 
  131.  Commands For Text 
  132.  Commands For Completion 
  133.  Commands For History 
  134.  Customizing the Prompt 
  135.  Diary and Echo Commands 
  136.  
  137.  Data Types 
  138.  
  139.  Built-in Data Types 
  140.  User-defined Data Types 
  141.  Object Sizes 
  142.  
  143.  Built-in Data Types 
  144.  
  145.  Numeric Objects 
  146.  String Objects 
  147.  Data Structure Objects 
  148.  
  149.  Numeric Data Types 
  150.  
  151.  Matrices 
  152.  Ranges 
  153.  Predicates for Numeric Objects 
  154.  
  155.  Matrices 
  156.  
  157.  Empty Matrices 
  158.  
  159.  Strings 
  160.  
  161.  Creating Strings 
  162.  Searching and Replacing 
  163.  String Conversions 
  164.  Character Class Functions 
  165.  
  166.  Variables 
  167.  
  168.  Global Variables 
  169.  Status of Variables 
  170.  Summary of Built-in Variables 
  171.  Defaults from the Environment 
  172.  
  173.  Expressions 
  174.  
  175.  Index Expressions 
  176.  Calling Functions 
  177.  Arithmetic Ops 
  178.  Comparison Ops 
  179.  Boolean Expressions 
  180.  Assignment Ops 
  181.  Increment Ops 
  182.  Operator Precedence 
  183.  
  184.  Calling Functions 
  185.  
  186.  Call by Value 
  187.  Recursion 
  188.  
  189.  Boolean Expressions 
  190.  
  191.  Element-by-element Boolean Operators 
  192.  Short-circuit Boolean Operators 
  193.  
  194.  Statements 
  195.  
  196.  The if Statement 
  197.  The switch Statement 
  198.  The while Statement 
  199.  The for Statement 
  200.  The break Statement 
  201.  The continue Statement 
  202.  The unwind_protect Statement 
  203.  The try Statement 
  204.  Continuation Lines 
  205.  
  206.  The for Statement 
  207.  
  208.  Looping Over Structure Elements 
  209.  
  210.  Functions and Script Files 
  211.  
  212.  Defining Functions 
  213.  Multiple Return Values 
  214.  Variable-length Argument Lists 
  215.  Variable-length Return Lists 
  216.  Returning From a Function 
  217.  Function Files 
  218.  Script Files 
  219.  Dynamically Linked Functions 
  220.  Organization of Functions 
  221.  
  222.  Input and Output 
  223.  
  224.  Basic Input and Output 
  225.  C-Style I/O Functions 
  226.  
  227.  Basic Input and Output 
  228.  
  229.  Terminal Output 
  230.  Terminal Input 
  231.  Simple File I/O 
  232.  
  233.  C-Style I/O Functions 
  234.  
  235.  Opening and Closing Files 
  236.  Simple Output 
  237.  Line-Oriented Input 
  238.  Formatted Output 
  239.  Output Conversion for Matrices 
  240.  Output Conversion Syntax 
  241.  Table of Output Conversions 
  242.  Integer Conversions 
  243.  Floating-Point Conversions              Other Output Conversions:: 
  244.  Other Output Conversions 
  245.  Formatted Input 
  246.  Input Conversion Syntax 
  247.  Table of Input Conversions 
  248.  Numeric Input Conversions 
  249.  String Input Conversions 
  250.  Binary I/O 
  251.  Temporary Files 
  252.  EOF and Errors 
  253.  File Positioning 
  254.  
  255.  Plotting 
  256.  
  257.  Two-Dimensional Plotting 
  258.  Specialized Two-Dimensional Plots 
  259.  Three-Dimensional Plotting 
  260.  Plot Annotations 
  261.  Multiple Plots on One Page 
  262.  
  263.  Matrix Manipulation 
  264.  
  265.  Finding Elements and Checking Conditions 
  266.  Rearranging Matrices 
  267.  Special Utility Matrices 
  268.  Famous Matrices 
  269.  
  270.  Arithmetic 
  271.  
  272.  Utility Functions 
  273.  Complex Arithmetic 
  274.  Trigonometry 
  275.  Sums and Products 
  276.  Special Functions 
  277.  Mathematical Constants 
  278.  
  279.  Linear Algebra 
  280.  
  281.  Basic Matrix Functions 
  282.  Matrix Factorizations 
  283.  Functions of a Matrix 
  284.  
  285.  Quadrature 
  286.  
  287.  Functions of One Variable 
  288.  Orthogonal Collocation 
  289.  
  290.  Differential Equations 
  291.  
  292.  Ordinary Differential Equations 
  293.  Differential-Algebraic Equations 
  294.  
  295.  Optimization 
  296.  
  297.  Quadratic Programming 
  298.  Nonlinear Programming 
  299.  Linear Least Squares 
  300.  
  301.  System Utilities 
  302.  
  303.  Timing Utilities 
  304.  Filesystem Utilities 
  305.  Controlling Subprocesses 
  306.  Process ID Information 
  307.  Environment Variables 
  308.  Current Working Directory 
  309.  Password Database Functions 
  310.  Group Database Functions 
  311.  System Information 
  312.  
  313.  Tips and Standards 
  314.  
  315.  Style Tips                              Writing clean and robust programs. 
  316.  Coding Tips                             Making code run faster. 
  317.  Documentation Tips                      Writing readable documentation 
  318.                                          strings. 
  319.  Comment Tips                            Conventions for writing comments. 
  320.  Function Headers                        Standard headers for functions. 
  321.  
  322.  Known Causes of Trouble with Octave 
  323.  
  324.  Actual Bugs                             Bugs we will fix later. 
  325.  Reporting Bugs 
  326.  Bug Criteria 
  327.  Bug Lists 
  328.  Bug Reporting 
  329.  Sending Patches 
  330.  Service 
  331.  
  332.  Reporting Bugs 
  333.  
  334.  Bug Criteria 
  335.  * Where: Bug Lists.       Where to send your bug report. * Reporting: Bug 
  336.  Reporting.   How to report a bug effectively. * Patches: Sending Patches. 
  337.  How to send a patch for Octave. 
  338.  
  339.  Installing Octave 
  340.  
  341.  Installation Problems 
  342.  Binary Distributions 
  343.  
  344.  Binary Distributions 
  345.  
  346.  Installing Octave from a Binary Distribution 
  347.  Creating a Binary Distribution 
  348.  
  349.  Emacs Octave Support 
  350.  
  351.  Installing EOS 
  352.  Using Octave Mode 
  353.  Running Octave From Within Emacs 
  354.  Using the Emacs Info Reader for Octave 
  355.  
  356.  Grammar 
  357.  
  358.  Keywords 
  359.  
  360.  
  361. ΓòÉΓòÉΓòÉ 3. Preface ΓòÉΓòÉΓòÉ
  362.  
  363. Octave was originally intended to be companion software for an 
  364. undergraduate-level textbook on chemical reactor design being written by James 
  365. B. Rawlings of the University of Wisconsin-Madison and John G. Ekerdt of the 
  366. University of Texas. 
  367.  
  368. Clearly, Octave is now much more than just another `courseware' package with 
  369. limited utility beyond the classroom.  Although our initial goals were somewhat 
  370. vague, we knew that we wanted to create something that would enable students to 
  371. solve realistic problems, and that they could use for many things other than 
  372. chemical reactor design problems. 
  373.  
  374. There are those who would say that we should be teaching the students Fortran 
  375. instead, because that is the computer language of engineering, but every time 
  376. we have tried that, the students have spent far too much time trying to figure 
  377. out why their Fortran code crashes and not enough time learning about chemical 
  378. engineering.  With Octave, most students pick up the basics quickly, and are 
  379. using it confidently in just a few hours. 
  380.  
  381. Although it was originally intended to be used to teach reactor design, it has 
  382. been used in several other undergraduate and graduate courses in the Chemical 
  383. Engineering Department at the University of Texas, and the math department at 
  384. the University of Texas has been using it for teaching differential equations 
  385. and linear algebra as well.  If you find it useful, please let us know.  We are 
  386. always interested to find out how Octave is being used in other places. 
  387.  
  388. Virtually everyone thinks that the name Octave has something to do with music, 
  389. but it is actually the name of a former professor of mine who wrote a famous 
  390. textbook on chemical reaction engineering, and who was also well known for his 
  391. ability to do quick `back of the envelope' calculations.  We hope that this 
  392. software will make it possible for many people to do more ambitious 
  393. computations just as easily. 
  394.  
  395. Everyone is encouraged to share this software with others under the terms of 
  396. the GNU General Public License (see Copying) as described at the beginning of 
  397. this manual.  You are also encouraged to help make Octave more useful by 
  398. writing and contributing additional functions for it, and by reporting any 
  399. problems you may have. 
  400.  
  401.  Acknowledgements 
  402.  How You Can Contribute to Octave 
  403.  Distribution 
  404.  
  405.  
  406. ΓòÉΓòÉΓòÉ 3.1. Acknowledgements ΓòÉΓòÉΓòÉ
  407.  
  408. Many people have already contributed to Octave's development.  In addition to 
  409. John W. Eaton, the following people have helped write parts of Octave or helped 
  410. out in various other ways. 
  411.  
  412.      Thomas Baier baier@ci.tuwien.ac.at wrote the original versions of popen, 
  413.       pclose, execute, sync_system, and async_system. 
  414.  
  415.      Karl Berry karl@cs.umb.edu wrote the kpathsea library that allows Octave 
  416.       to recursively search directory paths for function and script files. 
  417.  
  418.      Georg Beyerle gbeyerle@awi-potsdam.de contributed code to save values in 
  419.       Matlab's `.mat'-file format, and has provided many useful bug reports and 
  420.       suggestions. 
  421.  
  422.      John Campbell jcc@bevo.che.wisc.edu wrote most of the file and C-style 
  423.       input and output functions. 
  424.  
  425.      Brian Fox bfox@gnu.ai.mit.edu wrote the readline library used for command 
  426.       history editing, and the portion of this manual that documents it. 
  427.  
  428.      Klaus Gebhardt gebhardt@crunch.ikp.physik.th-darmstadt.de ported Octave 
  429.       to OS/2. 
  430.  
  431.      A. Scottedward Hodel A.S.Hodel@eng.auburn.edu contributed a number of 
  432.       functions including expm, qzval, qzhess, syl, lyap, and balance. 
  433.  
  434.      Kurt Hornik Kurt.Hornik@ci.tuwien.ac.at provided the corrcoef, cov, 
  435.       fftconv, fftfilt, gcd, lcd, kurtosis, null, orth, poly, polyfit, roots, 
  436.       and skewness functions, supplied documentation for these and numerous 
  437.       other functions, rewrote the Emacs mode for editing Octave code and 
  438.       provided its documentation, and has helped tremendously with testing.  He 
  439.       has also been a constant source of new ideas for improving Octave. 
  440.  
  441.      Phil Johnson johnsonp@nicco.sscnet.ucla.edu has helped to make Linux 
  442.       releases available. 
  443.  
  444.      Friedrich Leisch leisch@ci.tuwien.ac.at provided the mahalanobis 
  445.       function. 
  446.  
  447.      Ken Neighbors wkn@leland.stanford.edu has provided many useful bug 
  448.       reports and comments on Matlab compatibility. 
  449.  
  450.      Rick Niles niles@axp745.gsfc.nasa.gov rewrote Octave's plotting functions 
  451.       to add line styles and the ability to specify an unlimited number of 
  452.       lines in a single call.  He also continues to track down odd 
  453.       incompatibilities and bugs. 
  454.  
  455.      Mark Odegard meo@sugarland.unocal.com provided the initial implementation 
  456.       of fread, fwrite, feof, and ferror. 
  457.  
  458.      Tony Richardson arichard@stark.cc.oh.us wrote Octave's image processing 
  459.       functions as well as most of the original polynomial functions. 
  460.  
  461.      R. Bruce Tenison Bruce.Tenison@eng.auburn.edu wrote the hess and schur 
  462.       functions. 
  463.  
  464.      Teresa Twaroch twaroch@ci.tuwien.ac.at provided the functions gls and 
  465.       ols. 
  466.  
  467.      Andreas Weingessel Andreas.Weingessel@ci.tuwien.ac.at wrote the audio 
  468.       functions lin2mu, loadaudio, mu2lin, playaudio, record, saveaudio, and 
  469.       setaudio. 
  470.  
  471.      Fook Fah Yap ffy@eng.cam.ac.uk provided the fft and ifft functions and 
  472.       valuable bug reports for early versions. 
  473.  
  474.  Special thanks to the following people and organizations for supporting the 
  475.  development of Octave: 
  476.  
  477.      Digital Equipment Corporation, for an equipment grant as part of their 
  478.       External Research Program. 
  479.  
  480.      Sun Microsystems, Inc., for an Academic Equipment grant. 
  481.  
  482.      International Business Machines, Inc., for providing equipment as part of 
  483.       a grant to the University of Texas College of Engineering. 
  484.  
  485.      Texaco Chemical Company, for providing funding to continue the 
  486.       development of this software. 
  487.  
  488.      The University of Texas College of Engineering, for providing a Challenge 
  489.       for Excellence Research Supplement, and for providing an Academic 
  490.       Development Funds grant. 
  491.  
  492.      The State of Texas, for providing funding through the Texas Advanced 
  493.       Technology Program under Grant No. 003658-078. 
  494.  
  495.      Noel Bell, Senior Engineer, Texaco Chemical Company, Austin Texas. 
  496.  
  497.      James B. Rawlings, Professor, University of Wisconsin-Madison, Department 
  498.       of Chemical Engineering. 
  499.  
  500.      Richard Stallman, for writing GNU. 
  501.  
  502.  This project would not have been possible without the GNU software used in and 
  503.  used to produce Octave. 
  504.  
  505.  
  506. ΓòÉΓòÉΓòÉ 3.2. How You Can Contribute to Octave ΓòÉΓòÉΓòÉ
  507.  
  508. There are a number of ways that you can contribute to help make Octave a better 
  509. system.  Perhaps the most important way to contribute is to write high-quality 
  510. code for solving new problems, and to make your code freely available for 
  511. others to use. 
  512.  
  513. If you find Octave useful, consider providing additional funding to continue 
  514. its development.  Even a modest amount of additional funding could make a 
  515. significant difference in the amount of time that is available for development 
  516. and support. 
  517.  
  518. If you cannot provide funding or contribute code, you can still help make 
  519. Octave better and more reliable by reporting any bugs you find and by offering 
  520. suggestions for ways to improve Octave.  See Trouble, for tips on how to write 
  521. useful bug reports. 
  522.  
  523.  
  524. ΓòÉΓòÉΓòÉ 3.3. Distribution ΓòÉΓòÉΓòÉ
  525.  
  526. Octave is free software.  This means that everyone is free to use it and free 
  527. to redistribute it on certain conditions.  Octave is not in the public domain. 
  528. It is copyrighted and there are restrictions on its distribution, but the 
  529. restrictions are designed to ensure that others will have the same freedom to 
  530. use and redistribute Octave that you have.  The precise conditions can be found 
  531. in the GNU General Public License that comes with Octave and that also appears 
  532. in Copying. 
  533.  
  534. Octave is available on CD-ROM with various collections of other free software, 
  535. and from the Free Software Foundation.  Ordering a copy of Octave from the Free 
  536. Software Foundation helps to fund the development of more free software.  For 
  537. more information, write to 
  538.  
  539. Free Software Foundation 
  540. 59 Temple Place---Suite 330 
  541. Boston, MA 02111--1307 
  542. USA 
  543.  
  544. Octave is also available on the Internet from 
  545. ftp://ftp.che.wisc.edu/pub/octave, and additional information is available from 
  546. http://www.che.wisc.edu/octave. 
  547.  
  548.  
  549. ΓòÉΓòÉΓòÉ 4. A Brief Introduction to Octave ΓòÉΓòÉΓòÉ
  550.  
  551. This manual documents how to run, install and port GNU Octave, and how to 
  552. report bugs. 
  553.  
  554. GNU Octave is a high-level language, primarily intended for numerical 
  555. computations.  It provides a convenient command line interface for solving 
  556. linear and nonlinear problems numerically, and for performing other numerical 
  557. experiments.  It may also be used as a batch-oriented language. 
  558.  
  559. GNU Octave is also freely redistributable software.  You may redistribute it 
  560. and/or modify it under the terms of the GNU General Public License as published 
  561. by the Free Software Foundation.  The GPL is included in this manual in 
  562. Copying. 
  563.  
  564. This document corresponds to Octave version 2.1.14. 
  565.  
  566.  Running Octave 
  567.  Simple Examples 
  568.  Conventions 
  569.  
  570.  
  571. ΓòÉΓòÉΓòÉ 4.1. Running Octave ΓòÉΓòÉΓòÉ
  572.  
  573. On most systems, the way to invoke Octave is with the shell command `octave'. 
  574. Octave displays an initial message and then a prompt indicating it is ready to 
  575. accept input.  You can begin typing Octave commands immediately afterward. 
  576.  
  577. If you get into trouble, you can usually interrupt Octave by typing Control-C 
  578. (usually written C-c for short).  C-c gets its name from the fact that you type 
  579. it by holding down CTRL and then pressing c.  Doing this will normally return 
  580. you to Octave's prompt. 
  581.  
  582. To exit Octave, type quit, or exit at the Octave prompt. 
  583.  
  584. On systems that support job control, you can suspend Octave by sending it a 
  585. SIGTSTP signal, usually by typing C-z. 
  586.  
  587.  
  588. ΓòÉΓòÉΓòÉ 4.2. Simple Examples ΓòÉΓòÉΓòÉ
  589.  
  590. The following chapters describe all of Octave's features in detail, but before 
  591. doing that, it might be helpful to give a sampling of some of its capabilities. 
  592.  
  593. If you are new to Octave, I recommend that you try these examples to begin 
  594. learning Octave by using it.  Lines marked with `octave:13>' are lines you 
  595. type, ending each with a carriage return.  Octave will respond with an answer, 
  596. or by displaying a graph. 
  597.  
  598.  
  599. ΓòÉΓòÉΓòÉ 4.2.1. Creating a Matrix ΓòÉΓòÉΓòÉ
  600.  
  601. To create a new matrix and store it in a variable so that it you can refer to 
  602. it later, type the command 
  603.  
  604. octave:1> a = [ 1, 1, 2; 3, 5, 8; 13, 21, 34 ]
  605.  
  606. Octave will respond by printing the matrix in neatly aligned columns. Ending a 
  607. command with a semicolon tells Octave to not print the result of a command. 
  608. For example 
  609.  
  610. octave:2> b = rand (3, 2);
  611.  
  612. will create a 3 row, 2 column matrix with each element set to a random value 
  613. between zero and one. 
  614.  
  615. To display the value of any variable, simply type the name of the variable. 
  616. For example, to display the value stored in the matrix b, type the command 
  617.  
  618. octave:3> b
  619.  
  620.  
  621. ΓòÉΓòÉΓòÉ 4.2.2. Matrix Arithmetic ΓòÉΓòÉΓòÉ
  622.  
  623. Octave has a convenient operator notation for performing matrix arithmetic. 
  624. For example, to multiply the matrix a by a scalar value, type the command 
  625.  
  626. octave:4> 2 * a
  627.  
  628. To multiply the two matrices a and b, type the command 
  629.  
  630. octave:5> a * b
  631.  
  632. To form the matrix product transpose (a) * a, type the command 
  633.  
  634. octave:6> a' * a
  635.  
  636.  
  637. ΓòÉΓòÉΓòÉ 4.2.3. Solving Linear Equations ΓòÉΓòÉΓòÉ
  638.  
  639. To solve the set of linear equations ax = b, use the left division operator, 
  640. `\': 
  641.  
  642. octave:7> a \ b
  643.  
  644. This is conceptually equivalent to inv (a) * b, but avoids computing the 
  645. inverse of a matrix directly. 
  646.  
  647. If the coefficient matrix is singular, Octave will print a warning message and 
  648. compute a minimum norm solution. 
  649.  
  650.  
  651. ΓòÉΓòÉΓòÉ 4.2.4. Integrating Differential Equations ΓòÉΓòÉΓòÉ
  652.  
  653. Octave has built-in functions for solving nonlinear differential equations of 
  654. the form 
  655.  
  656. dx
  657. -- = f (x, t)
  658. dt
  659.  
  660. with the initial condition 
  661.  
  662. x(t = t0) = x0
  663.  
  664. For Octave to integrate equations of this form, you must first provide a 
  665. definition of the function f(x,t). This is straightforward, and may be 
  666. accomplished by entering the function body directly on the command line.  For 
  667. example, the following commands define the right hand side function for an 
  668. interesting pair of nonlinear differential equations.  Note that while you are 
  669. entering a function, Octave responds with a different prompt, to indicate that 
  670. it is waiting for you to complete your input. 
  671.  
  672. octave:8> function xdot = f (x, t)
  673. >
  674. >  r = 0.25;
  675. >  k = 1.4;
  676. >  a = 1.5;
  677. >  b = 0.16;
  678. >  c = 0.9;
  679. >  d = 0.8;
  680. >
  681. >  xdot(1) = r*x(1)*(1 - x(1)/k) - a*x(1)*x(2)/(1 + b*x(1));
  682. >  xdot(2) = c*a*x(1)*x(2)/(1 + b*x(1)) - d*x(2);
  683. >
  684. > endfunction
  685.  
  686. Given the initial condition 
  687.  
  688. x0 = [1; 2];
  689.  
  690. and the set of output times as a column vector (note that the first output time 
  691. corresponds to the initial condition given above) 
  692.  
  693. t = linspace (0, 50, 200)';
  694.  
  695. it is easy to integrate the set of differential equations: 
  696.  
  697. x = lsode ("f", x0, t);
  698.  
  699. The function lsode uses the Livermore Solver for Ordinary Differential 
  700. Equations, described in A. C. Hindmarsh, ODEPACK, a Systematized Collection of 
  701. ODE Solvers, in: Scientific Computing, R. S. Stepleman et al. (Eds.), 
  702. North-Holland, Amsterdam, 1983, pages 55--64. 
  703.  
  704.  
  705. ΓòÉΓòÉΓòÉ 4.2.5. Producing Graphical Output ΓòÉΓòÉΓòÉ
  706.  
  707. To display the solution of the previous example graphically, use the command 
  708.  
  709. plot (t, x)
  710.  
  711. If you are using the X Window System, Octave will automatically create a 
  712. separate window to display the plot.  If you are using a terminal that supports 
  713. some other graphics commands, you will need to tell Octave what kind of 
  714. terminal you have.  Type the command 
  715.  
  716. gset term
  717.  
  718. to see a list of the supported terminal types.  Octave uses gnuplot to display 
  719. graphics, and can display graphics on any terminal that is supported by 
  720. gnuplot. 
  721.  
  722. To capture the output of the plot command in a file rather than sending the 
  723. output directly to your terminal, you can use a set of commands like this 
  724.  
  725. gset term postscript
  726. gset output "foo.ps"
  727. replot
  728.  
  729. This will work for other types of output devices as well.  Octave's gset 
  730. command is really just piped to the gnuplot subprocess, so that once you have a 
  731. plot on the screen that you like, you should be able to do something like this 
  732. to create an output file suitable for your graphics printer. 
  733.  
  734. Or, you can eliminate the intermediate file by using commands like this 
  735.  
  736. gset term postscript
  737. gset output "|lpr -Pname_of_your_graphics_printer"
  738. replot
  739.  
  740.  
  741. ΓòÉΓòÉΓòÉ 4.2.6. Editing What You Have Typed ΓòÉΓòÉΓòÉ
  742.  
  743. At the Octave prompt, you can recall, edit, and reissue previous commands using 
  744. Emacs- or vi-style editing commands.  The default keybindings use Emacs-style 
  745. commands.  For example, to recall the previous command, type Control-p (usually 
  746. written C-p for short).  C-p gets its name from the fact that you type it by 
  747. holding down CTRL and then pressing p.  Doing this will normally bring back the 
  748. previous line of input.  C-n will bring up the next line of input, C-b will 
  749. move the cursor backward on the line, C-f will move the cursor forward on the 
  750. line, etc. 
  751.  
  752. A complete description of the command line editing capability is given in this 
  753. manual in Command Line Editing. 
  754.  
  755.  
  756. ΓòÉΓòÉΓòÉ 4.2.7. Getting Help ΓòÉΓòÉΓòÉ
  757.  
  758. Octave has an extensive help facility.  The same documentation that is 
  759. available in printed form is also available from the Octave prompt, because 
  760. both forms of the documentation are created from the same input file. 
  761.  
  762. In order to get good help you first need to know the name of the command that 
  763. you want to use.  This name of the function may not always be obvious, but a 
  764. good place to start is to just type help. This will show you all the operators, 
  765. reserved words, functions, built-in variables, and function files.  You can 
  766. then get more help on anything that is listed by simply including the name as 
  767. an argument to help.  For example, 
  768.  
  769. help plot
  770.  
  771. will display the help text for the plot function. 
  772.  
  773. Octave sends output that is too long to fit on one screen through a pager like 
  774. less or more.  Type a RET to advance one line, a SPC to advance one page, and q 
  775. to exit the pager. 
  776.  
  777. The part of Octave's help facility that allows you to read the complete text of 
  778. the printed manual from within Octave normally uses a separate program called 
  779. Info.  When you invoke Info you will be put into a menu driven program that 
  780. contains the entire Octave manual.  Help for using Info is provided in this 
  781. manual in Getting Help. 
  782.  
  783.  
  784. ΓòÉΓòÉΓòÉ 4.3. Conventions ΓòÉΓòÉΓòÉ
  785.  
  786. This section explains the notational conventions that are used in this manual. 
  787. You may want to skip this section and refer back to it later. 
  788.  
  789.  Fonts 
  790.  Evaluation Notation 
  791.  Printing Notation 
  792.  Error Messages 
  793.  Format of Descriptions 
  794.  
  795.  
  796. ΓòÉΓòÉΓòÉ 4.3.1. Fonts ΓòÉΓòÉΓòÉ
  797.  
  798. Examples of Octave code appear in this font or form: svd (a). Names that 
  799. represent arguments or metasyntactic variables appear in this font or form: 
  800. first-number.  Commands that you type at the shell prompt sometimes appear in 
  801. this font or form: `octave --no-init-file'.  Commands that you type at the 
  802. Octave prompt sometimes appear in this font or form: foo --bar --baz. Specific 
  803. keys on your keyboard appear in this font or form: ANY. 
  804.  
  805.  
  806. ΓòÉΓòÉΓòÉ 4.3.2. Evaluation Notation ΓòÉΓòÉΓòÉ
  807.  
  808. In the examples in this manual, results from expressions that you evaluate are 
  809. indicated with `=>'.  For example, 
  810.  
  811. sqrt (2)
  812.      => 1.4142
  813.  
  814. You can read this as ``sqrt (2) evaluates to 1.4142''. 
  815.  
  816. In some cases, matrix values that are returned by expressions are displayed 
  817. like this 
  818.  
  819. [1, 2; 3, 4] == [1, 3; 2, 4]
  820.      => [ 1, 0; 0, 1 ]
  821.  
  822. and in other cases, they are displayed like this 
  823.  
  824. eye (3)
  825.      =>  1  0  0
  826.          0  1  0
  827.          0  0  1
  828.  
  829. in order to clearly show the structure of the result. 
  830.  
  831. Sometimes to help describe one expression, another expression is shown that 
  832. produces identical results.  The exact equivalence of expressions is indicated 
  833. with `=='.  For example, 
  834.  
  835. rot90 ([1, 2; 3, 4], -1)
  836. ==
  837. rot90 ([1, 2; 3, 4], 3)
  838. ==
  839. rot90 ([1, 2; 3, 4], 7)
  840.  
  841.  
  842. ΓòÉΓòÉΓòÉ 4.3.3. Printing Notation ΓòÉΓòÉΓòÉ
  843.  
  844. Many of the examples in this manual print text when they are evaluated. 
  845. Examples in this manual indicate printed text with `-|'.  The value that is 
  846. returned by evaluating the expression (here 1) is displayed with `=>' and 
  847. follows on a separate line. 
  848.  
  849. printf ("foo %s\n", "bar")
  850.      -| foo bar
  851.      => 1
  852.  
  853.  
  854. ΓòÉΓòÉΓòÉ 4.3.4. Error Messages ΓòÉΓòÉΓòÉ
  855.  
  856. Some examples signal errors.  This normally displays an error message on your 
  857. terminal.  Error messages are shown on a line starting with error:. 
  858.  
  859. struct_elements ([1, 2; 3, 4])
  860. error: struct_elements: wrong type argument `matrix'
  861.  
  862.  
  863. ΓòÉΓòÉΓòÉ 4.3.5. Format of Descriptions ΓòÉΓòÉΓòÉ
  864.  
  865. Functions, commands, and variables are described in this manual in a uniform 
  866. format.  The first line of a description contains the name of the item followed 
  867. by its arguments, if any. The category---function, variable, or 
  868. whatever---appears at the beginning of the line. The description follows on 
  869. succeeding lines, sometimes with examples. 
  870.  
  871.  A Sample Function Description 
  872.  A Sample Command Description 
  873.  A Sample Variable Description 
  874.  
  875.  
  876. ΓòÉΓòÉΓòÉ 4.3.5.1. A Sample Function Description ΓòÉΓòÉΓòÉ
  877.  
  878. In a function description, the name of the function being described appears 
  879. first.  It is followed on the same line by a list of parameters. The names used 
  880. for the parameters are also used in the body of the description. 
  881.  
  882. Here is a description of an imaginary function foo: 
  883.  
  884. Function:  foo (x, y, ...) 
  885. The function foo subtracts x from y, then adds the remaining arguments to the 
  886. result.  If y is not supplied, then the number 19 is used by default. 
  887.  
  888. foo (1, [3, 5], 3, 9)
  889.      => [ 14, 16 ]
  890. foo (5)
  891.      => 14
  892.  
  893. More generally, 
  894.  
  895. foo (w, x, y, ...)
  896. ==
  897. x - w + y + ...
  898.  
  899. Any parameter whose name contains the name of a type (e.g., integer, integer1 
  900. or matrix) is expected to be of that type.  Parameters named object may be of 
  901. any type.  Parameters with other sorts of names (e.g., new_file) are discussed 
  902. specifically in the description of the function.  In some sections, features 
  903. common to parameters of several functions are described at the beginning. 
  904.  
  905. Functions in Octave may be defined in several different ways.  The catagory 
  906. name for functions may include another name that indicates the way that the 
  907. function is defined.  These additional tags include 
  908.  
  909.  Built-in Function 
  910.            The function described is written in a language like C++, C, or 
  911.            Fortran, and is part of the compiled Octave binary. 
  912.  
  913.  Loadable Function 
  914.            The function described is written in a language like C++, C, or 
  915.            Fortran. On systems that support dynamic linking of user-supplied 
  916.            functions, it may be automatically linked while Octave is running, 
  917.            but only if it is needed.  See Dynamically Linked Functions. 
  918.  
  919.  Function File 
  920.            The function described is defined using Octave commands stored in a 
  921.            text file.  See Function Files. 
  922.  
  923.  Mapping Function 
  924.            The function described works element-by-element for matrix and 
  925.            vector arguments. 
  926.  
  927.  
  928. ΓòÉΓòÉΓòÉ 4.3.5.2. A Sample Command Description ΓòÉΓòÉΓòÉ
  929.  
  930. Command descriptions have a format similar to function descriptions, except 
  931. that the word `Function' is replaced by `Command.  Commands are functions that 
  932. may called without surrounding their arguments in parentheses.  For example, 
  933. here is the description for Octave's cd command: 
  934.  
  935. Command: cd dir 
  936.  
  937. Command: chdir dir 
  938. Change the current working directory to dir.  For example, cd ~/octave changes 
  939. the current working directory to `~/octave'.  If the directory does not exist, 
  940. an error message is printed and the working directory is not changed. 
  941.  
  942.  
  943. ΓòÉΓòÉΓòÉ 4.3.5.3. A Sample Variable Description ΓòÉΓòÉΓòÉ
  944.  
  945. A variable is a name that can hold a value.  Although any variable can be set 
  946. by the user, built-in variables typically exist specifically so that users can 
  947. change them to alter the way Octave behaves (built-in variables are also 
  948. sometimes called user options).  Ordinary variables and built-in variables are 
  949. described using a format like that for functions except that there are no 
  950. arguments. 
  951.  
  952. Here is a description of the imaginary variable do_what_i_mean_not_what_i_say. 
  953.  
  954. Built-in Variable: do_what_i_mean_not_what_i_say 
  955. If the value of this variable is nonzero, Octave will do what you actually 
  956. wanted, even if you have typed a completely different and meaningless list of 
  957. commands. 
  958.  
  959. Other variable descriptions have the same format, but `Built-in Variable' is 
  960. replaced by `Variable', for ordinary variables, or `Constant' for symbolic 
  961. constants whose values cannot be changed. 
  962.  
  963.  
  964. ΓòÉΓòÉΓòÉ 5. Getting Started ΓòÉΓòÉΓòÉ
  965.  
  966. This chapter explains some of Octave's basic features, including how to start 
  967. an Octave session, get help at the command prompt, edit the command line, and 
  968. write Octave programs that can be executed as commands from your shell. 
  969.  
  970.  Invoking Octave 
  971.  Quitting Octave 
  972.  Getting Help 
  973.  Command Line Editing 
  974.  Errors 
  975.  Executable Octave Programs 
  976.  Comments 
  977.  
  978.  
  979. ΓòÉΓòÉΓòÉ 5.1. Invoking Octave ΓòÉΓòÉΓòÉ
  980.  
  981. Normally, Octave is used interactively by running the program `octave' without 
  982. any arguments.  Once started, Octave reads commands from the terminal until you 
  983. tell it to exit. 
  984.  
  985. You can also specify the name of a file on the command line, and Octave will 
  986. read and execute the commands from the named file and then exit when it is 
  987. finished. 
  988.  
  989. You can further control how Octave starts by using the command-line options 
  990. described in the next section, and Octave itself can remind you of the options 
  991. available.  Type `octave --help' to display all available options and briefly 
  992. describe their use (`octave -h' is a shorter equivalent). 
  993.  
  994.  Command Line Options 
  995.  Startup Files 
  996.  
  997.  
  998. ΓòÉΓòÉΓòÉ 5.1.1. Command Line Options ΓòÉΓòÉΓòÉ
  999.  
  1000. Here is a complete list of all the command line options that Octave accepts. 
  1001.  
  1002.  --debug 
  1003.  -d 
  1004.            Enter parser debugging mode.  Using this option will cause Octave's 
  1005.            parser to print a lot of information about the commands it reads, 
  1006.            and is probably only useful if you are actually trying to debug the 
  1007.            parser. 
  1008.  
  1009.  --echo-commands 
  1010.  -x 
  1011.            Echo commands as they are executed. 
  1012.  
  1013.  --exec-path path 
  1014.            Specify the path to search for programs to run.  The value of path 
  1015.            specified on the command line will override any value of 
  1016.            OCTAVE_EXEC_PATH found in the environment, but not any commands in 
  1017.            the system or user startup files that set the built-in variable 
  1018.            EXEC_PATH. 
  1019.  
  1020.  --help 
  1021.  -h 
  1022.  -? 
  1023.            Print short help message and exit. 
  1024.  
  1025.  --info-file filename 
  1026.            Specify the name of the info file to use.  The value of filename 
  1027.            specified on the command line will override any value of 
  1028.            OCTAVE_INFO_FILE found in the environment, but not any commands in 
  1029.            the system or user startup files that set the built-in variable 
  1030.            INFO_FILE. 
  1031.  
  1032.  --info-program program 
  1033.            Specify the name of the info program to use.  The value of program 
  1034.            specified on the command line will override any value of 
  1035.            OCTAVE_INFO_PROGRAM found in the environment, but not any commands 
  1036.            in the system or user startup files that set the built-in variable 
  1037.            INFO_PROGRAM. 
  1038.  
  1039.  --interactive 
  1040.  -i 
  1041.            Force interactive behavior.  This can be useful for running Octave 
  1042.            via a remote shell command or inside an Emacs shell buffer.  For 
  1043.            another way to run Octave within Emacs, see Emacs. 
  1044.  
  1045.  --no-init-file 
  1046.            Don't read the `~/.octaverc' or `.octaverc' files. 
  1047.  
  1048.  --no-line-editing 
  1049.            Disable command-line editing. 
  1050.  
  1051.  --no-site-file 
  1052.            Don't read the site-wide `octaverc' file. 
  1053.  
  1054.  --norc 
  1055.  -f 
  1056.            Don't read any of the system or user initialization files at 
  1057.            startup. This is equivalent to using both of the options 
  1058.            --no-init-file and --no-site-file. 
  1059.  
  1060.  --path path 
  1061.  -p path 
  1062.            Specify the path to search for function files.  The value of path 
  1063.            specified on the command line will override any value of OCTAVE_PATH 
  1064.            found in the environment, but not any commands in the system or user 
  1065.            startup files that set the built-in variable LOADPATH. 
  1066.  
  1067.  --silent 
  1068.  --quiet 
  1069.  -q 
  1070.            Don't print the usual greeting and version message at startup. 
  1071.  
  1072.  --traditional 
  1073.  --braindead 
  1074.            Set initial values for user-preference variables to the following 
  1075.            values for compatibility with Matlab. 
  1076.  
  1077.                       PS1                           = ">> "
  1078.                       PS2                           = ""
  1079.                       beep_on_error                 = 1
  1080.                       default_save_format           = "mat-binary"
  1081.                       define_all_return_values      = 1
  1082.                       do_fortran_indexing           = 1
  1083.                       crash_dumps_octave_core       = 0
  1084.                       empty_list_elements_ok        = 1
  1085.                       implicit_str_to_num_ok        = 1
  1086.                       ok_to_lose_imaginary_part     = 1
  1087.                       page_screen_output            = 0
  1088.                       prefer_column_vectors         = 0
  1089.                       print_empty_dimensions        = 0
  1090.                       treat_neg_dim_as_zero         = 1
  1091.                       warn_function_name_clash      = 0
  1092.                       whitespace_in_literal_matrix  = "traditional"
  1093.  
  1094.  --verbose 
  1095.  -V 
  1096.            Turn on verbose output. 
  1097.  
  1098.  --version 
  1099.  -v 
  1100.            Print the program version number and exit. 
  1101.  
  1102.  file 
  1103.            Execute commands from file. 
  1104.  
  1105.  Octave also includes several built-in variables that contain information about 
  1106.  the command line, including the number of arguments and all of the options. 
  1107.  
  1108.  Built-in Variable: argv 
  1109.  The command line arguments passed to Octave are available in this variable. 
  1110.  For example, if you invoked Octave using the command 
  1111.  
  1112.   octave --no-line-editing --silent
  1113.  
  1114.  argv would be a list of strings with the elements --no-line-editing and 
  1115.  --silent. 
  1116.  
  1117.  If you write an executable Octave script, argv will contain the list of 
  1118.  arguments passed to the script.  see Executable Octave Programs. 
  1119.  
  1120.  Built-in Variable: program_invocation_name 
  1121.  
  1122.  Built-in Variable: program_name 
  1123.  When Octave starts, the value of the built-in variable program_invocation_name 
  1124.  is automatically set to the name that was typed at the shell prompt to run 
  1125.  Octave, and the value of program_name is automatically set to the final 
  1126.  component of program_invocation_name.  For example, if you typed 
  1127.  `*/bin/octave' to start Octave, program_invocation_name would have the value 
  1128.  "*/bin/octave", and program_name would have the value "octave". 
  1129.  
  1130.  If executing a script from the command line (e.g., octave foo.m or using an 
  1131.  executable Octave script, the program name is set to the name of the script. 
  1132.  See Executable Octave Programs for an example of how to create an executable 
  1133.  Octave script. 
  1134.  
  1135.  Here is an example of using these variables to reproduce Octave's command 
  1136.  line. 
  1137.  
  1138.   printf ("%s", program_name);
  1139.   for i = 1:nargin
  1140.     printf (" %s", argv(i));
  1141.   endfor
  1142.   printf ("\n");
  1143.  
  1144.  See Index Expressions for an explanation of how to properly index arrays of 
  1145.  strings and substrings in Octave, and See Defining Functions for information 
  1146.  about the variable nargin. 
  1147.  
  1148.  
  1149. ΓòÉΓòÉΓòÉ 5.1.2. Startup Files ΓòÉΓòÉΓòÉ
  1150.  
  1151. When Octave starts, it looks for commands to execute from the following files: 
  1152.  
  1153.  octave-home/share/octave/site/m/startup/octaverc 
  1154.            Where octave-home is the directory in which all of Octave is 
  1155.            installed (the default is `*').  This file is provided so that 
  1156.            changes to the default Octave environment can be made globally for 
  1157.            all users at your site for all versions of Octave you have 
  1158.            installed.  Some care should be taken when making changes to this 
  1159.            file, since all users of Octave at your site will be affected. 
  1160.  
  1161.  octave-home/share/octave/version/m/startup/octaverc 
  1162.            Where octave-home is the directory in which all of Octave is 
  1163.            installed (the default is `*'), and version is the version number of 
  1164.            Octave.  This file is provided so that changes to the default Octave 
  1165.            environment can be made globally for all users for a particular 
  1166.            version of Octave.  Some care should be taken when making changes to 
  1167.            this file, since all users of Octave at your site will be affected. 
  1168.  
  1169.  ~/.octaverc 
  1170.            This file is normally used to make personal changes to the default 
  1171.            Octave environment. 
  1172.  
  1173.  .octaverc 
  1174.            This file can be used to make changes to the default Octave 
  1175.            environment for a particular project.  Octave searches for this file 
  1176.            in the current directory after it reads `~/.octaverc'.  Any use of 
  1177.            the cd command in the `~/.octaverc' file will affect the directory 
  1178.            that Octave searches for the file `.octaverc'. 
  1179.  
  1180.            If you start Octave in your home directory, commands from from the 
  1181.            file `~/.octaverc' will only be executed once. 
  1182.  
  1183.  A message will be displayed as each of the startup files is read if you invoke 
  1184.  Octave with the --verbose option but without the --silent option. 
  1185.  
  1186.  Startup files may contain any valid Octave commands, including function 
  1187.  definitions. 
  1188.  
  1189.  
  1190. ΓòÉΓòÉΓòÉ 5.2. Quitting Octave ΓòÉΓòÉΓòÉ
  1191.  
  1192. Built-in Function:  exit (status) 
  1193.  
  1194. Built-in Function:  quit (status) 
  1195. Exit the current Octave session.  If the optional integer value status is 
  1196. supplied, pass that value to the operating system as the Octave's exit status. 
  1197.  
  1198. Built-in Function:  atexit (fcn) 
  1199. Register function to be called when Octave exits.  For example, 
  1200.  
  1201. function print_flops_at_exit ()
  1202.   printf ("\n%s\n", system ("fortune"));
  1203.   fflush (stdout);
  1204. endfunction
  1205. atexit ("print_flops_at_exit");
  1206.  
  1207. will print a message when Octave exits. 
  1208.  
  1209.  
  1210. ΓòÉΓòÉΓòÉ 5.3. Commands for Getting Help ΓòÉΓòÉΓòÉ
  1211.  
  1212. The entire text of this manual is available from the Octave prompt via the 
  1213. command help -i.  In addition, the documentation for individual user-written 
  1214. functions and variables is also available via the help command.  This section 
  1215. describes the commands used for reading the manual and the documentation 
  1216. strings for user-supplied functions and variables.  See Function Files, for 
  1217. more information about how to document the functions you write. 
  1218.  
  1219. Command: help 
  1220. Octave's help command can be used to print brief usage-style messages, or to 
  1221. display information directly from an on-line version of the printed manual, 
  1222. using the GNU Info browser.  If invoked without any arguments, help prints a 
  1223. list of all the available operators, functions, and built-in variables.  If the 
  1224. first argument is -i, the help command searches the index of the on-line 
  1225. version of this manual for the given topics. 
  1226.  
  1227. For example, the command help help prints a short message describing the help 
  1228. command, and help -i help starts the GNU Info browser at this node in the 
  1229. on-line version of the manual. 
  1230.  
  1231. Once the GNU Info browser is running, help for using it is available using the 
  1232. command C-h. 
  1233.  
  1234. The help command can give you information about operators, but not the comma 
  1235. and semicolons that are used as command separators.  To get help for those, you 
  1236. must type help comma or help semicolon. 
  1237.  
  1238. Built-in Variable: INFO_FILE 
  1239. The variable INFO_FILE names the location of the Octave info file. The default 
  1240. value is "octave-home/info/octave.info", where octave-home is the directory 
  1241. where all of Octave is installed. 
  1242.  
  1243. Built-in Variable: INFO_PROGRAM 
  1244. The variable INFO_PROGRAM names the info program to run.  Its initial value is 
  1245. "octave-home/libexec/octave/version/exec/arch/info", where octave-home is the 
  1246. directory where all of Octave is installed, version is the Octave version 
  1247. number, and arch is the machine type.  The value of INFO_PROGRAM can be 
  1248. overridden by the environment variable OCTAVE_INFO_PROGRAM, or the command line 
  1249. argument --info-program NAME, or by setting the value of the built-in variable 
  1250. INFO_PROGRAM in a startup script. 
  1251.  
  1252. Built-in Variable: suppress_verbose_help_message 
  1253. If the value of suppress_verbose_help_message is nonzero, Octave will not add 
  1254. additional help information to the end of the output from the help command and 
  1255. usage messages for built-in commands. 
  1256.  
  1257.  
  1258. ΓòÉΓòÉΓòÉ 5.4. Command Line Editing ΓòÉΓòÉΓòÉ
  1259.  
  1260. Octave uses the GNU readline library to provide an extensive set of 
  1261. command-line editing and history features.  Only the most common features are 
  1262. described in this manual.  Please see The GNU Readline Library manual for more 
  1263. information. 
  1264.  
  1265. To insert printing characters (letters, digits, symbols, etc.), simply type the 
  1266. character.  Octave will insert the character at the cursor and advance the 
  1267. cursor forward. 
  1268.  
  1269. Many of the command-line editing functions operate using control characters. 
  1270. For example, the character Control-a moves the cursor to the beginning of the 
  1271. line.  To type C-a, hold down CTRL and then press a.  In the following 
  1272. sections, control characters such as Control-a are written as C-a. 
  1273.  
  1274. Another set of command-line editing functions use Meta characters.  On some 
  1275. terminals, you type M-u by holding down META and pressing u.  If your terminal 
  1276. does not have a META key, you can still type Meta charcters using two-character 
  1277. sequences starting with ESC.  Thus, to enter M-u, you could type ESCu.  The ESC 
  1278. character sequences are also allowed on terminals with real Meta keys.  In the 
  1279. following sections, Meta characters such as Meta-u are written as M-u. 
  1280.  
  1281.  Cursor Motion 
  1282.  Killing and Yanking 
  1283.  Commands For Text 
  1284.  Commands For Completion 
  1285.  Commands For History 
  1286.  Customizing the Prompt 
  1287.  Diary and Echo Commands 
  1288.  
  1289.  
  1290. ΓòÉΓòÉΓòÉ 5.4.1. Cursor Motion ΓòÉΓòÉΓòÉ
  1291.  
  1292. The following commands allow you to position the cursor. 
  1293.  
  1294.  C-b 
  1295.            Move back one character. 
  1296.  
  1297.  C-f 
  1298.            Move forward one character. 
  1299.  
  1300.  DEL 
  1301.            Delete the character to the left of the cursor. 
  1302.  
  1303.  C-d 
  1304.            Delete the character underneath the cursor. 
  1305.  
  1306.  M-f 
  1307.            Move forward a word. 
  1308.  
  1309.  M-b 
  1310.            Move backward a word. 
  1311.  
  1312.  C-a 
  1313.            Move to the start of the line. 
  1314.  
  1315.  C-e 
  1316.            Move to the end of the line. 
  1317.  
  1318.  C-l 
  1319.            Clear the screen, reprinting the current line at the top. 
  1320.  
  1321.  C-_ 
  1322.  C-/ 
  1323.            Undo the last thing that you did.  You can undo all the way back to 
  1324.            an empty line. 
  1325.  
  1326.  M-r 
  1327.            Undo all changes made to this line.  This is like typing the `undo' 
  1328.            command enough times to get back to the beginning. 
  1329.  
  1330.  The above table describes the most basic possible keystrokes that you need in 
  1331.  order to do editing of the input line.  On most terminals, you can also use 
  1332.  the arrow keys in place of C-f and C-b to move forward and backward. 
  1333.  
  1334.  Notice how C-f moves forward a character, while M-f moves forward a word.  It 
  1335.  is a loose convention that control keystrokes operate on characters while meta 
  1336.  keystrokes operate on words. 
  1337.  
  1338.  There is also a function available so that you can clear the screen from 
  1339.  within Octave programs. 
  1340.  
  1341.  Built-in Function:  clc () 
  1342.  
  1343.  Built-in Function:  home () 
  1344.  Clear the terminal screen and move the cursor to the upper left corner. 
  1345.  
  1346.  
  1347. ΓòÉΓòÉΓòÉ 5.4.2. Killing and Yanking ΓòÉΓòÉΓòÉ
  1348.  
  1349. Killing text means to delete the text from the line, but to save it away for 
  1350. later use, usually by yanking it back into the line. If the description for a 
  1351. command says that it `kills' text, then you can be sure that you can get the 
  1352. text back in a different (or the same) place later. 
  1353.  
  1354. Here is the list of commands for killing text. 
  1355.  
  1356.  C-k 
  1357.            Kill the text from the current cursor position to the end of the 
  1358.            line. 
  1359.  
  1360.  M-d 
  1361.            Kill from the cursor to the end of the current word, or if between 
  1362.            words, to the end of the next word. 
  1363.  
  1364.  M-DEL 
  1365.            Kill from the cursor to the start of the previous word, or if 
  1366.            between words, to the start of the previous word. 
  1367.  
  1368.  C-w 
  1369.            Kill from the cursor to the previous whitespace.  This is different 
  1370.            than M-DEL because the word boundaries differ. 
  1371.  
  1372.  And, here is how to yank the text back into the line.  Yanking means to copy 
  1373.  the most-recently-killed text from the kill buffer. 
  1374.  
  1375.  C-y 
  1376.            Yank the most recently killed text back into the buffer at the 
  1377.            cursor. 
  1378.  
  1379.  M-y 
  1380.            Rotate the kill-ring, and yank the new top.  You can only do this if 
  1381.            the prior command is C-y or M-y. 
  1382.  
  1383.  When you use a kill command, the text is saved in a kill-ring. Any number of 
  1384.  consecutive kills save all of the killed text together, so that when you yank 
  1385.  it back, you get it in one clean sweep.  The kill ring is not line specific; 
  1386.  the text that you killed on a previously typed line is available to be yanked 
  1387.  back later, when you are typing another line. 
  1388.  
  1389.  
  1390. ΓòÉΓòÉΓòÉ 5.4.3. Commands For Changing Text ΓòÉΓòÉΓòÉ
  1391.  
  1392. The following commands can be used for entering characters that would otherwise 
  1393. have a special meaning (e.g., TAB, C-q, etc.), or for quickly correcting typing 
  1394. mistakes. 
  1395.  
  1396.  C-q 
  1397.  C-v 
  1398.            Add the next character that you type to the line verbatim.  This is 
  1399.            how to insert things like C-q for example. 
  1400.  
  1401.  M-TAB 
  1402.            Insert a tab character. 
  1403.  
  1404.  C-t 
  1405.            Drag the character before the cursor forward over the character at 
  1406.            the cursor, also moving the cursor forward.  If the cursor is at the 
  1407.            end of the line, then transpose the two characters before it. 
  1408.  
  1409.  M-t 
  1410.            Drag the word behind the cursor past the word in front of the cursor 
  1411.            moving the cursor over that word as well. 
  1412.  
  1413.  M-u 
  1414.            Uppercase the characters following the cursor to the end of the 
  1415.            current (or following) word, moving the cursor to the end of the 
  1416.            word. 
  1417.  
  1418.  M-l 
  1419.            Lowecase the characters following the cursor to the end of the 
  1420.            current (or following) word, moving the cursor to the end of the 
  1421.            word. 
  1422.  
  1423.  M-c 
  1424.            Uppercase the character following the cursor (or the beginning of 
  1425.            the next word if the cursor is between words), moving the cursor to 
  1426.            the end of the word. 
  1427.  
  1428.  
  1429. ΓòÉΓòÉΓòÉ 5.4.4. Letting Readline Type For You ΓòÉΓòÉΓòÉ
  1430.  
  1431. The following commands allow Octave to complete command and variable names for 
  1432. you. 
  1433.  
  1434.  TAB 
  1435.            Attempt to do completion on the text before the cursor.  Octave can 
  1436.            complete the names of commands and variables. 
  1437.  
  1438.  M-? 
  1439.            List the possible completions of the text before the cursor. 
  1440.  
  1441.  Built-in Variable: completion_append_char 
  1442.  The value of completion_append_char is used as the character to append to 
  1443.  successful command-line completion attempts.  The default value is " " (a 
  1444.  single space). 
  1445.  
  1446.  Built-in Function:  completion_matches (hint) 
  1447.  Generate possible completions given hint. 
  1448.  
  1449.  This function is provided for the benefit of programs like Emacs which might 
  1450.  be controlling Octave and handling user input.  The current command number is 
  1451.  not incremented when this function is called.  This is a feature, not a bug. 
  1452.  
  1453.  
  1454. ΓòÉΓòÉΓòÉ 5.4.5. Commands For Manipulating The History ΓòÉΓòÉΓòÉ
  1455.  
  1456. Octave normally keeps track of the commands you type so that you can recall 
  1457. previous commands to edit or execute them again.  When you exit Octave, the 
  1458. most recent commands you have typed, up to the number specified by the variable 
  1459. history_size, are saved in a file. When Octave starts, it loads an initial list 
  1460. of commands from the file named by the variable history_file. 
  1461.  
  1462. Here are the commands for simple browsing and searching the history list. 
  1463.  
  1464.  LFD 
  1465.  RET 
  1466.            Accept the line regardless of where the cursor is.  If this line is 
  1467.            non-empty, add it to the history list.  If this line was a history 
  1468.            line, then restore the history line to its original state. 
  1469.  
  1470.  C-p 
  1471.            Move `up' through the history list. 
  1472.  
  1473.  C-n 
  1474.            Move `down' through the history list. 
  1475.  
  1476.  M-< 
  1477.            Move to the first line in the history. 
  1478.  
  1479.  M-> 
  1480.            Move to the end of the input history, i.e., the line you are 
  1481.            entering! 
  1482.  
  1483.  C-r 
  1484.            Search backward starting at the current line and moving `up' through 
  1485.            the history as necessary.  This is an incremental search. 
  1486.  
  1487.  C-s 
  1488.            Search forward starting at the current line and moving `down' 
  1489.            through the history as necessary. 
  1490.  
  1491.  On most terminals, you can also use the arrow keys in place of C-p and C-n to 
  1492.  move through the history list. 
  1493.  
  1494.  In addition to the keyboard commands for moving through the history list, 
  1495.  Octave provides three functions for viewing, editing, and re-running chunks of 
  1496.  commands from the history list. 
  1497.  
  1498.  Command: history options 
  1499.  If invoked with no arguments, history displays a list of commands that you 
  1500.  have executed.  Valid options are: 
  1501.  
  1502.  -w file 
  1503.            Write the current history to the file file.  If the name is omitted, 
  1504.            use the default history file (normally `~/.octave_hist'). 
  1505.  
  1506.  -r file 
  1507.            Read the file file, replacing the current history list with its 
  1508.            contents.  If the name is omitted, use the default history file 
  1509.            (normally `~/.octave_hist'). 
  1510.  
  1511.  N 
  1512.            Only display the most recent N lines of history. 
  1513.  
  1514.  -q 
  1515.            Don't number the displayed lines of history.  This is useful for 
  1516.            cutting and pasting commands if you are using the X Window System. 
  1517.  
  1518.  For example, to display the five most recent commands that you have typed 
  1519.  without displaying line numbers, use the command history -q 5. 
  1520.  
  1521.  Command: edit_history options 
  1522.  If invoked with no arguments, edit_history allows you to edit the history list 
  1523.  using the editor named by the variable EDITOR.  The commands to be edited are 
  1524.  first copied to a temporary file.  When you exit the editor, Octave executes 
  1525.  the commands that remain in the file. It is often more convenient to use 
  1526.  edit_history to define functions rather than attempting to enter them directly 
  1527.  on the command line. By default, the block of commands is executed as soon as 
  1528.  you exit the editor.  To avoid executing any commands, simply delete all the 
  1529.  lines from the buffer before exiting the editor. 
  1530.  
  1531.  The edit_history command takes two optional arguments specifying the history 
  1532.  numbers of first and last commands to edit.  For example, the command 
  1533.  
  1534.   edit_history 13
  1535.  
  1536.  extracts all the commands from the 13th through the last in the history list. 
  1537.  The command 
  1538.  
  1539.   edit_history 13 169
  1540.  
  1541.  only extracts commands 13 through 169.  Specifying a larger number for the 
  1542.  first command than the last command reverses the list of commands before 
  1543.  placing them in the buffer to be edited.  If both arguments are omitted, the 
  1544.  previous command in the history list is used. 
  1545.  
  1546.  Command: run_history 
  1547.  Similar to edit_history, except that the editor is not invoked, and the 
  1548.  commands are simply executed as they appear in the history list. 
  1549.  
  1550.  Built-in Variable: EDITOR 
  1551.  A string naming the editor to use with the edit_history command. If the 
  1552.  environment variable EDITOR is set when Octave starts, its value is used as 
  1553.  the default.  Otherwise, EDITOR is set to "emacs". 
  1554.  
  1555.  Built-in Variable: history_file 
  1556.  This variable specifies the name of the file used to store command history. 
  1557.  The default value is "~/.octave_hist", but may be overridden by the 
  1558.  environment variable OCTAVE_HISTFILE. 
  1559.  
  1560.  Built-in Variable: history_size 
  1561.  This variable specifies how many entries to store in the history file. The 
  1562.  default value is 1024, but may be overridden by the environment variable 
  1563.  OCTAVE_HISTSIZE. 
  1564.  
  1565.  Built-in Variable: saving_history 
  1566.  If the value of saving_history is nonzero, command entered on the command line 
  1567.  are saved in the file specified by the variable history_file. 
  1568.  
  1569.  
  1570. ΓòÉΓòÉΓòÉ 5.4.6. Customizing the Prompt ΓòÉΓòÉΓòÉ
  1571.  
  1572. The following variables are available for customizing the appearance of the 
  1573. command-line prompts.  Octave allows the prompt to be customized by inserting a 
  1574. number of backslash-escaped special characters that are decoded as follows: 
  1575.  
  1576.  `\t' 
  1577.            The time. 
  1578.  
  1579.  `\d' 
  1580.            The date. 
  1581.  
  1582.  `\n' 
  1583.            Begins a new line by printing the equivalent of a carriage return 
  1584.            followed by a line feed. 
  1585.  
  1586.  `\s' 
  1587.            The name of the program (usually just `octave'). 
  1588.  
  1589.  `\w' 
  1590.            The current working directory. 
  1591.  
  1592.  `\W' 
  1593.            The basename of the current working directory. 
  1594.  
  1595.  `\u' 
  1596.            The username of the current user. 
  1597.  
  1598.  `\h' 
  1599.            The hostname, up to the first `.'. 
  1600.  
  1601.  `\H' 
  1602.            The hostname. 
  1603.  
  1604.  `\#' 
  1605.            The command number of this command, counting from when Octave 
  1606.            starts. 
  1607.  
  1608.  `\!' 
  1609.            The history number of this command.  This differs from `\#' by the 
  1610.            number of commands in the history list when Octave starts. 
  1611.  
  1612.  `\$' 
  1613.            If the effective UID is 0, a `#', otherwise a `$'. 
  1614.  
  1615.  `\nnn' 
  1616.            The character whose character code in octal is nnn. 
  1617.  
  1618.  `\\' 
  1619.            A backslash. 
  1620.  
  1621.  Built-in Variable: PS1 
  1622.  The primary prompt string.  When executing interactively, Octave displays the 
  1623.  primary prompt PS1 when it is ready to read a command. 
  1624.  
  1625.  The default value of PS1 is "\s:\#> ".  To change it, use a command like 
  1626.  
  1627.   octave:13> PS1 = "\\u@\\H> "
  1628.  
  1629.  which will result in the prompt `boris@kremvax> ' for the user `boris' logged 
  1630.  in on the host `kremvax.kgb.su'.  Note that two backslashes are required to 
  1631.  enter a backslash into a string. See Strings. 
  1632.  
  1633.  Built-in Variable: PS2 
  1634.  The secondary prompt string, which is printed when Octave is expecting 
  1635.  additional input to complete a command.  For example, when defining a function 
  1636.  over several lines, Octave will print the value of PS1 at the beginning of 
  1637.  each line after the first.  The default value of PS2 is "> ". 
  1638.  
  1639.  Built-in Variable: PS4 
  1640.  If Octave is invoked with the --echo-input option, the value of PS4 is printed 
  1641.  before each line of input that is echoed.  The default value of PS4 is "+ ". 
  1642.  See Invoking Octave, for a description of --echo-input. 
  1643.  
  1644.  
  1645. ΓòÉΓòÉΓòÉ 5.4.7. Diary and Echo Commands ΓòÉΓòÉΓòÉ
  1646.  
  1647. Octave's diary feature allows you to keep a log of all or part of an 
  1648. interactive session by recording the input you type and the output that Octave 
  1649. produces in a separate file. 
  1650.  
  1651. Command: diary options 
  1652. Create a list of all commands and the output they produce, mixed together just 
  1653. as you see them on your terminal.  Valid options are: 
  1654.  
  1655.  on 
  1656.            Start recording your session in a file called `diary' in your 
  1657.            current working directory. 
  1658.  
  1659.  off 
  1660.            Stop recording your session in the diary file. 
  1661.  
  1662.  file 
  1663.            Record your session in the file named file. 
  1664.  
  1665.  Without any arguments, diary toggles the current diary state. 
  1666.  
  1667.  Sometimes it is useful to see the commands in a function or script as they are 
  1668.  being evaluated.  This can be especially helpful for debugging some kinds of 
  1669.  problems. 
  1670.  
  1671.  Command: echo options 
  1672.  Control whether commands are displayed as they are executed.  Valid options 
  1673.  are: 
  1674.  
  1675.  on 
  1676.            Enable echoing of commands as they are executed in script files. 
  1677.  
  1678.  off 
  1679.            Disable echoing of commands as they are executed in script files. 
  1680.  
  1681.  on all 
  1682.            Enable echoing of commands as they are executed in script files and 
  1683.            functions. 
  1684.  
  1685.  off all 
  1686.            Disable echoing of commands as they are executed in script files and 
  1687.            functions. 
  1688.  
  1689.  If invoked without any arguments, echo toggles the current echo state. 
  1690.  
  1691.  Built-in Variable: echo_executing_commands 
  1692.  This variable is may also be used to control the echo state.  It may be the 
  1693.  sum of the following values: 
  1694.  
  1695.  1 
  1696.            Echo commands read from script files. 
  1697.  
  1698.  2 
  1699.            Echo commands from functions. 
  1700.  
  1701.  4 
  1702.            Echo commands read from command line. 
  1703.  
  1704.  More than one state can be active at once.  For example, a value of 3 is 
  1705.  equivalent to the command echo on all. 
  1706.  
  1707.  The value of echo_executing_commands is set by the echo command and the 
  1708.  command line option --echo-input. 
  1709.  
  1710.  
  1711. ΓòÉΓòÉΓòÉ 5.5. How Octave Reports Errors ΓòÉΓòÉΓòÉ
  1712.  
  1713. Octave reports two kinds of errors for invalid programs. 
  1714.  
  1715. A parse error occurs if Octave cannot understand something you have typed.  For 
  1716. example, if you misspell a keyword, 
  1717.  
  1718. octave:13> functon y = f (x) y = x^2; endfunction
  1719.  
  1720. Octave will respond immediately with a message like this: 
  1721.  
  1722. parse error:
  1723.  
  1724.   functon y = f (x) y = x^2; endfunction
  1725.           ^
  1726.  
  1727. For most parse errors, Octave uses a caret (`^') to mark the point on the line 
  1728. where it was unable to make sense of your input.  In this case, Octave 
  1729. generated an error message because the keyword function was misspelled. 
  1730. Instead of seeing `function f', Octave saw two consecutive variable names, 
  1731. which is invalid in this context.  It marked the error at the y because the 
  1732. first name by itself was accepted as valid input. 
  1733.  
  1734. Another class of error message occurs at evaluation time.  These errors are 
  1735. called run-time errors, or sometimes evaluation errors because they occur when 
  1736. your program is being run, or evaluated.  For example, if after correcting the 
  1737. mistake in the previous function definition, you type 
  1738.  
  1739. octave:13> f ()
  1740.  
  1741. Octave will respond with 
  1742.  
  1743. error: `x' undefined near line 1 column 24
  1744. error: evaluating expression near line 1, column 24
  1745. error: evaluating assignment expression near line 1, column 22
  1746. error: called from `f'
  1747.  
  1748. This error message has several parts, and gives you quite a bit of information 
  1749. to help you locate the source of the error.  The messages are generated from 
  1750. the point of the innermost error, and provide a traceback of enclosing 
  1751. expressions and function calls. 
  1752.  
  1753. In the example above, the first line indicates that a variable named `x' was 
  1754. found to be undefined near line 1 and column 24 of some function or expression. 
  1755. For errors occurring within functions, lines from the beginning of the file 
  1756. containing the function definition.  For errors occurring at the top level, the 
  1757. line number indicates the input line number, which is usually displayed in the 
  1758. prompt string. 
  1759.  
  1760. The second and third lines in the example indicate that the error occurred 
  1761. within an assignment expression, and the last line of the error message 
  1762. indicates that the error occurred within the function f. If the function f had 
  1763. been called from another function, for example, g, the list of errors would 
  1764. have ended with one more line: 
  1765.  
  1766. error: called from `g'
  1767.  
  1768. These lists of function calls usually make it fairly easy to trace the path 
  1769. your program took before the error occurred, and to correct the error before 
  1770. trying again. 
  1771.  
  1772.  
  1773. ΓòÉΓòÉΓòÉ 5.6. Executable Octave Programs ΓòÉΓòÉΓòÉ
  1774.  
  1775. Once you have learned Octave, you may want to write self-contained Octave 
  1776. scripts, using the `#!' script mechanism.  You can do this on GNU systems and 
  1777. on many Unix systems (1) 
  1778.  
  1779. For example, you could create a text file named `hello', containing the 
  1780. following lines: 
  1781.  
  1782. #! octave-interpreter-name -qf
  1783. # a sample Octave program
  1784. printf ("Hello, world!\n");
  1785.  
  1786. (where octave-interpreter-name should be replaced with the full file name for 
  1787. your Octave binary).  After making this file executable (with the chmod 
  1788. command), you can simply type: 
  1789.  
  1790. hello
  1791.  
  1792. at the shell, and the system will arrange to run Octave as if you had typed: 
  1793.  
  1794. octave hello
  1795.  
  1796. The line beginning with `#!' lists the full file name of an interpreter to be 
  1797. run, and an optional initial command line argument to pass to that interpreter. 
  1798. The operating system then runs the interpreter with the given argument and the 
  1799. full argument list of the executed program.  The first argument in the list is 
  1800. the full file name of the Octave program. The rest of the argument list will 
  1801. either be options to Octave, or data files, or both.  The `-qf' option is 
  1802. usually specified in stand-alone Octave programs to prevent them from printing 
  1803. the normal startup message, and to keep them from behaving differently 
  1804. depending on the contents of a particular user's `~/.octaverc' file.  See 
  1805. Invoking Octave.  Note that some operating systems may place a limit on the 
  1806. number of characters that are recognized after `#!'. 
  1807.  
  1808. Self-contained Octave scripts are useful when you want to write a program which 
  1809. users can invoke without knowing that the program is written in the Octave 
  1810. language. 
  1811.  
  1812. If you invoke an executable Octave script with command line arguments, the 
  1813. arguments are available in the built-in variable argv. See Command Line 
  1814. Options.  For example, the following program will reproduce the command line 
  1815. that is used to execute it. 
  1816.  
  1817. #! /bin/octave -qf
  1818. printf ("%s", program_name);
  1819. for i = 1:nargin
  1820.   printf (" %s", argv(i,:));
  1821. endfor
  1822. printf ("\n");
  1823.  
  1824.  
  1825. ΓòÉΓòÉΓòÉ 5.7. Comments in Octave Programs ΓòÉΓòÉΓòÉ
  1826.  
  1827. A comment is some text that is included in a program for the sake of human 
  1828. readers, and that is not really part of the program.  Comments can explain what 
  1829. the program does, and how it works.  Nearly all programming languages have 
  1830. provisions for comments, because programs are typically hard to understand 
  1831. without them. 
  1832.  
  1833. In the Octave language, a comment starts with either the sharp sign character, 
  1834. `#', or the percent symbol `%' and continues to the end of the line.  The 
  1835. Octave interpreter ignores the rest of a line following a sharp sign or percent 
  1836. symbol.  For example, we could have put the following into the function f: 
  1837.  
  1838. function xdot = f (x, t)
  1839.  
  1840. # usage: f (x, t)
  1841. #
  1842. # This function defines the right hand
  1843. # side functions for a set of nonlinear
  1844. # differential equations.
  1845.  
  1846.   r = 0.25;
  1847.   ...
  1848. endfunction
  1849.  
  1850. The help command (see Getting Help) is able to find the first block of comments 
  1851. in a function (even those that are composed directly on the command line). 
  1852. This means that users of Octave can use the same commands to get help for 
  1853. built-in functions, and for functions that you have defined.  For example, 
  1854. after defining the function f above, the command help f produces the output 
  1855.  
  1856.  usage: f (x, t)
  1857.  
  1858.  This function defines the right hand
  1859.  side functions for a set of nonlinear
  1860.  differential equations.
  1861.  
  1862. Although it is possible to put comment lines into keyboard-composed throw-away 
  1863. Octave programs, it usually isn't very useful, because the purpose of a comment 
  1864. is to help you or another person understand the program at a later time. 
  1865.  
  1866.  
  1867. ΓòÉΓòÉΓòÉ 6. Data Types ΓòÉΓòÉΓòÉ
  1868.  
  1869. All versions of Octave include a number of built-in data types, including real 
  1870. and complex scalars and matrices, character strings, and a data structure type. 
  1871.  
  1872. It is also possible to define new specialized data types by writing a small 
  1873. amount of C++ code.  On some systems, new data types can be loaded dynamically 
  1874. while Octave is running, so it is not necessary to recompile all of Octave just 
  1875. to add a new type. See Dynamically Linked Functions for more information about 
  1876. Octave's dynamic linking capabilities.  User-defined Data Types describes what 
  1877. you must do to define a new data type for Octave. 
  1878.  
  1879.  Built-in Data Types 
  1880.  User-defined Data Types 
  1881.  Object Sizes 
  1882.  
  1883.  
  1884. ΓòÉΓòÉΓòÉ 6.1. Built-in Data Types ΓòÉΓòÉΓòÉ
  1885.  
  1886. The standard built-in data types are real and complex scalars and matrices, 
  1887. ranges, character strings, and a data structure type. Additional built-in data 
  1888. types may be added in future versions.  If you need a specialized data type 
  1889. that is not currently provided as a built-in type, you are encouraged to write 
  1890. your own user-defined data type and contribute it for distribution in a future 
  1891. release of Octave. 
  1892.  
  1893.  Numeric Objects 
  1894.  String Objects 
  1895.  Data Structure Objects 
  1896.  
  1897.  
  1898. ΓòÉΓòÉΓòÉ 6.1.1. Numeric Objects ΓòÉΓòÉΓòÉ
  1899.  
  1900. Octave's built-in numeric objects include real and complex scalars and 
  1901. matrices.  All built-in numeric data is currently stored as double precision 
  1902. numbers.  On systems that use the IEEE floating point format, values in the 
  1903. range of approximately  2.2251e-308 to 1.7977e+308  can be stored, and the 
  1904. relative precision is approximately  2.2204e-16. The exact values are given by 
  1905. the variables realmin, realmax, and eps, respectively. 
  1906.  
  1907. Matrix objects can be of any size, and can be dynamically reshaped and resized. 
  1908. It is easy to extract individual rows, columns, or submatrices is using a 
  1909. variety of powerful indexing features.  See Index Expressions. 
  1910.  
  1911. See Numeric Data Types, for more information. 
  1912.  
  1913.  
  1914. ΓòÉΓòÉΓòÉ 6.1.2. String Objects ΓòÉΓòÉΓòÉ
  1915.  
  1916. A character string in Octave consists of a sequence of characters enclosed in 
  1917. either double-quote or single-quote marks.  Internally, Octave currently stores 
  1918. strings as matrices of characters.  All the indexing operations that work for 
  1919. matrix objects also work for strings. 
  1920.  
  1921. See Strings, for more information. 
  1922.  
  1923.  
  1924. ΓòÉΓòÉΓòÉ 6.1.3. Data Structure Objects ΓòÉΓòÉΓòÉ
  1925.  
  1926. Octave's data structure type can help you to organize related objects of 
  1927. different types.  The current implementation uses an associative array with 
  1928. indices limited to strings, but the syntax is more like C-style structures. 
  1929.  
  1930. See Data Structures, for more information. 
  1931.  
  1932.  
  1933. ΓòÉΓòÉΓòÉ 6.2. User-defined Data Types ΓòÉΓòÉΓòÉ
  1934.  
  1935. Someday I hope to expand this to include a complete description of Octave's 
  1936. mechanism for managing user-defined data types.  Until this feature is 
  1937. documented here, you will have to make do by reading the code in the `ov.h', 
  1938. `ops.h', and related files from Octave's `src' directory. 
  1939.  
  1940.  
  1941. ΓòÉΓòÉΓòÉ 6.3. Object Sizes ΓòÉΓòÉΓòÉ
  1942.  
  1943. The following functions allow you to determine the size of a variable or 
  1944. expression.  These functions are defined for all objects.  They return -1 when 
  1945. the operation doesn't make sense.  For example, Octave's data structure type 
  1946. doesn't have rows or columns, so the rows and columns functions return -1 for 
  1947. structure arguments. 
  1948.  
  1949. Function File:  columns (a) 
  1950. Return the number of columns of a. 
  1951.  
  1952. Function File:  rows (a) 
  1953. Return the number of rows of a. 
  1954.  
  1955. Function File:  length (a) 
  1956. Return the number of rows of a or the number of columns of a, whichever is 
  1957. larger. 
  1958.  
  1959. Function File:  size (a, n) 
  1960. Return the number rows and columns of a. 
  1961.  
  1962. With one input argument and one output argument, the result is returned in a 2 
  1963. element row vector.  If there are two output arguments, the number of rows is 
  1964. assigned to the first, and the number of columns to the second.  For example, 
  1965.  
  1966. size ([1, 2; 3, 4; 5, 6])
  1967.      => [ 3, 2 ]
  1968.  
  1969. [nr, nc] = size ([1, 2; 3, 4; 5, 6])
  1970.      => nr = 3
  1971.      => nc = 2
  1972.  
  1973. If given a second argument of either 1 or 2, size will return only the row or 
  1974. column dimension.  For example 
  1975.  
  1976. size ([1, 2; 3, 4; 5, 6], 2)
  1977.      => 2
  1978.  
  1979. returns the number of columns in the given matrix. 
  1980.  
  1981. Function File:  isempty (a) 
  1982. Return 1 if a is an empty matrix (either the number of rows, or the number of 
  1983. columns, or both are zero).  Otherwise, return 0. 
  1984.  
  1985.  
  1986. ΓòÉΓòÉΓòÉ 7. Numeric Data Types ΓòÉΓòÉΓòÉ
  1987.  
  1988. A numeric constant may be a scalar, a vector, or a matrix, and it may contain 
  1989. complex values. 
  1990.  
  1991. The simplest form of a numeric constant, a scalar, is a single number that can 
  1992. be an integer, a decimal fraction, a number in scientific (exponential) 
  1993. notation, or a complex number.  Note that all numeric constants are represented 
  1994. within Octave in double-precision floating point format (complex constants are 
  1995. stored as pairs of double-precision floating point values).  Here are some 
  1996. examples of real-valued numeric constants, which all have the same value: 
  1997.  
  1998. 105
  1999. 1.05e+2
  2000. 1050e-1
  2001.  
  2002. To specify complex constants, you can write an expression of the form 
  2003.  
  2004. 3 + 4i
  2005. 3.0 + 4.0i
  2006. 0.3e1 + 40e-1i
  2007.  
  2008. all of which are equivalent.  The letter `i' in the previous example stands for 
  2009. the pure imaginary constant, defined as  sqrt (-1). 
  2010.  
  2011. For Octave to recognize a value as the imaginary part of a complex constant, a 
  2012. space must not appear between the number and the `i'. If it does, Octave will 
  2013. print an error message, like this: 
  2014.  
  2015. octave:13> 3 + 4 i
  2016.  
  2017. parse error:
  2018.  
  2019.   3 + 4 i
  2020.         ^
  2021.  
  2022. You may also use `j', `I', or `J' in place of the `i' above.  All four forms 
  2023. are equivalent. 
  2024.  
  2025.  Matrices 
  2026.  Ranges 
  2027.  Predicates for Numeric Objects 
  2028.  
  2029.  
  2030. ΓòÉΓòÉΓòÉ 7.1. Matrices ΓòÉΓòÉΓòÉ
  2031.  
  2032. It is easy to define a matrix of values in Octave.  The size of the matrix is 
  2033. determined automatically, so it is not necessary to explicitly state the 
  2034. dimensions.  The expression 
  2035.  
  2036. a = [1, 2; 3, 4]
  2037.  
  2038. results in the matrix 
  2039.  
  2040.  
  2041.         /      \
  2042.         | 1  2 |
  2043.   a  =  |      |
  2044.         | 3  4 |
  2045.         \      /
  2046.  
  2047. Elements of a matrix may be arbitrary expressions, provided that the dimensions 
  2048. all make sense when combining the various pieces.  For example, given the above 
  2049. matrix, the expression 
  2050.  
  2051. [ a, a ]
  2052.  
  2053. produces the matrix 
  2054.  
  2055. ans =
  2056.  
  2057.   1  2  1  2
  2058.   3  4  3  4
  2059.  
  2060. but the expression 
  2061.  
  2062. [ a, 1 ]
  2063.  
  2064. produces the error 
  2065.  
  2066. error: number of rows must match near line 13, column 6
  2067.  
  2068. (assuming that this expression was entered as the first thing on line 13, of 
  2069. course). 
  2070.  
  2071. Inside the square brackets that delimit a matrix expression, Octave looks at 
  2072. the surrounding context to determine whether spaces and newline characters 
  2073. should be converted into element and row separators, or simply ignored, so 
  2074. commands like 
  2075.  
  2076. [ linspace (1, 2) ]
  2077.  
  2078. and 
  2079.  
  2080. a = [ 1 2
  2081.       3 4 ]
  2082.  
  2083. will work.  However, some possible sources of confusion remain.  For example, 
  2084. in the expression 
  2085.  
  2086. [ 1 - 1 ]
  2087.  
  2088. the `-' is treated as a binary operator and the result is the scalar 0, but in 
  2089. the expression 
  2090.  
  2091. [ 1 -1 ]
  2092.  
  2093. the `-' is treated as a unary operator and the result is the vector [ 1, -1 ]. 
  2094.  
  2095. Given a = 1, the expression 
  2096.  
  2097. [ 1 a' ]
  2098.  
  2099. results in the single quote character `'' being treated as a transpose operator 
  2100. and the result is the vector [ 1, 1 ], but the expression 
  2101.  
  2102. [ 1 a ' ]
  2103.  
  2104. produces the error message 
  2105.  
  2106. error: unterminated string constant
  2107.  
  2108. because to not do so would make it impossible to correctly parse the valid 
  2109. expression 
  2110.  
  2111. [ a 'foo' ]
  2112.  
  2113. For clarity, it is probably best to always use commas and semicolons to 
  2114. separate matrix elements and rows.  It is possible to enforce this style by 
  2115. setting the built-in variable whitespace_in_literal_matrix to "ignore". 
  2116.  
  2117. Built-in Variable: whitespace_in_literal_matrix 
  2118. This variable allows some control over how Octave decides to convert spaces to 
  2119. commas and semicolons in matrix expressions like [m (1)] or 
  2120.  
  2121. [ 1, 2,
  2122.   3, 4 ]
  2123.  
  2124. If the value of whitespace_in_literal_matrix is "ignore", Octave will never 
  2125. insert a comma or a semicolon in a literal matrix list.  For example, the 
  2126. expression [1 2] will result in an error instead of being treated the same as 
  2127. [1, 2], and the expression 
  2128.  
  2129. [ 1, 2,
  2130.   3, 4 ]
  2131.  
  2132. will result in the vector [ 1, 2, 3, 4 ] instead of a matrix. 
  2133.  
  2134. If the value of whitespace_in_literal_matrix is "traditional", Octave will 
  2135. convert spaces to a comma between identifiers and `('.  For example, given the 
  2136. matrix 
  2137.  
  2138. m = [3 2]
  2139.  
  2140. the expression 
  2141.  
  2142. [m (1)]
  2143.  
  2144. will be parsed as 
  2145.  
  2146. [m, (1)]
  2147.  
  2148. and will result in 
  2149.  
  2150. [3 2 1]
  2151.  
  2152. and the expression 
  2153.  
  2154. [ 1, 2,
  2155.   3, 4 ]
  2156.  
  2157. will result in a matrix because the newline character is converted to a 
  2158. semicolon (row separator) even though there is a comma at the end of the first 
  2159. line (trailing commas or semicolons are ignored).  This is apparently how 
  2160. Matlab behaves. 
  2161.  
  2162. Any other value for whitespace_in_literal_matrix results in behavior that is 
  2163. the same as traditional, except that Octave does not convert spaces to a comma 
  2164. between identifiers and `('.  For example, the expression 
  2165.  
  2166. [m (1)]
  2167.  
  2168. will produce `3'.  This is the way Octave has always behaved. 
  2169.  
  2170. When you type a matrix or the name of a variable whose value is a matrix, 
  2171. Octave responds by printing the matrix in with neatly aligned rows and columns. 
  2172. If the rows of the matrix are too large to fit on the screen, Octave splits the 
  2173. matrix and displays a header before each section to indicate which columns are 
  2174. being displayed.  You can use the following variables to control the format of 
  2175. the output. 
  2176.  
  2177. Built-in Variable: output_max_field_width 
  2178. This variable specifies the maximum width of a numeric output field. The 
  2179. default value is 10. 
  2180.  
  2181. Built-in Variable: output_precision 
  2182. This variable specifies the minimum number of significant figures to display 
  2183. for numeric output.  The default value is 5. 
  2184.  
  2185. It is possible to achieve a wide range of output styles by using different 
  2186. values of output_precision and output_max_field_width.  Reasonable combinations 
  2187. can be set using the format function.  See Basic Input and Output. 
  2188.  
  2189. Built-in Variable: split_long_rows 
  2190. For large matrices, Octave may not be able to display all the columns of a 
  2191. given row on one line of your screen.  This can result in missing information 
  2192. or output that is nearly impossible to decipher, depending on whether your 
  2193. terminal truncates or wraps long lines. 
  2194.  
  2195. If the value of split_long_rows is nonzero, Octave will display the matrix in a 
  2196. series of smaller pieces, each of which can fit within the limits of your 
  2197. terminal width.  Each set of rows is labeled so that you can easily see which 
  2198. columns are currently being displayed. For example: 
  2199.  
  2200. octave:13> rand (2,10)
  2201. ans =
  2202.  
  2203.  Columns 1 through 6:
  2204.  
  2205.   0.75883  0.93290  0.40064  0.43818  0.94958  0.16467
  2206.   0.75697  0.51942  0.40031  0.61784  0.92309  0.40201
  2207.  
  2208.  Columns 7 through 10:
  2209.  
  2210.   0.90174  0.11854  0.72313  0.73326
  2211.   0.44672  0.94303  0.56564  0.82150
  2212.  
  2213. The default value of split_long_rows is nonzero. 
  2214.  
  2215. Octave automatically switches to scientific notation when values become very 
  2216. large or very small.  This guarantees that you will see several significant 
  2217. figures for every value in a matrix.  If you would prefer to see all values in 
  2218. a matrix printed in a fixed point format, you can set the built-in variable 
  2219. fixed_point_format to a nonzero value.  But doing so is not recommended, 
  2220. because it can produce output that can easily be misinterpreted. 
  2221.  
  2222. Built-in Variable: fixed_point_format 
  2223. If the value of this variable is nonzero, Octave will scale all values in a 
  2224. matrix so that the largest may be written with one leading digit. The scaling 
  2225. factor is printed on the first line of output.  For example, 
  2226.  
  2227. octave:1> logspace (1, 7, 5)'
  2228. ans =
  2229.  
  2230.   1.0e+07  *
  2231.  
  2232.   0.00000
  2233.   0.00003
  2234.   0.00100
  2235.   0.03162
  2236.   1.00000
  2237.  
  2238. Notice that first value appears to be zero when it is actually 1.  For this 
  2239. reason, you should be careful when setting fixed_point_format to a nonzero 
  2240. value. 
  2241.  
  2242. The default value of fixed_point_format is 0. 
  2243.  
  2244.  Empty Matrices 
  2245.  
  2246.  
  2247. ΓòÉΓòÉΓòÉ 7.1.1. Empty Matrices ΓòÉΓòÉΓòÉ
  2248.  
  2249. A matrix may have one or both dimensions zero, and operations on empty matrices 
  2250. are handled as described by Carl de Boor in An Empty Exercise, SIGNUM, Volume 
  2251. 25, pages 2--6, 1990 and C. N. Nett and W. M. Haddad, in A System-Theoretic 
  2252. Appropriate Realization of the Empty Matrix Concept, IEEE Transactions on 
  2253. Automatic Control, Volume 38, Number 5, May 1993. Briefly, given a scalar s, an 
  2254. m by n matrix M(mxn), and an m by n empty matrix [](mxn) (with either one or 
  2255. both dimensions equal to zero), the following are true: 
  2256.  
  2257. s * [](mxn) = [](mxn) * s = [](mxn)
  2258.  
  2259.     [](mxn) + [](mxn) = [](mxn)
  2260.  
  2261.     [](0xm) *  M(mxn) = [](0xn)
  2262.  
  2263.      M(mxn) * [](nx0) = [](mx0)
  2264.  
  2265.     [](mx0) * [](0xn) =  0(mxn)
  2266.  
  2267. By default, dimensions of the empty matrix are printed along with the empty 
  2268. matrix symbol, `[]'.  The built-in variable print_empty_dimensions controls 
  2269. this behavior. 
  2270.  
  2271. Built-in Variable: print_empty_dimensions 
  2272. If the value of print_empty_dimensions is nonzero, the dimensions of empty 
  2273. matrices are printed along with the empty matrix symbol, `[]'.  For example, 
  2274. the expression 
  2275.  
  2276. zeros (3, 0)
  2277.  
  2278. will print 
  2279.  
  2280. ans = [](3x0)
  2281.  
  2282. Empty matrices may also be used in assignment statements as a convenient way to 
  2283. delete rows or columns of matrices. See Assignment Expressions. 
  2284.  
  2285. Octave will normally issue a warning if it finds an empty matrix in the list of 
  2286. elements that make up another matrix.  You can use the variable 
  2287. empty_list_elements_ok to suppress the warning or to treat it as an error. 
  2288.  
  2289. Built-in Variable: empty_list_elements_ok 
  2290. This variable controls whether Octave ignores empty matrices in a matrix list. 
  2291.  
  2292. For example, if the value of empty_list_elements_ok is nonzero, Octave will 
  2293. ignore the empty matrices in the expression 
  2294.  
  2295. a = [1, [], 3, [], 5]
  2296.  
  2297. and the variable a will be assigned the value [ 1, 3, 5 ]. 
  2298.  
  2299. The default value is "warn". 
  2300.  
  2301. When Octave parses a matrix expression, it examines the elements of the list to 
  2302. determine whether they are all constants.  If they are, it replaces the list 
  2303. with a single matrix constant. 
  2304.  
  2305. Built-in Variable: propagate_empty_matrices 
  2306. If the value of propagate_empty_matrices is nonzero, functions like inverse and 
  2307. svd will return an empty matrix if they are given one as an argument.  The 
  2308. default value is 1. 
  2309.  
  2310.  
  2311. ΓòÉΓòÉΓòÉ 7.2. Ranges ΓòÉΓòÉΓòÉ
  2312.  
  2313. A range is a convenient way to write a row vector with evenly spaced elements. 
  2314. A range expression is defined by the value of the first element in the range, 
  2315. an optional value for the increment between elements, and a maximum value which 
  2316. the elements of the range will not exceed.  The base, increment, and limit are 
  2317. separated by colons (the `:' character) and may contain any arithmetic 
  2318. expressions and function calls.  If the increment is omitted, it is assumed to 
  2319. be 1. For example, the range 
  2320.  
  2321. 1 : 5
  2322.  
  2323. defines the set of values `[ 1, 2, 3, 4, 5 ]', and the range 
  2324.  
  2325. 1 : 3 : 5
  2326.  
  2327. defines the set of values `[ 1, 4 ]'. 
  2328.  
  2329. Although a range constant specifies a row vector, Octave does not convert range 
  2330. constants to vectors unless it is necessary to do so. This allows you to write 
  2331. a constant like `1 : 10000' without using 80,000 bytes of storage on a typical 
  2332. 32-bit workstation. 
  2333.  
  2334. Note that the upper (or lower, if the increment is negative) bound on the range 
  2335. is not always included in the set of values, and that ranges defined by 
  2336. floating point values can produce surprising results because Octave uses 
  2337. floating point arithmetic to compute the values in the range.  If it is 
  2338. important to include the endpoints of a range and the number of elements is 
  2339. known, you should use the linspace function instead (see Special Utility 
  2340. Matrices). 
  2341.  
  2342. When Octave parses a range expression, it examines the elements of the 
  2343. expression to determine whether they are all constants.  If they are, it 
  2344. replaces the range expression with a single range constant. 
  2345.  
  2346.  
  2347. ΓòÉΓòÉΓòÉ 7.3. Predicates for Numeric Objects ΓòÉΓòÉΓòÉ
  2348.  
  2349. Function File:  is_matrix (a) 
  2350. Return 1 if a is a matrix.  Otherwise, return 0. 
  2351.  
  2352. Function File:  is_vector (a) 
  2353. Return 1 if a is a vector.  Otherwise, return 0. 
  2354.  
  2355. Function File:  is_scalar (a) 
  2356. Return 1 if a is a scalar.  Otherwise, return 0. 
  2357.  
  2358. Function File:  is_square (x) 
  2359. If x is a square matrix, then return the dimension of x. Otherwise, return 0. 
  2360.  
  2361. Function File:  is_symmetric (x, tol) 
  2362. If x is symmetric within the tolerance specified by tol, then return the 
  2363. dimension of x.  Otherwise, return 0.  If tol is omitted, use a tolerance equal 
  2364. to the machine precision. 
  2365.  
  2366.  
  2367. ΓòÉΓòÉΓòÉ 8. Strings ΓòÉΓòÉΓòÉ
  2368.  
  2369. A string constant consists of a sequence of characters enclosed in either 
  2370. double-quote or single-quote marks.  For example, both of the following 
  2371. expressions 
  2372.  
  2373. "parrot"
  2374. 'parrot'
  2375.  
  2376. represent the string whose contents are `parrot'.  Strings in Octave can be of 
  2377. any length. 
  2378.  
  2379. Since the single-quote mark is also used for the transpose operator (see 
  2380. Arithmetic Ops) but double-quote marks have no other purpose in Octave, it is 
  2381. best to use double-quote marks to denote strings. 
  2382.  
  2383. Some characters cannot be included literally in a string constant.  You 
  2384. represent them instead with escape sequences, which are character sequences 
  2385. beginning with a backslash (`\'). 
  2386.  
  2387. One use of an escape sequence is to include a double-quote (single-quote) 
  2388. character in a string constant that has been defined using double-quote 
  2389. (single-quote) marks.  Since a plain double-quote would end the string, you 
  2390. must use `\"' to represent a single double-quote character as a part of the 
  2391. string.  The backslash character itself is another character that cannot be 
  2392. included normally.  You must write `\\' to put one backslash in the string. 
  2393. Thus, the string whose contents are the two characters `"\' may be written 
  2394. "\"\\" or '"\\'.  Similarly, the string whose contents are the two characters 
  2395. `'\' may be written '\'\\' or "'\\". 
  2396.  
  2397. Another use of backslash is to represent unprintable characters such as 
  2398. newline.  While there is nothing to stop you from writing most of these 
  2399. characters directly in a string constant, they may look ugly. 
  2400.  
  2401. Here is a table of all the escape sequences used in Octave.  They are the same 
  2402. as those used in the C programming language. 
  2403.  
  2404.  \\ 
  2405.            Represents a literal backslash, `\'. 
  2406.  
  2407.  \" 
  2408.            Represents a literal double-quote character, `"'. 
  2409.  
  2410.  \' 
  2411.            Represents a literal single-quote character, `''. 
  2412.  
  2413.  \a 
  2414.            Represents the ``alert'' character, control-g, ASCII code 7. 
  2415.  
  2416.  \b 
  2417.            Represents a backspace, control-h, ASCII code 8. 
  2418.  
  2419.  \f 
  2420.            Represents a formfeed, control-l, ASCII code 12. 
  2421.  
  2422.  \n 
  2423.            Represents a newline, control-j, ASCII code 10. 
  2424.  
  2425.  \r 
  2426.            Represents a carriage return, control-m, ASCII code 13. 
  2427.  
  2428.  \t 
  2429.            Represents a horizontal tab, control-i, ASCII code 9. 
  2430.  
  2431.  \v 
  2432.            Represents a vertical tab, control-k, ASCII code 11. 
  2433.  
  2434.  Strings may be concatenated using the notation for defining matrices. For 
  2435.  example, the expression 
  2436.  
  2437.   [ "foo" , "bar" , "baz" ]
  2438.  
  2439.  produces the string whose contents are `foobarbaz'. See Numeric Data Types for 
  2440.  more information about creating matrices. 
  2441.  
  2442.  Creating Strings 
  2443.  Searching and Replacing 
  2444.  String Conversions 
  2445.  Character Class Functions 
  2446.  
  2447.  
  2448. ΓòÉΓòÉΓòÉ 8.1. Creating Strings ΓòÉΓòÉΓòÉ
  2449.  
  2450. Function File:  blanks (n) 
  2451. Return a string of n blanks. 
  2452.  
  2453. Function File:  int2str (n) 
  2454.  
  2455. Function File:  num2str (x) 
  2456. Convert a number to a string.  These functions are not very flexible, but are 
  2457. provided for compatibility with Matlab.  For better control over the results, 
  2458. use sprintf (see Formatted Output). 
  2459.  
  2460. Built-in Function:  setstr (x) 
  2461. Convert a matrix to a string.  Each element of the matrix is converted to the 
  2462. corresponding ASCII character.  For example, 
  2463.  
  2464. setstr ([97, 98, 99])
  2465.      => "abc"
  2466.  
  2467. Function File:  strcat (s1, s2, ...) 
  2468. Return a string containing all the arguments concatenated.  For example, 
  2469.  
  2470. s = [ "ab"; "cde" ];
  2471. strcat (s, s, s)
  2472.      => "ab ab ab "
  2473.         "cdecdecde"
  2474.  
  2475. Built-in Variable: string_fill_char 
  2476. The value of this variable is used to pad all strings in a string matrix to the 
  2477. same length.  It should be a single character.  The default value is " " (a 
  2478. single space).  For example, 
  2479.  
  2480. string_fill_char = "X";
  2481. [ "these"; "are"; "strings" ]
  2482.      => "theseXX"
  2483.         "areXXXX"
  2484.         "strings"
  2485.  
  2486. Function File:  str2mat (s_1, ..., s_n) 
  2487. Return a matrix containing the strings s_1, ..., s_n as its rows.  Each string 
  2488. is padded with blanks in order to form a valid matrix. 
  2489.  
  2490. *Note:* This function is modelled after Matlab.  In Octave, you can create a 
  2491. matrix of strings by [s_1; ...; s_n] even if the strings are not all the same 
  2492. length. 
  2493.  
  2494. Built-in Function:  isstr (a) 
  2495. Return 1 if a is a string.  Otherwise, return 0. 
  2496.  
  2497.  
  2498. ΓòÉΓòÉΓòÉ 8.2. Searching and Replacing ΓòÉΓòÉΓòÉ
  2499.  
  2500. Function File:  deblank (s) 
  2501. Removes the trailing blanks from the string s. 
  2502.  
  2503. Function File:  findstr (s, t, overlap) 
  2504. Return the vector of all positions in the longer of the two strings s and t 
  2505. where an occurrence of the shorter of the two starts. If the optional argument 
  2506. overlap is nonzero, the returned vector can include overlapping positions (this 
  2507. is the default).  For example, 
  2508.  
  2509. findstr ("ababab", "a")
  2510.      => [ 1, 3, 5 ]
  2511. findstr ("abababa", "aba", 0)
  2512.      => [ 1, 5 ]
  2513.  
  2514. Function File:  index (s, t) 
  2515. Return the position of the first occurrence of the string t in the string s, or 
  2516. 0 if no occurrence is found.  For example, 
  2517.  
  2518. index ("Teststring", "t")
  2519.      => 4
  2520.  
  2521. *Note:*  This function does not work for arrays of strings. 
  2522.  
  2523. Function File:  rindex (s, t) 
  2524. Return the position of the last occurrence of the string t in the string s, or 
  2525. 0 if no occurrence is found.  For example, 
  2526.  
  2527. rindex ("Teststring", "t")
  2528.      => 6
  2529.  
  2530. *Note:*  This function does not work for arrays of strings. 
  2531.  
  2532. Function File:  split (s, t) 
  2533. Divides the string s into pieces separated by t, returning the result in a 
  2534. string array (padded with blanks to form a valid matrix).  For example, 
  2535.  
  2536. split ("Test string", "t")
  2537.      => "Tes "
  2538.         " s  "
  2539.         "ring"
  2540.  
  2541. Function File:  strcmp (s1, s2) 
  2542. Compares two strings, returning 1 if they are the same, and 0 otherwise. 
  2543.  
  2544. *Note:*  For compatibility with Matlab, Octave's strcmp function returns 1 if 
  2545. the strings are equal, and 0 otherwise.  This is just the opposite of the 
  2546. corresponding C library function. 
  2547.  
  2548. Function File:  strrep (s, x, y) 
  2549. Replaces all occurrences of the substring x of the string s with the string y. 
  2550. For example, 
  2551.  
  2552. strrep ("This is a test string", "is", "&%$")
  2553.      => "Th&%$ &%$ a test string"
  2554.  
  2555. Function File:  substr (s, beg, len) 
  2556. Return the substring of s which starts at character number beg and is len 
  2557. characters long.  For example, 
  2558.  
  2559. substr ("This is a test string", 6, 9)
  2560.      => "is a test"
  2561.  
  2562. *Note:* This function is patterned after AWK.  You can get the same result by s 
  2563. (beg : (beg + len - 1)). 
  2564.  
  2565.  
  2566. ΓòÉΓòÉΓòÉ 8.3. String Conversions ΓòÉΓòÉΓòÉ
  2567.  
  2568. Function File:  bin2dec (s) 
  2569. Return a decimal number corresponding to the binary number represented as a 
  2570. string of zeros and ones.  For example, 
  2571.  
  2572. bin2dec ("1110")
  2573.      => 14
  2574.  
  2575. Function File:  dec2bin (n) 
  2576. Return a binary number corresponding the nonnegative decimal number n, as a 
  2577. string of ones and zeros.  For example, 
  2578.  
  2579. dec2bin (14)
  2580.      => "1110"
  2581.  
  2582. Function File:  dec2hex (n) 
  2583. Return the hexadecimal number corresponding to the nonnegative decimal number 
  2584. n, as a string.  For example, 
  2585.  
  2586. dec2hex (2748)
  2587.      => "abc"
  2588.  
  2589. Function File:  hex2dec (s) 
  2590. Return the decimal number corresponding to the hexadecimal number stored in the 
  2591. string s.  For example, 
  2592.  
  2593. hex2dec ("12B")
  2594.      => 299
  2595. hex2dec ("12b")
  2596.      => 299
  2597.  
  2598. Function File:  str2num (s) 
  2599. Convert the string s to a number. 
  2600.  
  2601. Function File:  toascii (s) 
  2602. Return ASCII representation of s in a matrix.  For example, 
  2603.  
  2604. toascii ("ASCII")
  2605.      => [ 65, 83, 67, 73, 73 ]
  2606.  
  2607. Function File:  tolower (s) 
  2608. Return a copy of the string s, with each upper-case character replaced by the 
  2609. corresponding lower-case one; nonalphabetic characters are left unchanged.  For 
  2610. example, 
  2611.  
  2612. tolower ("MiXeD cAsE 123")
  2613.      => "mixed case 123"
  2614.  
  2615. Function File:  toupper (s) 
  2616. Return a copy of the string s, with each  lower-case character replaced by the 
  2617. corresponding upper-case one; nonalphabetic characters are left unchanged.  For 
  2618. example, 
  2619.  
  2620. toupper ("MiXeD cAsE 123")
  2621.      => "MIXED CASE 123"
  2622.  
  2623. Built-in Function:  undo_string_escapes (s) 
  2624. Converts special characters in strings back to their escaped forms.  For 
  2625. example, the expression 
  2626.  
  2627. bell = "\a";
  2628.  
  2629. assigns the value of the alert character (control-g, ASCII code 7) to the 
  2630. string variable bell.  If this string is printed, the system will ring the 
  2631. terminal bell (if it is possible).  This is normally the desired outcome. 
  2632. However, sometimes it is useful to be able to print the original representation 
  2633. of the string, with the special characters replaced by their escape sequences. 
  2634. For example, 
  2635.  
  2636. octave:13> undo_string_escapes (bell)
  2637. ans = \a
  2638.  
  2639. replaces the unprintable alert character with its printable representation. 
  2640.  
  2641. Built-in Variable: implicit_num_to_str_ok 
  2642. If the value of implicit_num_to_str_ok is nonzero, implicit conversions of 
  2643. numbers to their ASCII character equivalents are allowed when strings are 
  2644. constructed using a mixture of strings and numbers in matrix notation. 
  2645. Otherwise, an error message is printed and control is returned to the top 
  2646. level. The default value is 0.  For example, 
  2647.  
  2648. [ "f", 111, 111 ]
  2649.      => "foo"
  2650.  
  2651. Built-in Variable: implicit_str_to_num_ok 
  2652. If the value of implicit_str_to_num_ok is nonzero, implicit conversions of 
  2653. strings to their numeric ASCII equivalents are allowed. Otherwise, an error 
  2654. message is printed and control is returned to the top level.  The default value 
  2655. is 0. 
  2656.  
  2657.  
  2658. ΓòÉΓòÉΓòÉ 8.4. Character Class Functions ΓòÉΓòÉΓòÉ
  2659.  
  2660. Octave also provides the following character class test functions patterned 
  2661. after the functions in the standard C library.  They all operate on string 
  2662. arrays and return matrices of zeros and ones. Elements that are nonzero 
  2663. indicate that the condition was true for the corresponding character in the 
  2664. string array.  For example, 
  2665.  
  2666. isalpha ("!Q@WERT^Y&")
  2667.      => [ 0, 1, 0, 1, 1, 1, 1, 0, 1, 0 ]
  2668.  
  2669. Mapping Function:  isalnum (s) 
  2670. Return 1 for characters that are letters or digits (isalpha (a) or isdigit () 
  2671. is true). 
  2672.  
  2673. Mapping Function:  isalpha (s) 
  2674. Return true for characters that are letters (isupper (a) or islower () is 
  2675. true). 
  2676.  
  2677. Mapping Function:  isascii (s) 
  2678. Return 1 for characters that are ASCII (in the range 0 to 127 decimal). 
  2679.  
  2680. Mapping Function:  iscntrl (s) 
  2681. Return 1 for control characters. 
  2682.  
  2683. Mapping Function:  isdigit (s) 
  2684. Return 1 for characters that are decimal digits. 
  2685.  
  2686. Mapping Function:  isgraph (s) 
  2687. Return 1 for printable characters (but not the space character). 
  2688.  
  2689. Mapping Function:  islower (s) 
  2690. Return 1 for characters that are lower case letters. 
  2691.  
  2692. Mapping Function:  isprint (s) 
  2693. Return 1 for printable characters (including the space character). 
  2694.  
  2695. Mapping Function:  ispunct (s) 
  2696. Return 1 for punctuation characters. 
  2697.  
  2698. Mapping Function:  isspace (s) 
  2699. Return 1 for whitespace characters (space, formfeed, newline, carriage return, 
  2700. tab, and vertical tab). 
  2701.  
  2702. Mapping Function:  isupper (s) 
  2703. Return 1 for upper case letters. 
  2704.  
  2705. Mapping Function:  isxdigit (s) 
  2706. Return 1 for characters that are hexadecimal digits. 
  2707.  
  2708.  
  2709. ΓòÉΓòÉΓòÉ 9. Data Structures ΓòÉΓòÉΓòÉ
  2710.  
  2711. Octave includes support for organizing data in structures.  The current 
  2712. implementation uses an associative array with indices limited to strings, but 
  2713. the syntax is more like C-style structures.  Here are some examples of using 
  2714. data structures in Octave. 
  2715.  
  2716. Elements of structures can be of any value type.  For example, the three 
  2717. expressions 
  2718.  
  2719. x.a = 1
  2720. x.b = [1, 2; 3, 4]
  2721. x.c = "string"
  2722.  
  2723. create a structure with three elements.  To print the value of the structure, 
  2724. you can type its name, just as for any other variable: 
  2725.  
  2726. octave:2> x
  2727. x =
  2728. {
  2729.   a = 1
  2730.   b =
  2731.  
  2732.     1  2
  2733.     3  4
  2734.  
  2735.   c = string
  2736. }
  2737.  
  2738. Note that Octave may print the elements in any order. 
  2739.  
  2740. Structures may be copied. 
  2741.  
  2742. octave:1> y = x
  2743. y =
  2744. {
  2745.   a = 1
  2746.   b =
  2747.  
  2748.     1  2
  2749.     3  4
  2750.  
  2751.   c = string
  2752. }
  2753.  
  2754. Since structures are themselves values, structure elements may reference other 
  2755. structures.  The following statements change the value of the element b of the 
  2756. structure x to be a data structure containing the single element d, which has a 
  2757. value of 3. 
  2758.  
  2759. octave:1> x.b.d = 3
  2760. x.b.d = 3
  2761. octave:2> x.b
  2762. ans =
  2763. {
  2764.   d = 3
  2765. }
  2766. octave:3> x
  2767. x =
  2768. {
  2769.   a = 1
  2770.   b =
  2771.   {
  2772.     d = 3
  2773.   }
  2774.  
  2775.   c = string
  2776. }
  2777.  
  2778. Note that when Octave prints the value of a structure that contains other 
  2779. structures, only a few levels are displayed.  For example, 
  2780.  
  2781. octave:1> a.b.c.d.e = 1;
  2782. octave:2> a
  2783. a =
  2784. {
  2785.   b =
  2786.   {
  2787.     c = <structure>
  2788.   }
  2789. }
  2790.  
  2791. This prevents long and confusing output from large deeply nested structures. 
  2792.  
  2793. Built-in Variable: struct_levels_to_print 
  2794. You can tell Octave how many structure levels to display by setting the 
  2795. built-in variable struct_levels_to_print.  The default value is 2. 
  2796.  
  2797. Functions can return structures.  For example, the following function separates 
  2798. the real and complex parts of a matrix and stores them in two elements of the 
  2799. same structure variable. 
  2800.  
  2801. octave:1> function y = f (x)
  2802. > y.re = real (x);
  2803. > y.im = imag (x);
  2804. > endfunction
  2805.  
  2806. When called with a complex-valued argument, f returns the data structure 
  2807. containing the real and imaginary parts of the original function argument. 
  2808.  
  2809. octave:2> f (rand (2) + rand (2) * I);
  2810. ans =
  2811. {
  2812.   im =
  2813.  
  2814.     0.26475  0.14828
  2815.     0.18436  0.83669
  2816.  
  2817.   re =
  2818.  
  2819.     0.040239  0.242160
  2820.     0.238081  0.402523
  2821. }
  2822.  
  2823. Function return lists can include structure elements, and they may be indexed 
  2824. like any other variable.  For example, 
  2825.  
  2826. octave:1> [ x.u, x.s(2:3,2:3), x.v ] = svd ([1, 2; 3, 4])
  2827. x.u =
  2828.  
  2829.   -0.40455  -0.91451
  2830.   -0.91451   0.40455
  2831.  
  2832. x.s =
  2833.  
  2834.   0.00000  0.00000  0.00000
  2835.   0.00000  5.46499  0.00000
  2836.   0.00000  0.00000  0.36597
  2837.  
  2838. x.v =
  2839.  
  2840.   -0.57605   0.81742
  2841.   -0.81742  -0.57605
  2842.  
  2843. It is also possible to cycle through all the elements of a structure in a loop, 
  2844. using a special form of the for statement (see The for Statement) 
  2845.  
  2846. The following functions are available to give you information about structures. 
  2847.  
  2848. Built-in Function:  is_struct (expr) 
  2849. Return 1 if the value of the expression expr is a structure. 
  2850.  
  2851. Built-in Function:  struct_contains (expr, name) 
  2852. Return 1 if the expression expr is a structure and it includes an element named 
  2853. name.  The first argument must be a structure and the second must be a string. 
  2854.  
  2855. Built-in Function:  struct_elements (struct) 
  2856. Return a list of strings naming the elements of the structure struct.  It is an 
  2857. error to call struct_elements with an argument that is not a structure. 
  2858.  
  2859.  
  2860. ΓòÉΓòÉΓòÉ 10. Variables ΓòÉΓòÉΓòÉ
  2861.  
  2862. Variables let you give names to values and refer to them later.  You have 
  2863. already seen variables in many of the examples.  The name of a variable must be 
  2864. a sequence of letters, digits and underscores, but it may not begin with a 
  2865. digit.  Octave does not enforce a limit on the length of variable names, but it 
  2866. is seldom useful to have variables with names longer than about 30 characters. 
  2867. The following are all valid variable names 
  2868.  
  2869. x
  2870. x15
  2871. __foo_bar_baz__
  2872. fucnrdthsucngtagdjb
  2873.  
  2874. However, names like __foo_bar_baz__ that begin and end with two underscores are 
  2875. understood to be reserved for internal use by Octave. You should not use them 
  2876. in code you write, except to access Octave's documented internal variables and 
  2877. built-in symbolic constants. 
  2878.  
  2879. Case is significant in variable names.  The symbols a and A are distinct 
  2880. variables. 
  2881.  
  2882. A variable name is a valid expression by itself.  It represents the variable's 
  2883. current value.  Variables are given new values with assignment operators and 
  2884. increment operators. See Assignment Expressions. 
  2885.  
  2886. A number of variables have special built-in meanings.  For example, ans holds 
  2887. the current working directory, and pi names the ratio of the circumference of a 
  2888. circle to its diameter. See Summary of Built-in Variables, for a list of all 
  2889. the predefined variables.  Some of these built-in symbols are constants and may 
  2890. not be changed.  Others can be used and assigned just like all other variables, 
  2891. but their values are also used or changed automatically by Octave. 
  2892.  
  2893. Variables in Octave do not have fixed types, so it is possible to first store a 
  2894. numeric value in a variable and then to later use the same name to hold a 
  2895. string value in the same program.  Variables may not be used before they have 
  2896. been given a value.  Doing so results in an error. 
  2897.  
  2898.  Global Variables 
  2899.  Status of Variables 
  2900.  Summary of Built-in Variables 
  2901.  Defaults from the Environment 
  2902.  
  2903.  
  2904. ΓòÉΓòÉΓòÉ 10.1. Global Variables ΓòÉΓòÉΓòÉ
  2905.  
  2906. A variable that has been declared global may be accessed from within a function 
  2907. body without having to pass it as a formal parameter. 
  2908.  
  2909. A variable may be declared global using a global declaration statement.  The 
  2910. following statements are all global declarations. 
  2911.  
  2912. global a
  2913. global b = 2
  2914. global c = 3, d, e = 5
  2915.  
  2916. It is necessary declare a variable as global within a function body in order to 
  2917. access it.  For example, 
  2918.  
  2919. global x
  2920. function f ()
  2921.   x = 1;
  2922. endfunction
  2923. f ()
  2924.  
  2925. does not set the value of the global variable x to 1.  In order to change the 
  2926. value of the global variable x, you must also declare it to be global within 
  2927. the function body, like this 
  2928.  
  2929. function f ()
  2930.   global x;
  2931.   x = 1;
  2932. endfunction
  2933.  
  2934. Passing a global variable in a function parameter list will make a local copy 
  2935. and not modify the global value.  For example, given the function 
  2936.  
  2937. function f (x)
  2938.   x = 0
  2939. endfunction
  2940.  
  2941. and the definition of x as a global variable at the top level, 
  2942.  
  2943. global x = 13
  2944.  
  2945. the expression 
  2946.  
  2947. f (x)
  2948.  
  2949. will display the value of x from inside the function as 0, but the value of x 
  2950. at the top level remains unchanged, because the function works with a copy of 
  2951. its argument. 
  2952.  
  2953. Built-in Variable: warn_comma_in_global_decl 
  2954. If the value of warn_comma_in_global_decl is nonzero, a warning is issued for 
  2955. statements like 
  2956.  
  2957. global a = 1, b
  2958.  
  2959. which makes the variables a and b global and assigns the value 1 to the 
  2960. variable a, because in this context, the comma is not interpreted as a 
  2961. statement separator. 
  2962.  
  2963. The default value of warn_comma_in_global_decl is nonzero. 
  2964.  
  2965. default_global_variable_value if: initialize_global_variables is nonzero, the 
  2966. value of 
  2967. default_glbaol_variable_value is used as the initial value of global variables 
  2968. that are not explicitly initialized.  for example, 
  2969.  
  2970. initialize_global_variables = 1;
  2971. default_global_variable_value = 13;
  2972. global foo;
  2973. foo
  2974.      => 13
  2975.  
  2976. the variable default_global_variable_value is initially undefined. 
  2977.  
  2978. Built-in Function:  is_global (name) 
  2979. Return 1 if name is globally visible.  Otherwise, return 0.  For example, 
  2980.  
  2981. global x
  2982. is_global ("x")
  2983.      => 1
  2984.  
  2985.  
  2986. ΓòÉΓòÉΓòÉ 10.2. Status of Variables ΓòÉΓòÉΓòÉ
  2987.  
  2988. Command: clear options pattern ... 
  2989. Delete the names matching the given patterns from the symbol table.  The 
  2990. pattern may contain the following special characters: 
  2991.  
  2992.  ? 
  2993.            Match any single character. 
  2994.  
  2995.  * 
  2996.            Match zero or more characters. 
  2997.  
  2998.  [ list ] 
  2999.            Match the list of characters specified by list.  If the first 
  3000.            character is ! or ^, match all characters except those specified by 
  3001.            list.  For example, the pattern `[a-zA-Z]' will match all lower and 
  3002.            upper case alphabetic characters. 
  3003.  
  3004.  For example, the command 
  3005.  
  3006.   clear foo b*r
  3007.  
  3008.  clears the name foo and all names that begin with the letter b and end with 
  3009.  the letter r. 
  3010.  
  3011.  If clear is called without any arguments, all user-defined variables (local 
  3012.  and global) are cleared from the symbol table.  If clear is called with at 
  3013.  least one argument, only the visible names matching the arguments are cleared. 
  3014.  For example, suppose you have defined a function foo, and then hidden it by 
  3015.  performing the assignment foo = 2.  Executing the command clear foo once will 
  3016.  clear the variable definition and restore the definition of foo as a function. 
  3017.  Executing clear foo a second time will clear the function definition. 
  3018.  
  3019.  This command may not be used within a function body. 
  3020.  
  3021.  Command: who options pattern ... 
  3022.  
  3023.  Command: whos options pattern ... 
  3024.  List currently defined symbols matching the given patterns.  The following are 
  3025.  valid options.  They may be shortened to one character but may not be 
  3026.  combined. 
  3027.  
  3028.  -all 
  3029.            List all currently defined symbols. 
  3030.  
  3031.  -builtins 
  3032.            List built-in variables and functions.  This includes all currently 
  3033.            compiled function files, but does not include all function files 
  3034.            that are in the LOADPATH. 
  3035.  
  3036.  -functions 
  3037.            List user-defined functions. 
  3038.  
  3039.  -long 
  3040.            Print a long listing including the type and dimensions of any 
  3041.            symbols. The symbols in the first column of output indicate whether 
  3042.            it is possible to redefine the symbol, and whether it is possible 
  3043.            for it to be cleared. 
  3044.  
  3045.  -variables 
  3046.            List user-defined variables. 
  3047.  
  3048.  Valid patterns are the same as described for the clear command above.  If no 
  3049.  patterns are supplied, all symbols from the given category are listed.  By 
  3050.  default, only user defined functions and variables visible in the local scope 
  3051.  are displayed. 
  3052.  
  3053.  The command whos is equivalent to who -long. 
  3054.  
  3055.  Built-in Function:  exist (name) 
  3056.  Return 1 if the name exists as a variable, 2 if the name (after appending 
  3057.  `.m') is a function file in the path, 3 if the name is a `.oct' file in the 
  3058.  path, or 5 if the name is a built-in function. Otherwise, return 0. 
  3059.  
  3060.  Built-in Function:  document (symbol, text) 
  3061.  Set the documentation string for symbol to text. 
  3062.  
  3063.  Command: type options name ... 
  3064.  Display the definition of each name that refers to a function. 
  3065.  
  3066.  Normally also displays if each name is user-defined or builtin; the -q option 
  3067.  suppresses this behaviour. 
  3068.  
  3069.  Currently, Octave can only display functions that can be compiled cleanly, 
  3070.  because it uses its internal representation of the function to recreate the 
  3071.  program text. 
  3072.  
  3073.  Comments are not displayed because Octave's parser currently discards them as 
  3074.  it converts the text of a function file to its internal representation.  This 
  3075.  problem may be fixed in a future release. 
  3076.  
  3077.  Command: which name ... 
  3078.  Display the type of each name.  If name is defined from a function file, the 
  3079.  full name of the file is also displayed. 
  3080.  
  3081.  
  3082. ΓòÉΓòÉΓòÉ 10.3. Summary of Built-in Variables ΓòÉΓòÉΓòÉ
  3083.  
  3084. Here is a summary of all of Octave's built-in variables along with cross 
  3085. references to additional information and their default values.  In the 
  3086. following table octave-home stands for the root directory where all of Octave 
  3087. is installed (the default is `*', version stands for the Octave version number 
  3088. (for example, 2.1.14) and arch stands for the type of system for which Octave 
  3089. was compiled (for example, i486-pc-os/2). 
  3090.  
  3091.  DEFAULT_LOADPATH 
  3092.            See Function Files. 
  3093.  
  3094.            Default value: ".:octave-home/lib/version". 
  3095.  
  3096.  EDITOR 
  3097.            See Commands For History. 
  3098.  
  3099.            Default value: "emacs". 
  3100.  
  3101.  EXEC_PATH 
  3102.            See Controlling Subprocesses. 
  3103.  
  3104.            Default value: ":$PATH". 
  3105.  
  3106.  INFO_FILE 
  3107.            See Getting Help. 
  3108.  
  3109.            Default value: "octave-home/info/octave.info". 
  3110.  
  3111.  INFO_PROGRAM 
  3112.            See Getting Help. 
  3113.  
  3114.            Default value: "octave-home/libexec/octave/version/exec/arch/info". 
  3115.  
  3116.  LOADPATH 
  3117.            See Function Files. 
  3118.  
  3119.            Default value: ":", which tells Octave to use the directories 
  3120.            specified by the built-in variable DEFAULT_LOADPATH. 
  3121.  
  3122.  OCTAVE_HOME 
  3123.            Default value: "*". 
  3124.  
  3125.  PAGER 
  3126.            See Input and Output. 
  3127.  
  3128.            Default value: "less", or "more". 
  3129.  
  3130.  PS1 
  3131.            See Customizing the Prompt. 
  3132.  
  3133.            Default value: "\s:\#> ". 
  3134.  
  3135.  PS2 
  3136.            See Customizing the Prompt. 
  3137.  
  3138.            Default value: "> ". 
  3139.  
  3140.  PS4 
  3141.            See Customizing the Prompt. 
  3142.  
  3143.            Default value: "+ ". 
  3144.  
  3145.  auto_unload_dot_oct_files 
  3146.            See Dynamically Linked Functions. 
  3147.  
  3148.            Default value: 0. 
  3149.  
  3150.  automatic_replot 
  3151.            See Two-Dimensional Plotting. 
  3152.  
  3153.            Default value: 0. 
  3154.  
  3155.  beep_on_error 
  3156.            See Error Handling. 
  3157.  
  3158.            Default value: 0. 
  3159.  
  3160.  completion_append_char 
  3161.            See Commands For Completion. 
  3162.  
  3163.            Default value: " ". 
  3164.  
  3165.  default_eval_print_flag 
  3166.            See Evaluation. 
  3167.  
  3168.            Default value: 1. 
  3169.  
  3170.  default_return_value 
  3171.            See Multiple Return Values. 
  3172.  
  3173.            Default value: []. 
  3174.  
  3175.  default_save_format 
  3176.            See Simple File I/O. 
  3177.  
  3178.            Default value: "ascii". 
  3179.  
  3180.  do_fortran_indexing 
  3181.            See Index Expressions. 
  3182.  
  3183.            Default value: 0. 
  3184.  
  3185.  crash_dumps_octave_core 
  3186.            See Simple File I/O. 
  3187.  
  3188.            Default value: 1. 
  3189.  
  3190.  define_all_return_values 
  3191.            See Multiple Return Values. 
  3192.  
  3193.            Default value: 0. 
  3194.  
  3195.  empty_list_elements_ok 
  3196.            See Empty Matrices. 
  3197.  
  3198.            Default value: "warn". 
  3199.  
  3200.  fixed_point_format 
  3201.            See Matrices. 
  3202.  
  3203.            Default value: 0. 
  3204.  
  3205.  gnuplot_binary 
  3206.            See Three-Dimensional Plotting. 
  3207.  
  3208.            Default value: "gnuplot". 
  3209.  
  3210.  history_file 
  3211.            See Commands For History. 
  3212.  
  3213.            Default value: "~/.octave_hist". 
  3214.  
  3215.  history_size 
  3216.            See Commands For History. 
  3217.  
  3218.            Default value: 1024. 
  3219.  
  3220.  ignore_function_time_stamp 
  3221.            See Function Files. 
  3222.  
  3223.            Default value: "system". 
  3224.  
  3225.  implicit_num_to_str_ok 
  3226.            See String Conversions. 
  3227.  
  3228.            Default value: 0. 
  3229.  
  3230.  implicit_str_to_num_ok 
  3231.            See String Conversions. 
  3232.  
  3233.            Default value: 0. 
  3234.  
  3235.  max_recursion_depth 
  3236.            See Recursion. 
  3237.  
  3238.            Default value: 256. 
  3239.  
  3240.  ok_to_lose_imaginary_part 
  3241.            See Special Utility Matrices. 
  3242.  
  3243.            Default value: "warn". 
  3244.  
  3245.  output_max_field_width 
  3246.            See Matrices. 
  3247.  
  3248.            Default value: 10. 
  3249.  
  3250.  output_precision 
  3251.            See Matrices. 
  3252.  
  3253.            Default value: 5. 
  3254.  
  3255.  page_screen_output 
  3256.            See Input and Output. 
  3257.  
  3258.            Default value: 1. 
  3259.  
  3260.  prefer_column_vectors 
  3261.            See Index Expressions. 
  3262.  
  3263.            Default value: 1. 
  3264.  
  3265.  print_answer_id_name 
  3266.            See Terminal Output. 
  3267.  
  3268.            Default value: 1. 
  3269.  
  3270.  print_empty_dimensions 
  3271.            See Empty Matrices. 
  3272.  
  3273.            Default value: 1. 
  3274.  
  3275.  resize_on_range_error 
  3276.            See Index Expressions. 
  3277.  
  3278.            Default value: 1. 
  3279.  
  3280.  return_last_computed_value 
  3281.            See Returning From a Function. 
  3282.  
  3283.            Default value: 0. 
  3284.  
  3285.  save_precision 
  3286.            See Simple File I/O. 
  3287.  
  3288.            Default value: 17. 
  3289.  
  3290.  saving_history 
  3291.            See Commands For History. 
  3292.  
  3293.            Default value: 1. 
  3294.  
  3295.  silent_functions 
  3296.            See Defining Functions. 
  3297.  
  3298.            Default value: 0. 
  3299.  
  3300.  split_long_rows 
  3301.            See Matrices. 
  3302.  
  3303.            Default value: 1. 
  3304.  
  3305.  struct_levels_to_print 
  3306.            See Data Structures. 
  3307.  
  3308.            Default value: 2. 
  3309.  
  3310.  suppress_verbose_help_message 
  3311.            See Getting Help. 
  3312.  
  3313.            Default value: 1. 
  3314.  
  3315.  treat_neg_dim_as_zero 
  3316.            See Special Utility Matrices. 
  3317.  
  3318.            Default value: 0. 
  3319.  
  3320.  warn_assign_as_truth_value 
  3321.            See The if Statement. 
  3322.  
  3323.            Default value: 1. 
  3324.  
  3325.  warn_comma_in_global_decl 
  3326.            See Global Variables. 
  3327.  
  3328.            Default value: 1. 
  3329.  
  3330.  warn_divide_by_zero 
  3331.            See Arithmetic Ops. 
  3332.  
  3333.            Default value: 1. 
  3334.  
  3335.  warn_function_name_clash 
  3336.            See Function Files. 
  3337.  
  3338.            Default value: 1. 
  3339.  
  3340.  warn_reload_forces_clear 
  3341.            See Dynamically Linked Functions. 
  3342.  
  3343.            Default value: 1. 
  3344.  
  3345.  warn_variable_switch_label 
  3346.            See The switch Statement. 
  3347.  
  3348.            Default value: 0. 
  3349.  
  3350.  whitespace_in_literal_matrix 
  3351.            See Matrices. 
  3352.  
  3353.            Default value: "". 
  3354.  
  3355.  
  3356. ΓòÉΓòÉΓòÉ 10.4. Defaults from the Environment ΓòÉΓòÉΓòÉ
  3357.  
  3358. Octave uses the values of the following environment variables to set the 
  3359. default values for the corresponding built-in variables.  In addition, the 
  3360. values from the environment may be overridden by command-line arguments.  See 
  3361. Command Line Options. 
  3362.  
  3363.  EDITOR 
  3364.            See Commands For History. 
  3365.  
  3366.            Built-in variable: EDITOR. 
  3367.  
  3368.  OCTAVE_EXEC_PATH 
  3369.            See Controlling Subprocesses. 
  3370.  
  3371.            Built-in variable: EXEC_PATH. Command-line argument: --exec-path. 
  3372.  
  3373.  OCTAVE_PATH 
  3374.            See Function Files. 
  3375.  
  3376.            Built-in variable: LOADPATH. Command-line argument: --path. 
  3377.  
  3378.  OCTAVE_INFO_FILE 
  3379.            See Getting Help. 
  3380.  
  3381.            Built-in variable: INFO_FILE. Command-line argument: --info-file. 
  3382.  
  3383.  OCTAVE_INFO_PROGRAM 
  3384.            See Getting Help. 
  3385.  
  3386.            Built-in variable: INFO_PROGRAM. Command-line argument: 
  3387.            --info-program. 
  3388.  
  3389.  OCTAVE_HISTSIZE 
  3390.            See Commands For History. 
  3391.  
  3392.            Built-in variable: history_size. 
  3393.  
  3394.  OCTAVE_HISTFILE 
  3395.            See Commands For History. 
  3396.  
  3397.            Built-in variable: history_file. 
  3398.  
  3399.  
  3400. ΓòÉΓòÉΓòÉ 11. Expressions ΓòÉΓòÉΓòÉ
  3401.  
  3402. Expressions are the basic building block of statements in Octave.  An 
  3403. expression evaluates to a value, which you can print, test, store in a 
  3404. variable, pass to a function, or assign a new value to a variable with an 
  3405. assignment operator. 
  3406.  
  3407. An expression can serve as a statement on its own.  Most other kinds of 
  3408. statements contain one or more expressions which specify data to be operated 
  3409. on.  As in other languages, expressions in Octave include variables, array 
  3410. references, constants, and function calls, as well as combinations of these 
  3411. with various operators. 
  3412.  
  3413.  Index Expressions 
  3414.  Calling Functions 
  3415.  Arithmetic Ops 
  3416.  Comparison Ops 
  3417.  Boolean Expressions 
  3418.  Assignment Ops 
  3419.  Increment Ops 
  3420.  Operator Precedence 
  3421.  
  3422.  
  3423. ΓòÉΓòÉΓòÉ 11.1. Index Expressions ΓòÉΓòÉΓòÉ
  3424.  
  3425. An index expression allows you to reference or extract selected elements of a 
  3426. matrix or vector. 
  3427.  
  3428. Indices may be scalars, vectors, ranges, or the special operator `:', which may 
  3429. be used to select entire rows or columns. 
  3430.  
  3431. Vectors are indexed using a single expression.  Matrices require two indices 
  3432. unless the value of the built-in variable do_fortran_indexing is nonzero, in 
  3433. which case matrices may also be indexed by a single expression. 
  3434.  
  3435. Built-in Variable: do_fortran_indexing 
  3436. If the value of do_fortran_indexing is nonzero, Octave allows you to select 
  3437. elements of a two-dimensional matrix using a single index by treating the 
  3438. matrix as a single vector created from the columns of the matrix.  The default 
  3439. value is 0. 
  3440.  
  3441. Given the matrix 
  3442.  
  3443. a = [1, 2; 3, 4]
  3444.  
  3445. all of the following expressions are equivalent 
  3446.  
  3447. a (1, [1, 2])
  3448. a (1, 1:2)
  3449. a (1, :)
  3450.  
  3451. and select the first row of the matrix. 
  3452.  
  3453. A special form of indexing may be used to select elements of a matrix or 
  3454. vector.  If the indices are vectors made up of only ones and zeros, the result 
  3455. is a new matrix whose elements correspond to the elements of the index vector 
  3456. that are equal to one.  For example, 
  3457.  
  3458. a = [1, 2; 3, 4];
  3459. a ([1, 0], :)
  3460.  
  3461. selects the first row of the matrix a. 
  3462.  
  3463. This operation can be useful for selecting elements of a matrix based on some 
  3464. condition, since the comparison operators return matrices of ones and zeros. 
  3465.  
  3466. This special zero-one form of indexing leads to a conflict with the standard 
  3467. indexing operation.  For example, should the following statements 
  3468.  
  3469. a = [1, 2; 3, 4];
  3470. a ([1, 1], :)
  3471.  
  3472. return the original matrix, or the matrix formed by selecting the first row 
  3473. twice?  Although this conflict is not likely to arise very often in practice, 
  3474. you may select the behavior you prefer by setting the built-in variable 
  3475. prefer_zero_one_indexing. 
  3476.  
  3477. Built-in Variable: prefer_zero_one_indexing 
  3478. If the value of prefer_zero_one_indexing is nonzero, Octave will perform 
  3479. zero-one style indexing when there is a conflict with the normal indexing 
  3480. rules.  See Index Expressions.  For example, given a matrix 
  3481.  
  3482. a = [1, 2, 3, 4]
  3483.  
  3484. with prefer_zero_one_indexing is set to nonzero, the expression 
  3485.  
  3486. a ([1, 1, 1, 1])
  3487.  
  3488. results in the matrix [ 1, 2, 3, 4 ].  If the value of prefer_zero_one_indexing 
  3489. set to 0, the result would be the matrix [ 1, 1, 1, 1 ]. 
  3490.  
  3491. In the first case, Octave is selecting each element corresponding to a `1' in 
  3492. the index vector.  In the second, Octave is selecting the first element 
  3493. multiple times. 
  3494.  
  3495. The default value for prefer_zero_one_indexing is 0. 
  3496.  
  3497. Finally, indexing a scalar with a vector of ones can be used to create a vector 
  3498. the same size as the index vector, with each element equal to the value of the 
  3499. original scalar.  For example, the following statements 
  3500.  
  3501. a = 13;
  3502. a ([1, 1, 1, 1])
  3503.  
  3504. produce a vector whose four elements are all equal to 13. 
  3505.  
  3506. Similarly, indexing a scalar with two vectors of ones can be used to create a 
  3507. matrix.  For example the following statements 
  3508.  
  3509. a = 13;
  3510. a ([1, 1], [1, 1, 1])
  3511.  
  3512. create a 2 by 3 matrix with all elements equal to 13. 
  3513.  
  3514. This is an obscure notation and should be avoided.  It is better to use the 
  3515. function ones to generate a matrix of the appropriate size whose elements are 
  3516. all one, and then to scale it to produce the desired result.  See Special 
  3517. Utility Matrices. 
  3518.  
  3519. Built-in Variable: prefer_column_vectors 
  3520. If prefer_column_vectors is nonzero, operations like 
  3521.  
  3522. for i = 1:10
  3523.   a (i) = i;
  3524. endfor
  3525.  
  3526. (for a previously  undefined) produce column vectors.  Otherwise, row vectors 
  3527. are preferred.  The default value is 1. 
  3528.  
  3529. If a variable is already defined to be a vector (a matrix with a single row or 
  3530. column), the original orientation is respected, regardless of the value of 
  3531. prefer_column_vectors. 
  3532.  
  3533. Built-in Variable: resize_on_range_error 
  3534. If the value of resize_on_range_error is nonzero, expressions like 
  3535.  
  3536. for i = 1:10
  3537.   a (i) = sqrt (i);
  3538. endfor
  3539.  
  3540. (for a previously undefined) result in the variable a being resized to be just 
  3541. large enough to hold the new value.  New elements that have not been given a 
  3542. value are set to zero.  If the value of resize_on_range_error is 0, an error 
  3543. message is printed and control is returned to the top level.  The default value 
  3544. is 1. 
  3545.  
  3546. Note that it is quite inefficient to create a vector using a loop like the one 
  3547. shown in the example above.  In this particular case, it would have been much 
  3548. more efficient to use the expression 
  3549.  
  3550. a = sqrt (1:10);
  3551.  
  3552. thus avoiding the loop entirely.  In cases where a loop is still required, or a 
  3553. number of values must be combined to form a larger matrix, it is generally much 
  3554. faster to set the size of the matrix first, and then insert elements using 
  3555. indexing commands.  For example, given a matrix a, 
  3556.  
  3557. [nr, nc] = size (a);
  3558. x = zeros (nr, n * nc);
  3559. for i = 1:n
  3560.   x(:,(i-1)*n+1:i*n) = a;
  3561. endfor
  3562.  
  3563. is considerably faster than 
  3564.  
  3565. x = a;
  3566. for i = 1:n-1
  3567.   x = [x, a];
  3568. endfor
  3569.  
  3570. particularly for large matrices because Octave does not have to repeatedly 
  3571. resize the result. 
  3572.  
  3573.  
  3574. ΓòÉΓòÉΓòÉ 11.2. Calling Functions ΓòÉΓòÉΓòÉ
  3575.  
  3576. A function is a name for a particular calculation.  Because it has a name, you 
  3577. can ask for it by name at any point in the program.  For example, the function 
  3578. sqrt computes the square root of a number. 
  3579.  
  3580. A fixed set of functions are built-in, which means they are available in every 
  3581. Octave program.  The sqrt function is one of these.  In addition, you can 
  3582. define your own functions. See Functions and Scripts, for information about how 
  3583. to do this. 
  3584.  
  3585. The way to use a function is with a function call expression, which consists of 
  3586. the function name followed by a list of arguments in parentheses. The arguments 
  3587. are expressions which give the raw materials for the calculation that the 
  3588. function will do.  When there is more than one argument, they are separated by 
  3589. commas.  If there are no arguments, you can omit the parentheses, but it is a 
  3590. good idea to include them anyway, to clearly indicate that a function call was 
  3591. intended.  Here are some examples: 
  3592.  
  3593. sqrt (x^2 + y^2)      # One argument
  3594. ones (n, m)           # Two arguments
  3595. rand ()               # No arguments
  3596.  
  3597. Each function expects a particular number of arguments.  For example, the sqrt 
  3598. function must be called with a single argument, the number to take the square 
  3599. root of: 
  3600.  
  3601. sqrt (argument)
  3602.  
  3603. Some of the built-in functions take a variable number of arguments, depending 
  3604. on the particular usage, and their behavior is different depending on the 
  3605. number of arguments supplied. 
  3606.  
  3607. Like every other expression, the function call has a value, which is computed 
  3608. by the function based on the arguments you give it.  In this example, the value 
  3609. of sqrt (argument) is the square root of the argument.  A function can also 
  3610. have side effects, such as assigning the values of certain variables or doing 
  3611. input or output operations. 
  3612.  
  3613. Unlike most languages, functions in Octave may return multiple values. For 
  3614. example, the following statement 
  3615.  
  3616. [u, s, v] = svd (a)
  3617.  
  3618. computes the singular value decomposition of the matrix a and assigns the three 
  3619. result matrices to u, s, and v. 
  3620.  
  3621. The left side of a multiple assignment expression is itself a list of 
  3622. expressions, and is allowed to be a list of variable names or index 
  3623. expressions.  See also Index Expressions, and Assignment Ops. 
  3624.  
  3625.  Call by Value 
  3626.  Recursion 
  3627.  
  3628.  
  3629. ΓòÉΓòÉΓòÉ 11.2.1. Call by Value ΓòÉΓòÉΓòÉ
  3630.  
  3631. In Octave, unlike Fortran, function arguments are passed by value, which means 
  3632. that each argument in a function call is evaluated and assigned to a temporary 
  3633. location in memory before being passed to the function. There is currently no 
  3634. way to specify that a function parameter should be passed by reference instead 
  3635. of by value.  This means that it is impossible to directly alter the value of 
  3636. function parameter in the calling function.  It can only change the local copy 
  3637. within the function body.  For example, the function 
  3638.  
  3639. function f (x, n)
  3640.   while (n-- > 0)
  3641.     disp (x);
  3642.   endwhile
  3643. endfunction
  3644.  
  3645. displays the value of the first argument n times.  In this function, the 
  3646. variable n is used as a temporary variable without having to worry that its 
  3647. value might also change in the calling function.  Call by value is also useful 
  3648. because it is always possible to pass constants for any function parameter 
  3649. without first having to determine that the function will not attempt to modify 
  3650. the parameter. 
  3651.  
  3652. The caller may use a variable as the expression for the argument, but the 
  3653. called function does not know this: it only knows what value the argument had. 
  3654. For example, given a function called as 
  3655.  
  3656. foo = "bar";
  3657. fcn (foo)
  3658.  
  3659. you should not think of the argument as being ``the variable foo.''  Instead, 
  3660. think of the argument as the string value, "bar". 
  3661.  
  3662. Even though Octave uses pass-by-value semantics for function arguments, values 
  3663. are not copied unnecessarily.  For example, 
  3664.  
  3665. x = rand (1000);
  3666. f (x);
  3667.  
  3668. does not actually force two 1000 by 1000 element matrices to exist unless the 
  3669. function f modifies the value of its argument.  Then Octave must create a copy 
  3670. to avoid changing the value outside the scope of the function f, or attempting 
  3671. (and probably failing!) to modify the value of a constant or the value of a 
  3672. temporary result. 
  3673.  
  3674.  
  3675. ΓòÉΓòÉΓòÉ 11.2.2. Recursion ΓòÉΓòÉΓòÉ
  3676.  
  3677. With some restrictions(2), recursive function calls are allowed.  A recursive 
  3678. function is one which calls itself, either directly or indirectly.  For 
  3679. example, here is an inefficient(3) way to compute the factorial of a given 
  3680. integer: 
  3681.  
  3682. function retval = fact (n)
  3683.   if (n > 0)
  3684.     retval = n * fact (n-1);
  3685.   else
  3686.     retval = 1;
  3687.   endif
  3688. endfunction
  3689.  
  3690. This function is recursive because it calls itself directly.  It eventually 
  3691. terminates because each time it calls itself, it uses an argument that is one 
  3692. less than was used for the previous call.  Once the argument is no longer 
  3693. greater than zero, it does not call itself, and the recursion ends. 
  3694.  
  3695. The built-in variable max_recursion_depth specifies a limit to the recursion 
  3696. depth and prevents Octave from recursing infinitely. 
  3697.  
  3698. max_recursion_depth Limit: the number of times a function may be called 
  3699. recursively. 
  3700. If the limit is exceeded, an error message is printed and control returns to 
  3701. the top level. 
  3702.  
  3703. The default value is 256. 
  3704.  
  3705.  
  3706. ΓòÉΓòÉΓòÉ 11.3. Arithmetic Operators ΓòÉΓòÉΓòÉ
  3707.  
  3708. The following arithmetic operators are available, and work on scalars and 
  3709. matrices. 
  3710.  
  3711.  x + y 
  3712.            Addition.  If both operands are matrices, the number of rows and 
  3713.            columns must both agree.  If one operand is a scalar, its value is 
  3714.            added to all the elements of the other operand. 
  3715.  
  3716.  x .+ y 
  3717.            Element by element addition.  This operator is equivalent to +. 
  3718.  
  3719.  x - y 
  3720.            Subtraction.  If both operands are matrices, the number of rows and 
  3721.            columns of both must agree. 
  3722.  
  3723.  x .- y 
  3724.            Element by element subtraction.  This operator is equivalent to -. 
  3725.  
  3726.  x * y 
  3727.            Matrix multiplication.  The number of columns of x must agree with 
  3728.            the number of rows of y. 
  3729.  
  3730.  x .* y 
  3731.            Element by element multiplication.  If both operands are matrices, 
  3732.            the number of rows and columns must both agree. 
  3733.  
  3734.  x / y 
  3735.            Right division.  This is conceptually equivalent to the expression 
  3736.  
  3737.                       (inverse (y') * x')'
  3738.  
  3739.            but it is computed without forming the inverse of y'. 
  3740.  
  3741.            If the system is not square, or if the coefficient matrix is 
  3742.            singular, a minimum norm solution is computed. 
  3743.  
  3744.  x ./ y 
  3745.            Element by element right division. 
  3746.  
  3747.  x \ y 
  3748.            Left division.  This is conceptually equivalent to the expression 
  3749.  
  3750.                       inverse (x) * y
  3751.  
  3752.            but it is computed without forming the inverse of x. 
  3753.  
  3754.            If the system is not square, or if the coefficient matrix is 
  3755.            singular, a minimum norm solution is computed. 
  3756.  
  3757.  x .\ y 
  3758.            Element by element left division.  Each element of y is divided by 
  3759.            each corresponding element of x. 
  3760.  
  3761.  x ^ y 
  3762.  x ** y 
  3763.            Power operator.  If x and y are both scalars, this operator returns 
  3764.            x raised to the power y.  If x is a scalar and y is a square matrix, 
  3765.            the result is computed using an eigenvalue expansion.  If x is a 
  3766.            square matrix. the result is computed by repeated multiplication if 
  3767.            y is an integer, and by an eigenvalue expansion if y is not an 
  3768.            integer.  An error results if both x and y are matrices. 
  3769.  
  3770.            The implementation of this operator needs to be improved. 
  3771.  
  3772.  x .^ y 
  3773.  
  3774.  x .** y 
  3775.            Element by element power operator.  If both operands are matrices, 
  3776.            the number of rows and columns must both agree. 
  3777.  
  3778.  -x 
  3779.            Negation. 
  3780.  
  3781.  +x 
  3782.            Unary plus.  This operator has no effect on the operand. 
  3783.  
  3784.  x' 
  3785.            Complex conjugate transpose.  For real arguments, this operator is 
  3786.            the same as the transpose operator.  For complex arguments, this 
  3787.            operator is equivalent to the expression 
  3788.  
  3789.                       conj (x.')
  3790.  
  3791.  x.' 
  3792.            Transpose. 
  3793.  
  3794.  Note that because Octave's element by element operators begin with a `.', 
  3795.  there is a possible ambiguity for statements like 
  3796.  
  3797.   1./m
  3798.  
  3799.  because the period could be interpreted either as part of the constant or as 
  3800.  part of the operator.  To resolve this conflict, Octave treats the expression 
  3801.  as if you had typed 
  3802.  
  3803.   (1) ./ m
  3804.  
  3805.  and not 
  3806.  
  3807.   (1.) / m
  3808.  
  3809.  Although this is inconsistent with the normal behavior of Octave's lexer, 
  3810.  which usually prefers to break the input into tokens by preferring the longest 
  3811.  possible match at any given point, it is more useful in this case. 
  3812.  
  3813.  Built-in Variable: warn_divide_by_zero 
  3814.  If the value of warn_divide_by_zero is nonzero, a warning is issued when 
  3815.  Octave encounters a division by zero.  If the value is 0, the warning is 
  3816.  omitted.  The default value is 1. 
  3817.  
  3818.  
  3819. ΓòÉΓòÉΓòÉ 11.4. Comparison Operators ΓòÉΓòÉΓòÉ
  3820.  
  3821. Comparison operators compare numeric values for relationships such as equality. 
  3822. They are written using relational operators. 
  3823.  
  3824. All of Octave's comparison operators return a value of 1 if the comparison is 
  3825. true, or 0 if it is false.  For matrix values, they all work on an 
  3826. element-by-element basis.  For example, 
  3827.  
  3828. [1, 2; 3, 4] == [1, 3; 2, 4]
  3829.      =>  1  0
  3830.          0  1
  3831.  
  3832. If one operand is a scalar and the other is a matrix, the scalar is compared to 
  3833. each element of the matrix in turn, and the result is the same size as the 
  3834. matrix. 
  3835.  
  3836.  x < y 
  3837.            True if x is less than y. 
  3838.  
  3839.  x <= y 
  3840.            True if x is less than or equal to y. 
  3841.  
  3842.  x == y 
  3843.            True if x is equal to y. 
  3844.  
  3845.  x >= y 
  3846.            True if x is greater than or equal to y. 
  3847.  
  3848.  x > y 
  3849.            True if x is greater than y. 
  3850.  
  3851.  x != y 
  3852.  x ~= y 
  3853.  x <> y 
  3854.            True if x is not equal to y. 
  3855.  
  3856.  String comparisons may also be performed with the strcmp function, not with 
  3857.  the comparison operators listed above. See Strings. 
  3858.  
  3859.  
  3860. ΓòÉΓòÉΓòÉ 11.5. Boolean Expressions ΓòÉΓòÉΓòÉ
  3861.  
  3862.  Element-by-element Boolean Operators 
  3863.  Short-circuit Boolean Operators 
  3864.  
  3865.  
  3866. ΓòÉΓòÉΓòÉ 11.5.1. Element-by-element Boolean Operators ΓòÉΓòÉΓòÉ
  3867.  
  3868. An element-by-element boolean expression is a combination of comparison 
  3869. expressions using the boolean operators ``or'' (`|'), ``and'' (`&'), and 
  3870. ``not'' (`!'), along with parentheses to control nesting.  The truth of the 
  3871. boolean expression is computed by combining the truth values of the 
  3872. corresponding elements of the component expressions.  A value is considered to 
  3873. be false if it is zero, and true otherwise. 
  3874.  
  3875. Element-by-element boolean expressions can be used wherever comparison 
  3876. expressions can be used.  They can be used in if and while statements. 
  3877. However, if a matrix value used as the condition in an if or while statement is 
  3878. only true if all of its elements are nonzero. 
  3879.  
  3880. Like comparison operations, each element of an element-by-element boolean 
  3881. expression also has a numeric value (1 if true, 0 if false) that comes into 
  3882. play if the result of the boolean expression is stored in a variable, or used 
  3883. in arithmetic. 
  3884.  
  3885. Here are descriptions of the three element-by-element boolean operators. 
  3886.  
  3887.  boolean1 & boolean2 
  3888.            Elements of the result are true if both corresponding elements of 
  3889.            boolean1 and boolean2 are true. 
  3890.  
  3891.  boolean1 | boolean2 
  3892.            Elements of the result are true if either of the corresponding 
  3893.            elements of boolean1 or boolean2 is true. 
  3894.  
  3895.  ! boolean 
  3896.  ~ boolean 
  3897.            Each element of the result is true if the corresponding element of 
  3898.            boolean is false. 
  3899.  
  3900.  For matrix operands, these operators work on an element-by-element basis.  For 
  3901.  example, the expression 
  3902.  
  3903.   [1, 0; 0, 1] & [1, 0; 2, 3]
  3904.  
  3905.  returns a two by two identity matrix. 
  3906.  
  3907.  For the binary operators, the dimensions of the operands must conform if both 
  3908.  are matrices.  If one of the operands is a scalar and the other a matrix, the 
  3909.  operator is applied to the scalar and each element of the matrix. 
  3910.  
  3911.  For the binary element-by-element boolean operators, both subexpressions 
  3912.  boolean1 and boolean2 are evaluated before computing the result.  This can 
  3913.  make a difference when the expressions have side effects.  For example, in the 
  3914.  expression 
  3915.  
  3916.   a & b++
  3917.  
  3918.  the value of the variable b is incremented even if the variable a is zero. 
  3919.  
  3920.  This behavior is necessary for the boolean operators to work as described for 
  3921.  matrix-valued operands. 
  3922.  
  3923.  
  3924. ΓòÉΓòÉΓòÉ 11.5.2. Short-circuit Boolean Operators ΓòÉΓòÉΓòÉ
  3925.  
  3926. Combined with the implicit conversion to scalar values in if and while 
  3927. conditions, Octave's element-by-element boolean operators are often sufficient 
  3928. for performing most logical operations.  However, it is sometimes desirable to 
  3929. stop evaluating a boolean expression as soon as the overall truth value can be 
  3930. determined.  Octave's short-circuit boolean operators work this way. 
  3931.  
  3932.  boolean1 && boolean2 
  3933.            The expression boolean1 is evaluated and converted to a scalar using 
  3934.            the equivalent of the operation all (all (boolean1)). If it is 
  3935.            false, the result of the overall expression is 0.  If it is true, 
  3936.            the expression boolean2 is evaluated and converted to a scalar using 
  3937.            the equivalent of the operation all (all (boolean1)).  If it is 
  3938.            true, the result of the overall expression is 1.  Otherwise, the 
  3939.            result of the overall expression is 0. 
  3940.  
  3941.  boolean1 || boolean2 
  3942.            The expression boolean1 is evaluated and converted to a scalar using 
  3943.            the equivalent of the operation all (all (boolean1)). If it is true, 
  3944.            the result of the overall expression is 1.  If it is false, the 
  3945.            expression boolean2 is evaluated and converted to a scalar using the 
  3946.            equivalent of the operation all (all (boolean1)).  If it is true, 
  3947.            the result of the overall expression is 1.  Otherwise, the result of 
  3948.            the overall expression is 0. 
  3949.  
  3950.  The fact that both operands may not be evaluated before determining the 
  3951.  overall truth value of the expression can be important.  For example, in the 
  3952.  expression 
  3953.  
  3954.   a && b++
  3955.  
  3956.  the value of the variable b is only incremented if the variable a is nonzero. 
  3957.  
  3958.  This can be used to write somewhat more concise code.  For example, it is 
  3959.  possible write 
  3960.  
  3961.   function f (a, b, c)
  3962.     if (nargin > 2 && isstr (c))
  3963.       ...
  3964.  
  3965.  instead of having to use two if statements to avoid attempting to evaluate an 
  3966.  argument that doesn't exist.  For example, without the short-circuit feature, 
  3967.  it would be necessary to write 
  3968.  
  3969.   function f (a, b, c)
  3970.     if (nargin > 2)
  3971.       if (isstr (c))
  3972.         ...
  3973.  
  3974.  Writing 
  3975.  
  3976.   function f (a, b, c)
  3977.     if (nargin > 2 & isstr (c))
  3978.       ...
  3979.  
  3980.  would result in an error if f were called with one or two arguments because 
  3981.  Octave would be forced to try to evaluate both of the operands for the 
  3982.  operator `&'. 
  3983.  
  3984.  
  3985. ΓòÉΓòÉΓòÉ 11.6. Assignment Expressions ΓòÉΓòÉΓòÉ
  3986.  
  3987. An assignment is an expression that stores a new value into a variable.  For 
  3988. example, the following expression assigns the value 1 to the variable z: 
  3989.  
  3990. z = 1
  3991.  
  3992. After this expression is executed, the variable z has the value 1. Whatever old 
  3993. value z had before the assignment is forgotten. The `=' sign is called an 
  3994. assignment operator. 
  3995.  
  3996. Assignments can store string values also.  For example, the following 
  3997. expression would store the value "this food is good" in the variable message: 
  3998.  
  3999. thing = "food"
  4000. predicate = "good"
  4001. message = [ "this " , thing , " is " , predicate ]
  4002.  
  4003. (This also illustrates concatenation of strings.) 
  4004.  
  4005. Most operators (addition, concatenation, and so on) have no effect except to 
  4006. compute a value.  If you ignore the value, you might as well not use the 
  4007. operator.  An assignment operator is different.  It does produce a value, but 
  4008. even if you ignore the value, the assignment still makes itself felt through 
  4009. the alteration of the variable.  We call this a side effect. 
  4010.  
  4011. The left-hand operand of an assignment need not be a variable (see Variables). 
  4012. It can also be an element of a matrix (see Index Expressions) or a list of 
  4013. return values (see Calling Functions).  These are all called lvalues, which 
  4014. means they can appear on the left-hand side of an assignment operator. The 
  4015. right-hand operand may be any expression.  It produces the new value which the 
  4016. assignment stores in the specified variable, matrix element, or list of return 
  4017. values. 
  4018.  
  4019. It is important to note that variables do not have permanent types. The type of 
  4020. a variable is simply the type of whatever value it happens to hold at the 
  4021. moment.  In the following program fragment, the variable foo has a numeric 
  4022. value at first, and a string value later on: 
  4023.  
  4024. octave:13> foo = 1
  4025. foo = 1
  4026. octave:13> foo = "bar"
  4027. foo = bar
  4028.  
  4029. When the second assignment gives foo a string value, the fact that it 
  4030. previously had a numeric value is forgotten. 
  4031.  
  4032. Assignment of a scalar to an indexed matrix sets all of the elements that are 
  4033. referenced by the indices to the scalar value.  For example, if a is a matrix 
  4034. with at least two columns, 
  4035.  
  4036. a(:, 2) = 5
  4037.  
  4038. sets all the elements in the second column of a to 5. 
  4039.  
  4040. Assigning an empty matrix `[]' works in most cases to allow you to delete rows 
  4041. or columns of matrices and vectors.  See Empty Matrices. For example, given a 4 
  4042. by 5 matrix A, the assignment 
  4043.  
  4044. A (3, :) = []
  4045.  
  4046. deletes the third row of A, and the assignment 
  4047.  
  4048. A (:, 1:2:5) = []
  4049.  
  4050. deletes the first, third, and fifth columns. 
  4051.  
  4052. An assignment is an expression, so it has a value.  Thus, z = 1 as an 
  4053. expression has the value 1.  One consequence of this is that you can write 
  4054. multiple assignments together: 
  4055.  
  4056. x = y = z = 0
  4057.  
  4058. stores the value 0 in all three variables.  It does this because the value of z 
  4059. = 0, which is 0, is stored into y, and then the value of y = z = 0, which is 0, 
  4060. is stored into x. 
  4061.  
  4062. This is also true of assignments to lists of values, so the following is a 
  4063. valid expression 
  4064.  
  4065. [a, b, c] = [u, s, v] = svd (a)
  4066.  
  4067. that is exactly equivalent to 
  4068.  
  4069. [u, s, v] = svd (a)
  4070. a = u
  4071. b = s
  4072. c = v
  4073.  
  4074. In expressions like this, the number of values in each part of the expression 
  4075. need not match.  For example, the expression 
  4076.  
  4077. [a, b, c, d] = [u, s, v] = svd (a)
  4078.  
  4079. is equivalent to the expression above, except that the value of the variable 
  4080. `d' is left unchanged, and the expression 
  4081.  
  4082. [a, b] = [u, s, v] = svd (a)
  4083.  
  4084. is equivalent to 
  4085.  
  4086. [u, s, v] = svd (a)
  4087. a = u
  4088. b = s
  4089.  
  4090. You can use an assignment anywhere an expression is called for.  For example, 
  4091. it is valid to write x != (y = 1) to set y to 1 and then test whether x equals 
  4092. 1.  But this style tends to make programs hard to read.  Except in a one-shot 
  4093. program, you should rewrite it to get rid of such nesting of assignments.  This 
  4094. is never very hard. 
  4095.  
  4096.  
  4097. ΓòÉΓòÉΓòÉ 11.7. Increment Operators ΓòÉΓòÉΓòÉ
  4098.  
  4099. Increment operators increase or decrease the value of a variable by 1.  The 
  4100. operator to increment a variable is written as `++'.  It may be used to 
  4101. increment a variable either before or after taking its value. 
  4102.  
  4103. For example, to pre-increment the variable x, you would write ++x.  This would 
  4104. add one to x and then return the new value of x as the result of the 
  4105. expression.  It is exactly the same as the expression x = x + 1. 
  4106.  
  4107. To post-increment a variable x, you would write x++. This adds one to the 
  4108. variable x, but returns the value that x had prior to incrementing it.  For 
  4109. example, if x is equal to 2, the result of the expression x++ is 2, and the new 
  4110. value of x is 3. 
  4111.  
  4112. For matrix and vector arguments, the increment and decrement operators work on 
  4113. each element of the operand. 
  4114.  
  4115. Here is a list of all the increment and decrement expressions. 
  4116.  
  4117.  ++x 
  4118.            This expression increments the variable x.  The value of the 
  4119.            expression is the new value of x.  It is equivalent to the 
  4120.            expression x = x + 1. 
  4121.  
  4122.  --x 
  4123.            This expression decrements the variable x.  The value of the 
  4124.            expression is the new value of x.  It is equivalent to the 
  4125.            expression x = x - 1. 
  4126.  
  4127.  x++ 
  4128.            This expression causes the variable x to be incremented.  The value 
  4129.            of the expression is the old value of x. 
  4130.  
  4131.  x-- 
  4132.            This expression causes the variable x to be decremented.  The value 
  4133.            of the expression is the old value of x. 
  4134.  
  4135.  It is not currently possible to increment index expressions.  For example, you 
  4136.  might expect that the expression v(4)++ would increment the fourth element of 
  4137.  the vector v, but instead it results in a parse error.  This problem may be 
  4138.  fixed in a future release of Octave. 
  4139.  
  4140.  
  4141. ΓòÉΓòÉΓòÉ 11.8. Operator Precedence ΓòÉΓòÉΓòÉ
  4142.  
  4143. Operator precedence determines how operators are grouped, when different 
  4144. operators appear close by in one expression.  For example, `*' has higher 
  4145. precedence than `+'.  Thus, the expression a + b * c means to multiply b and c, 
  4146. and then add a to the product (i.e., a + (b * c)). 
  4147.  
  4148. You can overrule the precedence of the operators by using parentheses. You can 
  4149. think of the precedence rules as saying where the parentheses are assumed if 
  4150. you do not write parentheses yourself.  In fact, it is wise to use parentheses 
  4151. whenever you have an unusual combination of operators, because other people who 
  4152. read the program may not remember what the precedence is in this case.  You 
  4153. might forget as well, and then you too could make a mistake.  Explicit 
  4154. parentheses will help prevent any such mistake. 
  4155.  
  4156. When operators of equal precedence are used together, the leftmost operator 
  4157. groups first, except for the assignment and exponentiation operators, which 
  4158. group in the opposite order.  Thus, the expression a - b + c groups as (a - b) 
  4159. + c, but the expression a = b = c groups as a = (b = c). 
  4160.  
  4161. The precedence of prefix unary operators is important when another operator 
  4162. follows the operand.  For example, -x^2 means -(x^2), because `-' has lower 
  4163. precedence than `^'. 
  4164.  
  4165. Here is a table of the operators in Octave, in order of increasing precedence. 
  4166.  
  4167.  statement separators 
  4168.            `;', `,'. 
  4169.  
  4170.  assignment 
  4171.            `='.  This operator groups right to left. 
  4172.  
  4173.  logical "or" and "and" 
  4174.            `||', `&&'. 
  4175.  
  4176.  element-wise "or" and "and" 
  4177.            `|', `&'. 
  4178.  
  4179.  relational 
  4180.            `<', `<=', `==', `>=', `>', `!=', `~=', `<>'. 
  4181.  
  4182.  colon 
  4183.            `:'. 
  4184.  
  4185.  add, subtract 
  4186.            `+', `-'. 
  4187.  
  4188.  multiply, divide 
  4189.            `*', `/', `\', `.\', `.*', `./'. 
  4190.  
  4191.  transpose 
  4192.            `'', `.'' 
  4193.  
  4194.  unary plus, minus, increment, decrement, and ``not'' 
  4195.            `+', `-', `++', `--', `!', `~'. 
  4196.  
  4197.  exponentiation 
  4198.            `^', `**', `.^', `.**'. 
  4199.  
  4200.  
  4201. ΓòÉΓòÉΓòÉ 12. Evaluation ΓòÉΓòÉΓòÉ
  4202.  
  4203. Normally, you evaluate expressions simply by typing them at the Octave prompt, 
  4204. or by asking Octave to interpret commands that you have saved in a file. 
  4205.  
  4206. Sometimes, you may find it necessary to evaluate an expression that has been 
  4207. computed and stored in a string, or use a string as the name of a function to 
  4208. call.  The eval and feval functions allow you to do just that, and are 
  4209. necessary in order to evaluate commands that are not known until run time, or 
  4210. to write functions that will need to call user-supplied functions. 
  4211.  
  4212. Built-in Function:  eval (command) 
  4213. Parse the string command and evaluate it as if it were an Octave program, 
  4214. returning the last value computed.  The command is evaluated in the current 
  4215. context, so any results remain available after eval returns.  For example, 
  4216.  
  4217. eval ("a = 13")
  4218.      -| a = 13
  4219.      => 13
  4220.  
  4221. In this case, the value of the evaluated expression is printed and it is also 
  4222. returned returned from eval.  Just as with any other expression, you can turn 
  4223. printing off by ending the expression in a semicolon.  For example, 
  4224.  
  4225. eval ("a = 13;")
  4226.      => 13
  4227.  
  4228. In this example, the variable a has been given the value 13, but the value of 
  4229. the expression is not printed.  You can also turn off automatic printing for 
  4230. all expressions executed by eval using the variable default_eval_print_flag. 
  4231.  
  4232. Built-in Variable: default_eval_print_flag 
  4233. If the value of this variable is nonzero, Octave prints the results of commands 
  4234. executed by eval that do not end with semicolons.  If it is zero, automatic 
  4235. printing is suppressed.  The default value is 1. 
  4236.  
  4237. Built-in Function:  feval (name, ...) 
  4238. Evaluate the function named name.  Any arguments after the first are passed on 
  4239. to the named function.  For example, 
  4240.  
  4241. feval ("acos", -1)
  4242.      => 3.1416
  4243.  
  4244. calls the function acos with the argument `-1'. 
  4245.  
  4246. The function feval is necessary in order to be able to write functions that 
  4247. call user-supplied functions, because Octave does not have a way to declare a 
  4248. pointer to a function (like C) or to declare a special kind of variable that 
  4249. can be used to hold the name of a function (like EXTERNAL in Fortran). 
  4250. Instead, you must refer to functions by name, and use feval to call them. 
  4251.  
  4252. Here is a simple-minded function using feval that finds the root of a 
  4253. user-supplied function of one variable using Newton's method. 
  4254.  
  4255. function result = newtroot (fname, x)
  4256.  
  4257. # usage: newtroot (fname, x)
  4258. #
  4259. #   fname : a string naming a function f(x).
  4260. #   x     : initial guess
  4261.  
  4262.   delta = tol = sqrt (eps);
  4263.   maxit = 200;
  4264.   fx = feval (fname, x);
  4265.   for i = 1:maxit
  4266.     if (abs (fx) < tol)
  4267.       result = x;
  4268.       return;
  4269.     else
  4270.       fx_new = feval (fname, x + delta);
  4271.       deriv = (fx_new - fx) / delta;
  4272.       x = x - fx / deriv;
  4273.       fx = fx_new;
  4274.     endif
  4275.   endfor
  4276.  
  4277.   result = x;
  4278.  
  4279. endfunction
  4280.  
  4281. Note that this is only meant to be an example of calling user-supplied 
  4282. functions and should not be taken too seriously.  In addition to using a more 
  4283. robust algorithm, any serious code would check the number and type of all the 
  4284. arguments, ensure that the supplied function really was a function, etc.  See 
  4285. See Predicates for Numeric Objects, for example, for a list of predicates for 
  4286. numeric objects, and See Status of Variables, for a description of the exist 
  4287. function. 
  4288.  
  4289.  
  4290. ΓòÉΓòÉΓòÉ 13. Statements ΓòÉΓòÉΓòÉ
  4291.  
  4292. Statements may be a simple constant expression or a complicated list of nested 
  4293. loops and conditional statements. 
  4294.  
  4295. Control statements such as if, while, and so on control the flow of execution 
  4296. in Octave programs.  All the control statements start with special keywords 
  4297. such as if and while, to distinguish them from simple expressions. Many control 
  4298. statements contain other statements; for example, the if statement contains 
  4299. another statement which may or may not be executed. 
  4300.  
  4301. Each control statement has a corresponding end statement that marks the end of 
  4302. the end of the control statement.  For example, the keyword endif marks the end 
  4303. of an if statement, and endwhile marks the end of a while statement.  You can 
  4304. use the keyword end anywhere a more specific end keyword is expected, but using 
  4305. the more specific keywords is preferred because if you use them, Octave is able 
  4306. to provide better diagnostics for mismatched or missing end tokens. 
  4307.  
  4308. The list of statements contained between keywords like if or while and the 
  4309. corresponding end statement is called the body of a control statement. 
  4310.  
  4311.  The if Statement 
  4312.  The switch Statement 
  4313.  The while Statement 
  4314.  The for Statement 
  4315.  The break Statement 
  4316.  The continue Statement 
  4317.  The unwind_protect Statement 
  4318.  The try Statement 
  4319.  Continuation Lines 
  4320.  
  4321.  
  4322. ΓòÉΓòÉΓòÉ 13.1. The if Statement ΓòÉΓòÉΓòÉ
  4323.  
  4324. The if statement is Octave's decision-making statement.  There are three basic 
  4325. forms of an if statement.  In its simplest form, it looks like this: 
  4326.  
  4327. if (condition)
  4328.   then-body
  4329. endif
  4330.  
  4331. condition is an expression that controls what the rest of the statement will 
  4332. do.  The then-body is executed only if condition is true. 
  4333.  
  4334. The condition in an if statement is considered true if its value is non-zero, 
  4335. and false if its value is zero.  If the value of the conditional expression in 
  4336. an if statement is a vector or a matrix, it is considered true only if all of 
  4337. the elements are non-zero. 
  4338.  
  4339. The second form of an if statement looks like this: 
  4340.  
  4341. if (condition)
  4342.   then-body
  4343. else
  4344.   else-body
  4345. endif
  4346.  
  4347. If condition is true, then-body is executed; otherwise, else-body is executed. 
  4348.  
  4349. Here is an example: 
  4350.  
  4351. if (rem (x, 2) == 0)
  4352.   printf ("x is even\n");
  4353. else
  4354.   printf ("x is odd\n");
  4355. endif
  4356.  
  4357. In this example, if the expression rem (x, 2) == 0 is true (that is, the value 
  4358. of x is divisible by 2), then the first printf statement is evaluated, 
  4359. otherwise the second printf statement is evaluated. 
  4360.  
  4361. The third and most general form of the if statement allows multiple decisions 
  4362. to be combined in a single statement.  It looks like this: 
  4363.  
  4364. if (condition)
  4365.   then-body
  4366. elseif (condition)
  4367.   elseif-body
  4368. else
  4369.   else-body
  4370. endif
  4371.  
  4372. Any number of elseif clauses may appear.  Each condition is tested in turn, and 
  4373. if one is found to be true, its corresponding body is executed.  If none of the 
  4374. conditions are true and the else clause is present, its body is executed.  Only 
  4375. one else clause may appear, and it must be the last part of the statement. 
  4376.  
  4377. In the following example, if the first condition is true (that is, the value of 
  4378. x is divisible by 2), then the first printf statement is executed.  If it is 
  4379. false, then the second condition is tested, and if it is true (that is, the 
  4380. value of x is divisible by 3), then the second printf statement is executed. 
  4381. Otherwise, the third printf statement is performed. 
  4382.  
  4383. if (rem (x, 2) == 0)
  4384.   printf ("x is even\n");
  4385. elseif (rem (x, 3) == 0)
  4386.   printf ("x is odd and divisible by 3\n");
  4387. else
  4388.   printf ("x is odd\n");
  4389. endif
  4390.  
  4391. Note that the elseif keyword must not be spelled else if, as is allowed in 
  4392. Fortran.  If it is, the space between the else and if will tell Octave to treat 
  4393. this as a new if statement within another if statement's else clause.  For 
  4394. example, if you write 
  4395.  
  4396. if (c1)
  4397.   body-1
  4398. else if (c2)
  4399.   body-2
  4400. endif
  4401.  
  4402. Octave will expect additional input to complete the first if statement.  If you 
  4403. are using Octave interactively, it will continue to prompt you for additional 
  4404. input.  If Octave is reading this input from a file, it may complain about 
  4405. missing or mismatched end statements, or, if you have not used the more 
  4406. specific end statements (endif, endfor, etc.), it may simply produce incorrect 
  4407. results, without producing any warning messages. 
  4408.  
  4409. It is much easier to see the error if we rewrite the statements above like 
  4410. this, 
  4411.  
  4412. if (c1)
  4413.   body-1
  4414. else
  4415.   if (c2)
  4416.     body-2
  4417.   endif
  4418.  
  4419. using the indentation to show how Octave groups the statements. See Functions 
  4420. and Scripts. 
  4421.  
  4422. Built-in Variable: warn_assign_as_truth_value 
  4423. If the value of warn_assign_as_truth_value is nonzero, a warning is issued for 
  4424. statements like 
  4425.  
  4426. if (s = t)
  4427.   ...
  4428.  
  4429. since such statements are not common, and it is likely that the intent was to 
  4430. write 
  4431.  
  4432. if (s == t)
  4433.   ...
  4434.  
  4435. instead. 
  4436.  
  4437. There are times when it is useful to write code that contains assignments 
  4438. within the condition of a while or if statement.  For example, statements like 
  4439.  
  4440. while (c = getc())
  4441.   ...
  4442.  
  4443. are common in C programming. 
  4444.  
  4445. It is possible to avoid all warnings about such statements by setting 
  4446. warn_assign_as_truth_value to 0, but that may also let real errors like 
  4447.  
  4448. if (x = 1)  # intended to test (x == 1)!
  4449.   ...
  4450.  
  4451. slip by. 
  4452.  
  4453. In such cases, it is possible suppress errors for specific statements by 
  4454. writing them with an extra set of parentheses.  For example, writing the 
  4455. previous example as 
  4456.  
  4457. while ((c = getc()))
  4458.   ...
  4459.  
  4460. will prevent the warning from being printed for this statement, while allowing 
  4461. Octave to warn about other assignments used in conditional contexts. 
  4462.  
  4463. The default value of warn_assign_as_truth_value is 1. 
  4464.  
  4465.  
  4466. ΓòÉΓòÉΓòÉ 13.2. The switch Statement ΓòÉΓòÉΓòÉ
  4467.  
  4468. The switch statement was introduced in Octave 2.0.5.  It should be considered 
  4469. experimental, and details of the implementation may change slightly in future 
  4470. versions of Octave.  If you have comments or would like to share your 
  4471. experiences in trying to use this new command in real programs, please send 
  4472. them to octave-maintainers@bevo.che.wisc.edu.  (But if you think you've found a 
  4473. bug, please report it to bug-octave@bevo.che.wisc.edu. 
  4474.  
  4475. The general form of the switch statement is 
  4476.  
  4477. switch expression
  4478.   case label
  4479.     command_list
  4480.   case label
  4481.     command_list
  4482.   ...
  4483.  
  4484.   otherwise
  4485.     command_list
  4486. endswitch
  4487.  
  4488.      The identifiers switch, case, otherwise, and endswitch are now keywords. 
  4489.  
  4490.      The label may be any expression. 
  4491.  
  4492.      Duplicate label values are not detected.  The command_list corresponding 
  4493.       to the first match will be executed. 
  4494.  
  4495.      You must have at least one case label command_list clause. 
  4496.  
  4497.      The otherwise command_list clause is optional. 
  4498.  
  4499.      As with all other specific end keywords, endswitch may be replaced by 
  4500.       end, but you can get better diagnostics if you use the specific forms. 
  4501.  
  4502.      Cases are exclusive, so they don't `fall through' as do the cases in the 
  4503.       switch statement of the C language. 
  4504.  
  4505.      The command_list elements are not optional.  Making the list optional 
  4506.       would have meant requiring a separator between the label and the command 
  4507.       list.  Otherwise, things like 
  4508.  
  4509.             switch (foo)
  4510.               case (1) -2
  4511.               ...
  4512.  
  4513.       would produce surprising results, as would 
  4514.  
  4515.             switch (foo)
  4516.               case (1)
  4517.               case (2)
  4518.                 doit ();
  4519.               ...
  4520.  
  4521.       particularly for C programmers. 
  4522.  
  4523.      The implementation is simple-minded and currently offers no real 
  4524.       performance improvement over an equivalent if block, even if all the 
  4525.       labels are integer constants.  Perhaps a future variation on this could 
  4526.       detect all constant integer labels and improve performance by using a 
  4527.       jump table. 
  4528.  
  4529.  Built-in Variable: warn_variable_switch_label 
  4530.  If the value of this variable is nonzero, Octave will print a warning if a 
  4531.  switch label is not a constant or constant expression 
  4532.  
  4533.  
  4534. ΓòÉΓòÉΓòÉ 13.3. The while Statement ΓòÉΓòÉΓòÉ
  4535.  
  4536. In programming, a loop means a part of a program that is (or at least can be) 
  4537. executed two or more times in succession. 
  4538.  
  4539. The while statement is the simplest looping statement in Octave. It repeatedly 
  4540. executes a statement as long as a condition is true.  As with the condition in 
  4541. an if statement, the condition in a while statement is considered true if its 
  4542. value is non-zero, and false if its value is zero.  If the value of the 
  4543. conditional expression in a while statement is a vector or a matrix, it is 
  4544. considered true only if all of the elements are non-zero. 
  4545.  
  4546. Octave's while statement looks like this: 
  4547.  
  4548. while (condition)
  4549.   body
  4550. endwhile
  4551.  
  4552. Here body is a statement or list of statements that we call the body of the 
  4553. loop, and condition is an expression that controls how long the loop keeps 
  4554. running. 
  4555.  
  4556. The first thing the while statement does is test condition. If condition is 
  4557. true, it executes the statement body.  After body has been executed, condition 
  4558. is tested again, and if it is still true, body is executed again.  This process 
  4559. repeats until condition is no longer true.  If condition is initially false, 
  4560. the body of the loop is never executed. 
  4561.  
  4562. This example creates a variable fib that contains the first ten elements of the 
  4563. Fibonacci sequence. 
  4564.  
  4565. fib = ones (1, 10);
  4566. i = 3;
  4567. while (i <= 10)
  4568.   fib (i) = fib (i-1) + fib (i-2);
  4569.   i++;
  4570. endwhile
  4571.  
  4572. Here the body of the loop contains two statements. 
  4573.  
  4574. The loop works like this: first, the value of i is set to 3. Then, the while 
  4575. tests whether i is less than or equal to 10.  This is the case when i equals 3, 
  4576. so the value of the i-th element of fib is set to the sum of the previous two 
  4577. values in the sequence.  Then the i++ increments the value of i and the loop 
  4578. repeats.  The loop terminates when i reaches 11. 
  4579.  
  4580. A newline is not required between the condition and the body; but using one 
  4581. makes the program clearer unless the body is very simple. 
  4582.  
  4583. See The if Statement for a description of the variable 
  4584. warn_assign_as_truth_value. 
  4585.  
  4586.  
  4587. ΓòÉΓòÉΓòÉ 13.4. The for Statement ΓòÉΓòÉΓòÉ
  4588.  
  4589. The for statement makes it more convenient to count iterations of a loop.  The 
  4590. general form of the for statement looks like this: 
  4591.  
  4592. for var = expression
  4593.   body
  4594. endfor
  4595.  
  4596. where body stands for any statement or list of statements, expression is any 
  4597. valid expression, and var may take several forms.  Usually it is a simple 
  4598. variable name or an indexed variable.  If the value of expression is a 
  4599. structure, var may also be a list.  See Looping Over Structure Elements, below. 
  4600.  
  4601. The assignment expression in the for statement works a bit differently than 
  4602. Octave's normal assignment statement.  Instead of assigning the complete result 
  4603. of the expression, it assigns each column of the expression to var in turn.  If 
  4604. expression is a range, a row vector, or a scalar, the value of var will be a 
  4605. scalar each time the loop body is executed.  If var is a column vector or a 
  4606. matrix, var will be a column vector each time the loop body is executed. 
  4607.  
  4608. The following example shows another way to create a vector containing the first 
  4609. ten elements of the Fibonacci sequence, this time using the for statement: 
  4610.  
  4611. fib = ones (1, 10);
  4612. for i = 3:10
  4613.   fib (i) = fib (i-1) + fib (i-2);
  4614. endfor
  4615.  
  4616. This code works by first evaluating the expression 3:10, to produce a range of 
  4617. values from 3 to 10 inclusive.  Then the variable i is assigned the first 
  4618. element of the range and the body of the loop is executed once.  When the end 
  4619. of the loop body is reached, the next value in the range is assigned to the 
  4620. variable i, and the loop body is executed again.  This process continues until 
  4621. there are no more elements to assign. 
  4622.  
  4623. Although it is possible to rewrite all for loops as while loops, the Octave 
  4624. language has both statements because often a for loop is both less work to type 
  4625. and more natural to think of. Counting the number of iterations is very common 
  4626. in loops and it can be easier to think of this counting as part of looping 
  4627. rather than as something to do inside the loop. 
  4628.  
  4629.  Looping Over Structure Elements 
  4630.  
  4631.  
  4632. ΓòÉΓòÉΓòÉ 13.4.1. Looping Over Structure Elements ΓòÉΓòÉΓòÉ
  4633.  
  4634. A special form of the for statement allows you to loop over all the elements of 
  4635. a structure: 
  4636.  
  4637. for [ val, key ] = expression
  4638.   body
  4639. endfor
  4640.  
  4641. In this form of the for statement, the value of expression must be a structure. 
  4642. If it is, key and val are set to the name of the element and the corresponding 
  4643. value in turn, until there are no more elements. For example, 
  4644.  
  4645. x.a = 1
  4646. x.b = [1, 2; 3, 4]
  4647. x.c = "string"
  4648. for [val, key] = x
  4649.   key
  4650.   val
  4651. endfor
  4652.  
  4653.      -| key = a
  4654.      -| val = 1
  4655.      -| key = b
  4656.      -| val =
  4657.      -|
  4658.      -|   1  2
  4659.      -|   3  4
  4660.      -|
  4661.      -| key = c
  4662.      -| val = string
  4663.  
  4664. The elements are not accessed in any particular order.  If you need to cycle 
  4665. through the list in a particular way, you will have to use the function 
  4666. struct_elements and sort the list yourself. 
  4667.  
  4668. The key variable may also be omitted.  If it is, the brackets are also 
  4669. optional.  This is useful for cycling through the values of all the structure 
  4670. elements when the names of the elements do not need to be known. 
  4671.  
  4672.  
  4673. ΓòÉΓòÉΓòÉ 13.5. The break Statement ΓòÉΓòÉΓòÉ
  4674.  
  4675. The break statement jumps out of the innermost for or while loop that encloses 
  4676. it.  The break statement may only be used within the body of a loop.  The 
  4677. following example finds the smallest divisor of a given integer, and also 
  4678. identifies prime numbers: 
  4679.  
  4680. num = 103;
  4681. div = 2;
  4682. while (div*div <= num)
  4683.   if (rem (num, div) == 0)
  4684.     break;
  4685.   endif
  4686.   div++;
  4687. endwhile
  4688. if (rem (num, div) == 0)
  4689.   printf ("Smallest divisor of %d is %d\n", num, div)
  4690. else
  4691.   printf ("%d is prime\n", num);
  4692. endif
  4693.  
  4694. When the remainder is zero in the first while statement, Octave immediately 
  4695. breaks out of the loop.  This means that Octave proceeds immediately to the 
  4696. statement following the loop and continues processing.  (This is very different 
  4697. from the exit statement which stops the entire Octave program.) 
  4698.  
  4699. Here is another program equivalent to the previous one.  It illustrates how the 
  4700. condition of a while statement could just as well be replaced with a break 
  4701. inside an if: 
  4702.  
  4703. num = 103;
  4704. div = 2;
  4705. while (1)
  4706.   if (rem (num, div) == 0)
  4707.     printf ("Smallest divisor of %d is %d\n", num, div);
  4708.     break;
  4709.   endif
  4710.   div++;
  4711.   if (div*div > num)
  4712.     printf ("%d is prime\n", num);
  4713.     break;
  4714.   endif
  4715. endwhile
  4716.  
  4717.  
  4718. ΓòÉΓòÉΓòÉ 13.6. The continue Statement ΓòÉΓòÉΓòÉ
  4719.  
  4720. The continue statement, like break, is used only inside for or while loops.  It 
  4721. skips over the rest of the loop body, causing the next cycle around the loop to 
  4722. begin immediately. Contrast this with break, which jumps out of the loop 
  4723. altogether. Here is an example: 
  4724.  
  4725. # print elements of a vector of random
  4726. # integers that are even.
  4727.  
  4728. # first, create a row vector of 10 random
  4729. # integers with values between 0 and 100:
  4730.  
  4731. vec = round (rand (1, 10) * 100);
  4732.  
  4733. # print what we're interested in:
  4734.  
  4735. for x = vec
  4736.   if (rem (x, 2) != 0)
  4737.     continue;
  4738.   endif
  4739.   printf ("%d\n", x);
  4740. endfor
  4741.  
  4742. If one of the elements of vec is an odd number, this example skips the print 
  4743. statement for that element, and continues back to the first statement in the 
  4744. loop. 
  4745.  
  4746. This is not a practical example of the continue statement, but it should give 
  4747. you a clear understanding of how it works.  Normally, one would probably write 
  4748. the loop like this: 
  4749.  
  4750. for x = vec
  4751.   if (rem (x, 2) == 0)
  4752.     printf ("%d\n", x);
  4753.   endif
  4754. endfor
  4755.  
  4756.  
  4757. ΓòÉΓòÉΓòÉ 13.7. The unwind_protect Statement ΓòÉΓòÉΓòÉ
  4758.  
  4759. Octave supports a limited form of exception handling modelled after the 
  4760. unwind-protect form of Lisp. 
  4761.  
  4762. The general form of an unwind_protect block looks like this: 
  4763.  
  4764. unwind_protect
  4765.   body
  4766. unwind_protect_cleanup
  4767.   cleanup
  4768. end_unwind_protect
  4769.  
  4770. Where body and cleanup are both optional and may contain any Octave expressions 
  4771. or commands.  The statements in cleanup are guaranteed to be executed 
  4772. regardless of how control exits body. 
  4773.  
  4774. This is useful to protect temporary changes to global variables from possible 
  4775. errors.  For example, the following code will always restore the original value 
  4776. of the built-in variable do_fortran_indexing even if an error occurs while 
  4777. performing the indexing operation. 
  4778.  
  4779. save_do_fortran_indexing = do_fortran_indexing;
  4780. unwind_protect
  4781.   do_fortran_indexing = 1;
  4782.   elt = a (idx)
  4783. unwind_protect_cleanup
  4784.   do_fortran_indexing = save_do_fortran_indexing;
  4785. end_unwind_protect
  4786.  
  4787. Without unwind_protect, the value of do_fortran_indexing would not be restored 
  4788. if an error occurs while performing the indexing operation because evaluation 
  4789. would stop at the point of the error and the statement to restore the value 
  4790. would not be executed. 
  4791.  
  4792.  
  4793. ΓòÉΓòÉΓòÉ 13.8. The try Statement ΓòÉΓòÉΓòÉ
  4794.  
  4795. In addition to unwind_protect, Octave supports another limited form of 
  4796. exception handling. 
  4797.  
  4798. The general form of a try block looks like this: 
  4799.  
  4800. try
  4801.   body
  4802. catch
  4803.   cleanup
  4804. end_try_catch
  4805.  
  4806. Where body and cleanup are both optional and may contain any Octave expressions 
  4807. or commands.  The statements in cleanup are only executed if an error occurs in 
  4808. body. 
  4809.  
  4810. No warnings or error messages are printed while body is executing.  If an error 
  4811. does occur during the execution of body, cleanup can access the text of the 
  4812. message that would have been printed in the builtin constant __error_text__. 
  4813. This is the same as eval (try, catch) (which may now also use __error_text__) 
  4814. but it is more efficient since the commands do not need to be parsed each time 
  4815. the try and catch statements are evaluated.  See Error Handling, for more 
  4816. information about the __error_text__ variable. 
  4817.  
  4818. Octave's try block is a very limited variation on the Lisp condition-case form 
  4819. (limited because it cannot handle different classes of errors separately). 
  4820. Perhaps at some point Octave can have some sort of classification of errors and 
  4821. try-catch can be improved to be as powerful as condition-case in Lisp. 
  4822.  
  4823.  
  4824. ΓòÉΓòÉΓòÉ 13.9. Continuation Lines ΓòÉΓòÉΓòÉ
  4825.  
  4826. In the Octave language, most statements end with a newline character and you 
  4827. must tell Octave to ignore the newline character in order to continue a 
  4828. statement from one line to the next.  Lines that end with the characters ... or 
  4829. \ are joined with the following line before they are divided into tokens by 
  4830. Octave's parser.  For example, the lines 
  4831.  
  4832. x = long_variable_name ...
  4833.     + longer_variable_name \
  4834.     - 42
  4835.  
  4836. form a single statement.  The backslash character on the second line above is 
  4837. interpreted a continuation character, not as a division operator. 
  4838.  
  4839. For continuation lines that do not occur inside string constants, whitespace 
  4840. and comments may appear between the continuation marker and the newline 
  4841. character.  For example, the statement 
  4842.  
  4843. x = long_variable_name ...     # comment one
  4844.     + longer_variable_name \   # comment two
  4845.     - 42                       # last comment
  4846.  
  4847. is equivalent to the one shown above.  Inside string constants, the 
  4848. continuation marker must appear at the end of the line just before the newline 
  4849. character. 
  4850.  
  4851. Input that occurs inside parentheses can be continued to the next line without 
  4852. having to use a continuation marker.  For example, it is possible to write 
  4853. statements like 
  4854.  
  4855. if (fine_dining_destination == on_a_boat
  4856.     || fine_dining_destination == on_a_train)
  4857.   suess (i, will, not, eat, them, sam, i, am, i,
  4858.          will, not, eat, green, eggs, and, ham);
  4859. endif
  4860.  
  4861. without having to add to the clutter with continuation markers. 
  4862.  
  4863.  
  4864. ΓòÉΓòÉΓòÉ 14. Functions and Script Files ΓòÉΓòÉΓòÉ
  4865.  
  4866. Complicated Octave programs can often be simplified by defining functions. 
  4867. Functions can be defined directly on the command line during interactive Octave 
  4868. sessions, or in external files, and can be called just like built-in functions. 
  4869.  
  4870.  Defining Functions 
  4871.  Multiple Return Values 
  4872.  Variable-length Argument Lists 
  4873.  Variable-length Return Lists 
  4874.  Returning From a Function 
  4875.  Function Files 
  4876.  Script Files 
  4877.  Dynamically Linked Functions 
  4878.  Organization of Functions 
  4879.  
  4880.  
  4881. ΓòÉΓòÉΓòÉ 14.1. Defining Functions ΓòÉΓòÉΓòÉ
  4882.  
  4883. In its simplest form, the definition of a function named name looks like this: 
  4884.  
  4885. function name
  4886.   body
  4887. endfunction
  4888.  
  4889. A valid function name is like a valid variable name: a sequence of letters, 
  4890. digits and underscores, not starting with a digit.  Functions share the same 
  4891. pool of names as variables. 
  4892.  
  4893. The function body consists of Octave statements.  It is the most important part 
  4894. of the definition, because it says what the function should actually do. 
  4895.  
  4896. For example, here is a function that, when executed, will ring the bell on your 
  4897. terminal (assuming that it is possible to do so): 
  4898.  
  4899. function wakeup
  4900.   printf ("\a");
  4901. endfunction
  4902.  
  4903. The printf statement (see Input and Output) simply tells Octave to print the 
  4904. string "\a".  The special character `\a' stands for the alert character (ASCII 
  4905. 7).  See Strings. 
  4906.  
  4907. Once this function is defined, you can ask Octave to evaluate it by typing the 
  4908. name of the function. 
  4909.  
  4910. Normally, you will want to pass some information to the functions you define. 
  4911. The syntax for passing parameters to a function in Octave is 
  4912.  
  4913. function name (arg-list)
  4914.   body
  4915. endfunction
  4916.  
  4917. where arg-list is a comma-separated list of the function's arguments.  When the 
  4918. function is called, the argument names are used to hold the argument values 
  4919. given in the call.  The list of arguments may be empty, in which case this form 
  4920. is equivalent to the one shown above. 
  4921.  
  4922. To print a message along with ringing the bell, you might modify the beep to 
  4923. look like this: 
  4924.  
  4925. function wakeup (message)
  4926.   printf ("\a%s\n", message);
  4927. endfunction
  4928.  
  4929. Calling this function using a statement like this 
  4930.  
  4931. wakeup ("Rise and shine!");
  4932.  
  4933. will cause Octave to ring your terminal's bell and print the message `Rise and 
  4934. shine!', followed by a newline character (the `\n' in the first argument to the 
  4935. printf statement). 
  4936.  
  4937. In most cases, you will also want to get some information back from the 
  4938. functions you define.  Here is the syntax for writing a function that returns a 
  4939. single value: 
  4940.  
  4941. function ret-var = name (arg-list)
  4942.   body
  4943. endfunction
  4944.  
  4945. The symbol ret-var is the name of the variable that will hold the value to be 
  4946. returned by the function.  This variable must be defined before the end of the 
  4947. function body in order for the function to return a value. 
  4948.  
  4949. Variables used in the body of a function are local to the function.  Variables 
  4950. named in arg-list and ret-var are also local to the function.  See Global 
  4951. Variables, for information about how to access global variables inside a 
  4952. function. 
  4953.  
  4954. For example, here is a function that computes the average of the elements of a 
  4955. vector: 
  4956.  
  4957. function retval = avg (v)
  4958.   retval = sum (v) / length (v);
  4959. endfunction
  4960.  
  4961. If we had written avg like this instead, 
  4962.  
  4963. function retval = avg (v)
  4964.   if (is_vector (v))
  4965.     retval = sum (v) / length (v);
  4966.   endif
  4967. endfunction
  4968.  
  4969. and then called the function with a matrix instead of a vector as the argument, 
  4970. Octave would have printed an error message like this: 
  4971.  
  4972. error: `retval' undefined near line 1 column 10
  4973. error: evaluating index expression near line 7, column 1
  4974.  
  4975. because the body of the if statement was never executed, and retval was never 
  4976. defined.  To prevent obscure errors like this, it is a good idea to always make 
  4977. sure that the return variables will always have values, and to produce 
  4978. meaningful error messages when problems are encountered.  For example, avg 
  4979. could have been written like this: 
  4980.  
  4981. function retval = avg (v)
  4982.   retval = 0;
  4983.   if (is_vector (v))
  4984.     retval = sum (v) / length (v);
  4985.   else
  4986.     error ("avg: expecting vector argument");
  4987.   endif
  4988. endfunction
  4989.  
  4990. There is still one additional problem with this function.  What if it is called 
  4991. without an argument?  Without additional error checking, Octave will probably 
  4992. print an error message that won't really help you track down the source of the 
  4993. error.  To allow you to catch errors like this, Octave provides each function 
  4994. with an automatic variable called nargin.  Each time a function is called, 
  4995. nargin is automatically initialized to the number of arguments that have 
  4996. actually been passed to the function.  For example, we might rewrite the avg 
  4997. function like this: 
  4998.  
  4999. function retval = avg (v)
  5000.   retval = 0;
  5001.   if (nargin != 1)
  5002.     usage ("avg (vector)");
  5003.   endif
  5004.   if (is_vector (v))
  5005.     retval = sum (v) / length (v);
  5006.   else
  5007.     error ("avg: expecting vector argument");
  5008.   endif
  5009. endfunction
  5010.  
  5011. Although Octave does not automatically report an error if you call a function 
  5012. with more arguments than expected, doing so probably indicates that something 
  5013. is wrong.  Octave also does not automatically report an error if a function is 
  5014. called with too few arguments, but any attempt to use a variable that has not 
  5015. been given a value will result in an error. To avoid such problems and to 
  5016. provide useful messages, we check for both possibilities and issue our own 
  5017. error message. 
  5018.  
  5019. Automatic Variable: nargin 
  5020. When a function is called, this local variable is automatically initialized to 
  5021. the number of arguments passed to the function.  At the top level, nargin holds 
  5022. the number of command line arguments that were passed to Octave. 
  5023.  
  5024. Built-in Variable: silent_functions 
  5025. If the value of silent_functions is nonzero, internal output from a function is 
  5026. suppressed.  Otherwise, the results of expressions within a function body that 
  5027. are not terminated with a semicolon will have their values printed.  The 
  5028. default value is 0. 
  5029.  
  5030. For example, if the function 
  5031.  
  5032. function f ()
  5033.   2 + 2
  5034. endfunction
  5035.  
  5036. is executed, Octave will either print `ans = 4' or nothing depending on the 
  5037. value of silent_functions. 
  5038.  
  5039. Built-in Variable: warn_missing_semicolon 
  5040. If the value of this variable is nonzero, Octave will warn when statements in 
  5041. function definitions don't end in semicolons.  The default value is 0. 
  5042.  
  5043.  
  5044. ΓòÉΓòÉΓòÉ 14.2. Multiple Return Values ΓòÉΓòÉΓòÉ
  5045.  
  5046. Unlike many other computer languages, Octave allows you to define functions 
  5047. that return more than one value.  The syntax for defining functions that return 
  5048. multiple values is 
  5049.  
  5050. function [ret-list] = name (arg-list)
  5051.   body
  5052. endfunction
  5053.  
  5054. where name, arg-list, and body have the same meaning as before, and ret-list is 
  5055. a comma-separated list of variable names that will hold the values returned 
  5056. from the function.  The list of return values must have at least one element. 
  5057. If ret-list has only one element, this form of the function statement is 
  5058. equivalent to the form described in the previous section. 
  5059.  
  5060. Here is an example of a function that returns two values, the maximum element 
  5061. of a vector and the index of its first occurrence in the vector. 
  5062.  
  5063. function [max, idx] = vmax (v)
  5064.   idx = 1;
  5065.   max = v (idx);
  5066.   for i = 2:length (v)
  5067.     if (v (i) > max)
  5068.       max = v (i);
  5069.       idx = i;
  5070.     endif
  5071.   endfor
  5072. endfunction
  5073.  
  5074. In this particular case, the two values could have been returned as elements of 
  5075. a single array, but that is not always possible or convenient.  The values to 
  5076. be returned may not have compatible dimensions, and it is often desirable to 
  5077. give the individual return values distinct names. 
  5078.  
  5079. In addition to setting nargin each time a function is called, Octave also 
  5080. automatically initializes nargout to the number of values that are expected to 
  5081. be returned.  This allows you to write functions that behave differently 
  5082. depending on the number of values that the user of the function has requested. 
  5083. The implicit assignment to the built-in variable ans does not figure in the 
  5084. count of output arguments, so the value of nargout may be zero. 
  5085.  
  5086. The svd and lu functions are examples of built-in functions that behave 
  5087. differently depending on the value of nargout. 
  5088.  
  5089. It is possible to write functions that only set some return values.  For 
  5090. example, calling the function 
  5091.  
  5092. function [x, y, z] = f ()
  5093.   x = 1;
  5094.   z = 2;
  5095. endfunction
  5096.  
  5097. as 
  5098.  
  5099. [a, b, c] = f ()
  5100.  
  5101. produces: 
  5102.  
  5103. a = 1
  5104.  
  5105. b = [](0x0)
  5106.  
  5107. c = 2
  5108.  
  5109. provided that the built-in variable define_all_return_values is nonzero and the 
  5110. value of default_return_value is `[]'. See Summary of Built-in Variables. 
  5111.  
  5112. Automatic Variable: nargout 
  5113. When a function is called, this local variable is automatically initialized to 
  5114. the number of arguments expected to be returned.  For example, 
  5115.  
  5116. f ()
  5117.  
  5118. will result in nargout being set to 0 inside the function f and 
  5119.  
  5120. [s, t] = f ()
  5121.  
  5122. will result in nargout being set to 2 inside the function f. 
  5123.  
  5124. At the top level, nargout is undefined. 
  5125.  
  5126. Built-in Variable: default_return_value 
  5127. The value given to otherwise uninitialized return values if 
  5128. define_all_return_values is nonzero.  The default value is []. 
  5129.  
  5130. Built-in Variable: define_all_return_values 
  5131. If the value of define_all_return_values is nonzero, Octave will substitute the 
  5132. value specified by default_return_value for any return values that remain 
  5133. undefined when a function returns.  The default value is 0. 
  5134.  
  5135. Function File:  nargchk (nargin_min, nargin_max, n) 
  5136. If n is in the range nargin_min through nargin_max inclusive, return the empty 
  5137. matrix.  Otherwise, return a message indicating whether n is too large or too 
  5138. small. 
  5139.  
  5140. This is useful for checking to see that the number of arguments supplied to a 
  5141. function is within an acceptable range. 
  5142.  
  5143.  
  5144. ΓòÉΓòÉΓòÉ 14.3. Variable-length Argument Lists ΓòÉΓòÉΓòÉ
  5145.  
  5146. Octave has a real mechanism for handling functions that take an unspecified 
  5147. number of arguments, so it is not necessary to place an upper bound on the 
  5148. number of optional arguments that a function can accept. 
  5149.  
  5150. Here is an example of a function that uses the new syntax to print a header 
  5151. followed by an unspecified number of values: 
  5152.  
  5153. function foo (heading, ...)
  5154.   disp (heading);
  5155.   va_start ();
  5156.   ## Pre-decrement to skip `heading' arg.
  5157.   while (--nargin)
  5158.     disp (va_arg ());
  5159.   endwhile
  5160. endfunction
  5161.  
  5162. The ellipsis that marks the variable argument list may only appear once and 
  5163. must be the last element in the list of arguments. 
  5164.  
  5165. Built-in Function:  va_start () 
  5166. Position an internal pointer to the first unnamed argument and allows you to 
  5167. cycle through the arguments more than once.  It is not necessary to call 
  5168. va_start if you do not plan to cycle through the arguments more than once. 
  5169. This function may only be called inside functions that have been declared to 
  5170. accept a variable number of input arguments. 
  5171.  
  5172. Built-in Function:  va_arg () 
  5173. Return the value of the next available argument and move the internal pointer 
  5174. to the next argument.  It is an error to call va_arg() when there are no more 
  5175. arguments available. 
  5176.  
  5177. Sometimes it is useful to be able to pass all unnamed arguments to another 
  5178. function.  The keyword all_va_args makes this very easy to do.  For example, 
  5179.  
  5180. function f (...)
  5181.   while (nargin--)
  5182.     disp (va_arg ())
  5183.   endwhile
  5184. endfunction
  5185.  
  5186. function g (...)
  5187.   f ("begin", all_va_args, "end")
  5188. endfunction
  5189.  
  5190. g (1, 2, 3)
  5191.  
  5192.      -| begin
  5193.      -| 1
  5194.      -| 2
  5195.      -| 3
  5196.      -| end
  5197.  
  5198. Keyword: all_va_args 
  5199. This keyword stands for the entire list of optional argument, so it is possible 
  5200. to use it more than once within the same function without having to call 
  5201. va_start.  It can only be used within functions that take a variable number of 
  5202. arguments.  It is an error to use it in other contexts. 
  5203.  
  5204.  
  5205. ΓòÉΓòÉΓòÉ 14.4. Variable-length Return Lists ΓòÉΓòÉΓòÉ
  5206.  
  5207. Octave also has a real mechanism for handling functions that return an 
  5208. unspecified number of values, so it is no longer necessary to place an upper 
  5209. bound on the number of outputs that a function can produce. 
  5210.  
  5211. Here is an example of a function that uses a variable-length return list to 
  5212. produce n values: 
  5213.  
  5214. function [...] = f (n, x)
  5215.   for i = 1:n
  5216.     vr_val (i * x);
  5217.   endfor
  5218. endfunction
  5219.  
  5220. [dos, quatro] = f (2, 2)
  5221.      => dos = 2
  5222.      => quatro = 4
  5223.  
  5224. As with variable argument lists, the ellipsis that marks the variable return 
  5225. list may only appear once and must be the last element in the list of returned 
  5226. values. 
  5227.  
  5228. Built-in Function:  vr_val (val) 
  5229. Each time this function is called, it places the value of its argument at the 
  5230. end of the list of values to return from the current function. Once vr_val has 
  5231. been called, there is no way to go back to the beginning of the list and 
  5232. rewrite any of the return values.  This function may only be called within 
  5233. functions that have been declared to return an unspecified number of output 
  5234. arguments (by using the special ellipsis notation described above). 
  5235.  
  5236.  
  5237. ΓòÉΓòÉΓòÉ 14.5. Returning From a Function ΓòÉΓòÉΓòÉ
  5238.  
  5239. The body of a user-defined function can contain a return statement. This 
  5240. statement returns control to the rest of the Octave program.  It looks like 
  5241. this: 
  5242.  
  5243. return
  5244.  
  5245. Unlike the return statement in C, Octave's return statement cannot be used to 
  5246. return a value from a function.  Instead, you must assign values to the list of 
  5247. return variables that are part of the function statement.  The return statement 
  5248. simply makes it easier to exit a function from a deeply nested loop or 
  5249. conditional statement. 
  5250.  
  5251. Here is an example of a function that checks to see if any elements of a vector 
  5252. are nonzero. 
  5253.  
  5254. function retval = any_nonzero (v)
  5255.   retval = 0;
  5256.   for i = 1:length (v)
  5257.     if (v (i) != 0)
  5258.       retval = 1;
  5259.       return;
  5260.     endif
  5261.   endfor
  5262.   printf ("no nonzero elements found\n");
  5263. endfunction
  5264.  
  5265. Note that this function could not have been written using the break statement 
  5266. to exit the loop once a nonzero value is found without adding extra logic to 
  5267. avoid printing the message if the vector does contain a nonzero element. 
  5268.  
  5269. Keyword: return 
  5270. When Octave encounters the keyword return inside a function or script, it 
  5271. returns control to be caller immediately.  At the top level, the return 
  5272. statement is ignored.  A return statement is assumed at the end of every 
  5273. function definition. 
  5274.  
  5275. Built-in Variable: return_last_computed_value 
  5276. If the value of return_last_computed_value is true, and a function is defined 
  5277. without explicitly specifying a return value, the function will return the 
  5278. value of the last expression.  Otherwise, no value will be returned.  The 
  5279. default value is 0. 
  5280.  
  5281. For example, the function 
  5282.  
  5283. function f ()
  5284.   2 + 2;
  5285. endfunction
  5286.  
  5287. will either return nothing, if the value of return_last_computed_value is 0, or 
  5288. 4, if the value of return_last_computed_value is nonzero. 
  5289.  
  5290.  
  5291. ΓòÉΓòÉΓòÉ 14.6. Function Files ΓòÉΓòÉΓòÉ
  5292.  
  5293. Except for simple one-shot programs, it is not practical to have to define all 
  5294. the functions you need each time you need them.  Instead, you will normally 
  5295. want to save them in a file so that you can easily edit them, and save them for 
  5296. use at a later time. 
  5297.  
  5298. Octave does not require you to load function definitions from files before 
  5299. using them.  You simply need to put the function definitions in a place where 
  5300. Octave can find them. 
  5301.  
  5302. When Octave encounters an identifier that is undefined, it first looks for 
  5303. variables or functions that are already compiled and currently listed in its 
  5304. symbol table.  If it fails to find a definition there, it searches the list of 
  5305. directories specified by the built-in variable LOADPATH for files ending in 
  5306. `.m' that have the same base name as the undefined identifier.(4)  Once Octave 
  5307. finds a file with a name that matches, the contents of the file are read.  If 
  5308. it defines a single function, it is compiled and executed. See Script Files, 
  5309. for more information about how you can define more than one function in a 
  5310. single file. 
  5311.  
  5312. When Octave defines a function from a function file, it saves the full name of 
  5313. the file it read and the time stamp on the file.  After that, it checks the 
  5314. time stamp on the file every time it needs the function.  If the time stamp 
  5315. indicates that the file has changed since the last time it was read, Octave 
  5316. reads it again. 
  5317.  
  5318. Checking the time stamp allows you to edit the definition of a function while 
  5319. Octave is running, and automatically use the new function definition without 
  5320. having to restart your Octave session.  Checking the time stamp every time a 
  5321. function is used is rather inefficient, but it has to be done to ensure that 
  5322. the correct function definition is used. 
  5323.  
  5324. To avoid degrading performance unnecessarily by checking the time stamps on 
  5325. functions that are not likely to change, Octave assumes that function files in 
  5326. the directory tree `octave-home/share/octave/version/m' will not change, so it 
  5327. doesn't have to check their time stamps every time the functions defined in 
  5328. those files are used.  This is normally a very good assumption and provides a 
  5329. significant improvement in performance for the function files that are 
  5330. distributed with Octave. 
  5331.  
  5332. If you know that your own function files will not change while you are running 
  5333. Octave, you can improve performance by setting the variable 
  5334. ignore_function_time_stamp to "all", so that Octave will ignore the time stamps 
  5335. for all function files.  Setting it to "system" gives the default behavior.  If 
  5336. you set it to anything else, Octave will check the time stamps on all function 
  5337. files. 
  5338.  
  5339. Built-in Variable: DEFAULT_LOADPATH 
  5340. A colon separated list of directories in which to search for function files by 
  5341. default.  The value of this variable is also automatically substituted for 
  5342. leading, trailing, or doubled colons that appear in the built-in variable 
  5343. LOADPATH. 
  5344.  
  5345. Built-in Variable: LOADPATH 
  5346. A colon separated list of directories in which to search for function files. 
  5347. See Functions and Scripts.  The value of LOADPATH overrides the environment 
  5348. variable OCTAVE_PATH.  See Installation. 
  5349.  
  5350. LOADPATH is now handled in the same way as TeX handles TEXINPUTS.  Leading, 
  5351. trailing, or doubled colons that appear in LOADPATH are replaced by the value 
  5352. of DEFAULT_LOADPATH. The default value of LOADPATH is ":", which tells Octave 
  5353. to search in the directories specified by DEFAULT_LOADPATH. 
  5354.  
  5355. In addition, if any path element ends in `//', that directory and all 
  5356. subdirectories it contains are searched recursively for function files.  This 
  5357. can result in a slight delay as Octave caches the lists of files found in the 
  5358. LOADPATH the first time Octave searches for a function.  After that, searching 
  5359. is usually much faster because Octave normally only needs to search its 
  5360. internal cache for files. 
  5361.  
  5362. To improve performance of recursive directory searching, it is best for each 
  5363. directory that is to be searched recursively to contain either additional 
  5364. subdirectories or function files, but not a mixture of both. 
  5365.  
  5366. See Organization of Functions for a description of the function file 
  5367. directories that are distributed with Octave. 
  5368.  
  5369. Built-in Variable: ignore_function_time_stamp 
  5370. This variable can be used to prevent Octave from making the system call stat 
  5371. each time it looks up functions defined in function files. If 
  5372. ignore_function_time_stamp to "system", Octave will not automatically recompile 
  5373. function files in subdirectories of `octave-home/lib/version' if they have 
  5374. changed since they were last compiled, but will recompile other function files 
  5375. in the LOADPATH if they change.  If set to "all", Octave will not recompile any 
  5376. function files unless their definitions are removed with clear.  For any other 
  5377. value of ignore_function_time_stamp, Octave will always check to see if 
  5378. functions defined in function files need to recompiled.  The default value of 
  5379. ignore_function_time_stamp is "system". 
  5380.  
  5381. Built-in Variable: warn_function_name_clash 
  5382. If the value of warn_function_name_clash is nonzero, a warning is issued when 
  5383. Octave finds that the name of a function defined in a function file differs 
  5384. from the name of the file.  (If the names disagree, the name declared inside 
  5385. the file is ignored.)  If the value is 0, the warning is omitted.  The default 
  5386. value is 1. 
  5387.  
  5388.  
  5389. ΓòÉΓòÉΓòÉ 14.7. Script Files ΓòÉΓòÉΓòÉ
  5390.  
  5391. A script file is a file containing (almost) any sequence of Octave commands. 
  5392. It is read and evaluated just as if you had typed each command at the Octave 
  5393. prompt, and provides a convenient way to perform a sequence of commands that do 
  5394. not logically belong inside a function. 
  5395.  
  5396. Unlike a function file, a script file must not begin with the keyword function. 
  5397. If it does, Octave will assume that it is a function file, and that it defines 
  5398. a single function that should be evaluated as soon as it is defined. 
  5399.  
  5400. A script file also differs from a function file in that the variables named in 
  5401. a script file are not local variables, but are in the same scope as the other 
  5402. variables that are visible on the command line. 
  5403.  
  5404. Even though a script file may not begin with the function keyword, it is 
  5405. possible to define more than one function in a single script file and load (but 
  5406. not execute) all of them at once.  To do this, the first token in the file 
  5407. (ignoring comments and other white space) must be something other than 
  5408. function.  If you have no other statements to evaluate, you can use a statement 
  5409. that has no effect, like this: 
  5410.  
  5411. # Prevent Octave from thinking that this
  5412. # is a function file:
  5413.  
  5414. 1;
  5415.  
  5416. # Define function one:
  5417.  
  5418. function one ()
  5419.   ...
  5420.  
  5421. To have Octave read and compile these functions into an internal form, you need 
  5422. to make sure that the file is in Octave's LOADPATH, then simply type the base 
  5423. name of the file that contains the commands. (Octave uses the same rules to 
  5424. search for script files as it does to search for function files.) 
  5425.  
  5426. If the first token in a file (ignoring comments) is function, Octave will 
  5427. compile the function and try to execute it, printing a message warning about 
  5428. any non-whitespace characters that appear after the function definition. 
  5429.  
  5430. Note that Octave does not try to look up the definition of any identifier until 
  5431. it needs to evaluate it.  This means that Octave will compile the following 
  5432. statements if they appear in a script file, or are typed at the command line, 
  5433.  
  5434. # not a function file:
  5435. 1;
  5436. function foo ()
  5437.   do_something ();
  5438. endfunction
  5439. function do_something ()
  5440.   do_something_else ();
  5441. endfunction
  5442.  
  5443. even though the function do_something is not defined before it is referenced in 
  5444. the function foo.  This is not an error because Octave does not need to resolve 
  5445. all symbols that are referenced by a function until the function is actually 
  5446. evaluated. 
  5447.  
  5448. Since Octave doesn't look for definitions until they are needed, the following 
  5449. code will always print `bar = 3' whether it is typed directly on the command 
  5450. line, read from a script file, or is part of a function body, even if there is 
  5451. a function or script file called `bar.m' in Octave's LOADPATH. 
  5452.  
  5453. eval ("bar = 3");
  5454. bar
  5455.  
  5456. Code like this appearing within a function body could fool Octave if 
  5457. definitions were resolved as the function was being compiled.  It would be 
  5458. virtually impossible to make Octave clever enough to evaluate this code in a 
  5459. consistent fashion.  The parser would have to be able to perform the call to 
  5460. eval at compile time, and that would be impossible unless all the references in 
  5461. the string to be evaluated could also be resolved, and requiring that would be 
  5462. too restrictive (the string might come from user input, or depend on things 
  5463. that are not known until the function is evaluated). 
  5464.  
  5465. Although Octave normally executes commands from script files that have the name 
  5466. `file.m', you can use the function source to execute commands from any file. 
  5467.  
  5468. Built-in Function:  source (file) 
  5469. Parse and execute the contents of file.  This is equivalent to executing 
  5470. commands from a script file, but without requiring the file to be named 
  5471. `file.m'. 
  5472.  
  5473.  
  5474. ΓòÉΓòÉΓòÉ 14.8. Dynamically Linked Functions ΓòÉΓòÉΓòÉ
  5475.  
  5476. On some systems, Octave can dynamically load and execute functions written in 
  5477. C++.  Octave can only directly call functions written in C++, but you can also 
  5478. load functions written in other languages by calling them from a simple wrapper 
  5479. function written in C++. 
  5480.  
  5481. Here is an example of how to write a C++ function that Octave can load, with 
  5482. commentary.  The source for this function is included in the source 
  5483. distributions of Octave, in the file `examples/oregonator.cc'.  It defines the 
  5484. same set of differential equations that are used in the example problem of 
  5485. Ordinary Differential Equations.  By running that example and this one, we can 
  5486. compare the execution times to see what sort of increase in speed you can 
  5487. expect by using dynamically linked functions. 
  5488.  
  5489. The function defined in `oregonator.cc' contains just 8 statements, and is not 
  5490. much different than the code defined in the corresponding M-file (also 
  5491. distributed with Octave in the file `examples/oregonator.m'). 
  5492.  
  5493. Here is the complete text of `oregonator.cc': 
  5494.  
  5495. just 
  5496.  
  5497. #include <octave/oct.h>
  5498.  
  5499. DEFUN_DLD (oregonator, args, ,
  5500.   "The `oregonator'.")
  5501. {
  5502.   ColumnVector dx (3);
  5503.  
  5504.   ColumnVector x = args(0).vector_value ();
  5505.  
  5506.   dx(0) = 77.27 * (x(1) - x(0)*x(1) + x(0)
  5507.                    - 8.375e-06*pow (x(0), 2));
  5508.  
  5509.   dx(1) = (x(2) - x(0)*x(1) - x(1)) / 77.27;
  5510.  
  5511.   dx(2) = 0.161*(x(0) - x(2));
  5512.  
  5513.   return octave_value (dx);
  5514. }
  5515.  
  5516. The first line of the file, 
  5517.  
  5518. #include <octave/oct.h>
  5519.  
  5520. includes declarations for all of Octave's internal functions that you will 
  5521. need.  If you need other functions from the standard C++ or C libraries, you 
  5522. can include the necessary headers here. 
  5523.  
  5524. The next two lines 
  5525.  
  5526. DEFUN_DLD (oregonator, args, ,
  5527.   "The `oregonator'.")
  5528.  
  5529. declares the function.  The macro DEFUN_DLD and the macros that it depends on 
  5530. are defined in the files `defun-dld.h', `defun.h', and `defun-int.h' (these 
  5531. files are included in the header file `octave/oct.h'). 
  5532.  
  5533. Note that the third parameter to DEFUN_DLD (nargout) is not used, so it is 
  5534. omitted from the list of arguments to in order to avoid  the warning from gcc 
  5535. about an unused function parameter. 
  5536.  
  5537. simply declares an object to store the right hand sides of the differential 
  5538. equation, and 
  5539.  
  5540. The statement 
  5541.  
  5542. ColumnVector x = args(0).vector_value ();
  5543.  
  5544. extracts a column vector from the input arguments.  The variable args is passed 
  5545. to functions defined with DEFUN_DLD as an octave_value_list object, which 
  5546. includes methods for getting the length of the list and extracting individual 
  5547. elements. 
  5548.  
  5549. In this example, we don't check for errors, but that is not difficult. All of 
  5550. the Octave's built-in functions do some form of checking on their arguments, so 
  5551. you can check the source code for those functions for examples of various 
  5552. strategies for verifying that the correct number and types of arguments have 
  5553. been supplied. 
  5554.  
  5555. The next statements 
  5556.  
  5557. ColumnVector dx (3);
  5558.  
  5559. dx(0) = 77.27 * (x(1) - x(0)*x(1) + x(0)
  5560.                  - 8.375e-06*pow (x(0), 2));
  5561.  
  5562. dx(1) = (x(2) - x(0)*x(1) - x(1)) / 77.27;
  5563.  
  5564. dx(2) = 0.161*(x(0) - x(2));
  5565.  
  5566. define the right hand side of the differential equation.  Finally, we can 
  5567. return dx: 
  5568.  
  5569. return octave_value (dx);
  5570.  
  5571. The actual return type is octave_value_list, but it is only necessary to 
  5572. convert the return type to an octave_value because there is a default 
  5573. constructor that can automatically create an object of that type from an 
  5574. octave_value object, so we can just use that instead. 
  5575.  
  5576. To use this file, your version of Octave must support dynamic linking. To find 
  5577. out if it does, type the command octave_config_info ("dld") at the Octave 
  5578. prompt.  Support for dynamic linking is included if this command returns 1. 
  5579.  
  5580. To compile the example file, type the command `mkoctfile oregonator.cc' at the 
  5581. shell prompt.  The script mkoctfile should have been installed along with 
  5582. Octave.  Running it will create a file called `oregonator.oct' that can be 
  5583. loaded by Octave.  To test the `oregonator.oct' file, start Octave and type the 
  5584. command 
  5585.  
  5586. oregonator ([1, 2, 3], 0)
  5587.  
  5588. at the Octave prompt.  Octave should respond by printing 
  5589.  
  5590. ans =
  5591.  
  5592.    77.269353
  5593.    -0.012942
  5594.    -0.322000
  5595.  
  5596. You can now use the `oregonator.oct' file just as you would the oregonator.m 
  5597. file to solve the set of differential equations. 
  5598.  
  5599. On a 133 MHz Pentium running Linux, Octave can solve the problem shown in 
  5600. Ordinary Differential Equations in about 1.4 second using the dynamically 
  5601. linked function, compared to about 19 seconds using the M-file.  Similar 
  5602. decreases in execution time can be expected for other functions, particularly 
  5603. those that rely on functions like lsode that require user-supplied functions. 
  5604.  
  5605. Just as for M-files, Octave will automatically reload dynamically linked 
  5606. functions when the files that define them are more recent than the last time 
  5607. that the function was loaded.  Two variables are available to control how 
  5608. Octave behaves when dynamically linked functions are cleared or reloaded. 
  5609.  
  5610. Built-in Variable: auto_unload_dot_oct_files 
  5611. If the value of auto_unload_dot_oct_files is nonzero, Octave will automatically 
  5612. unload any `.oct' files when there are no longer any functions in the symbol 
  5613. table that reference them. 
  5614.  
  5615. Built-in Variable: warn_reload_forces_clear 
  5616. If several functions have been loaded from the same file, Octave must clear all 
  5617. the functions before any one of them can be reloaded.  If 
  5618. warn_reload_forces_clear, Octave will warn you when this happens, and print a 
  5619. list of the additional functions that it is forced to clear. 
  5620.  
  5621. Additional examples for writing dynamically linked functions are available in 
  5622. the files in the `src' directory of the Octave distribution.  Currently, this 
  5623. includes the files 
  5624.  
  5625. balance.cc   fft2.cc      inv.cc       qzval.cc
  5626. chol.cc      filter.cc    log.cc       schur.cc
  5627. colloc.cc    find.cc      lsode.cc     sort.cc
  5628. dassl.cc     fsolve.cc    lu.cc        svd.cc
  5629. det.cc       givens.cc    minmax.cc    syl.cc
  5630. eig.cc       hess.cc      pinv.cc
  5631. expm.cc      ifft.cc      qr.cc
  5632. fft.cc       ifft2.cc     quad.cc
  5633.  
  5634. These files use the macro DEFUN_DLD_BUILTIN instead of DEFUN_DLD.  The 
  5635. difference between these two macros is just that DEFUN_DLD_BUILTIN can define a 
  5636. built-in function that is not dynamically loaded if the operating system does 
  5637. not support dynamic linking.  To define your own dynamically linked functions 
  5638. you should use DEFUN_DLD. 
  5639.  
  5640. There is currently no detailed description of all the functions that you can 
  5641. call in a built-in function.  For the time being, you will have to read the 
  5642. source code for Octave. 
  5643.  
  5644.  
  5645. ΓòÉΓòÉΓòÉ 14.9. Organization of Functions Distributed with Octave ΓòÉΓòÉΓòÉ
  5646.  
  5647. Many of Octave's standard functions are distributed as function files. They are 
  5648. loosely organized by topic, in subdirectories of 
  5649. `octave-home/lib/octave/version/m', to make it easier to find them. 
  5650.  
  5651. The following is a list of all the function file subdirectories, and the types 
  5652. of functions you will find there. 
  5653.  
  5654.  `audio' 
  5655.            Functions for playing and recording sounds. 
  5656.  
  5657.  `control' 
  5658.            Functions for design and simulation of automatic control systems. 
  5659.  
  5660.  `elfun' 
  5661.            Elementary functions. 
  5662.  
  5663.  `general' 
  5664.            Miscellaneous matrix manipulations, like flipud, rot90, and triu, as 
  5665.            well as other basic functions, like is_matrix, nargchk, etc. 
  5666.  
  5667.  `image' 
  5668.            Image processing tools.  These functions require the X Window 
  5669.            System. 
  5670.  
  5671.  `io' 
  5672.            Input-ouput functions. 
  5673.  
  5674.  `linear-algebra' 
  5675.            Functions for linear algebra. 
  5676.  
  5677.  `miscellaneous' 
  5678.            Functions that don't really belong anywhere else. 
  5679.  
  5680.  `plot' 
  5681.            A set of functions that implement the Matlab-like plotting 
  5682.            functions. 
  5683.  
  5684.  `polynomial' 
  5685.            Functions for manipulating polynomials. 
  5686.  
  5687.  `set' 
  5688.            Functions for creating and manipulating sets of unique values. 
  5689.  
  5690.  `signal' 
  5691.            Functions for signal processing applications. 
  5692.  
  5693.  `specfun' 
  5694.            Special functions. 
  5695.  
  5696.  `special-matrix' 
  5697.            Functions that create special matrix forms. 
  5698.  
  5699.  `startup' 
  5700.            Octave's system-wide startup file. 
  5701.  
  5702.  `statistics' 
  5703.            Statistical functions. 
  5704.  
  5705.  `strings' 
  5706.            Miscellaneous string-handling functions. 
  5707.  
  5708.  `time' 
  5709.            Functions related to time keeping. 
  5710.  
  5711.  
  5712. ΓòÉΓòÉΓòÉ 15. Error Handling ΓòÉΓòÉΓòÉ
  5713.  
  5714. Octave includes several functions for printing error and warning messages. 
  5715. When you write functions that need to take special action when they encounter 
  5716. abnormal conditions, you should print the error messages using the functions 
  5717. described in this chapter. 
  5718.  
  5719. Built-in Function:  error (template, ...) 
  5720. The error function formats the optional arguments under the control of the 
  5721. template string template using the same rules as the printf family of functions 
  5722. (see Formatted Output). The resulting message is prefixed by the string `error: 
  5723. ' and printed on the stderr stream. 
  5724.  
  5725. Calling error also sets Octave's internal error state such that control will 
  5726. return to the top level without evaluating any more commands.  This is useful 
  5727. for aborting from functions or scripts. 
  5728.  
  5729. If the error message does not end with a new line character, Octave will print 
  5730. a traceback of all the function calls leading to the error.  For example, given 
  5731. the following function definitions: 
  5732.  
  5733. function f () g () end
  5734. function g () h () end
  5735. function h () nargin == 1 || error ("nargin != 1"); end
  5736.  
  5737. calling the function f will result in a list of messages that can help you to 
  5738. quickly locate the exact location of the error: 
  5739.  
  5740. f ()
  5741. error: nargin != 1
  5742. error: evaluating index expression near line 1, column 30
  5743. error: evaluating binary operator `||' near line 1, column 27
  5744. error: called from `h'
  5745. error: called from `g'
  5746. error: called from `f'
  5747.  
  5748. If the error message ends in a new line character, Octave will print the 
  5749. message but will not display any traceback messages as it returns control to 
  5750. the top level.  For example, modifying the error message in the previous 
  5751. example to end in a new line causes Octave to only print a single message: 
  5752.  
  5753. function h () nargin == 1 || error ("nargin != 1\n"); end
  5754. f ()
  5755. error: nargin != 1
  5756.  
  5757. Built-in Variable: error_text 
  5758. This variable contains the text of error messages that would have been printed 
  5759. in the body of the most recent unwind_protect or try statement or the try part 
  5760. of the most recent call to the eval function.  Outside of the unwind_protect 
  5761. and try statements or the eval function, or if no error has occurred within 
  5762. them, the value of error_text is guaranteed to be the empty string. 
  5763.  
  5764. Note that the message does not include the first `error: ' prefix, so that it 
  5765. may easily be passed to the error function without additional processing(5). 
  5766.  
  5767. See The try Statement and The unwind_protect Statement. 
  5768.  
  5769. Built-in Variable: beep_on_error 
  5770. If the value of beep_on_error is nonzero, Octave will try to ring your 
  5771. terminal's bell before printing an error message.  The default value is 0. 
  5772.  
  5773. Built-in Function:  warning (msg) 
  5774. Print a warning message msg prefixed by the string `warning: '. After printing 
  5775. the warning message, Octave will continue to execute commands.  You should use 
  5776. this function should when you want to notify the user of an unusual condition, 
  5777. but only when it makes sense for your program to go on. 
  5778.  
  5779. Built-in Function:  usage (msg) 
  5780. Print the message msg, prefixed by the string `usage: ', and set Octave's 
  5781. internal error state such that control will return to the top level without 
  5782. evaluating any more commands.  This is useful for aborting from functions. 
  5783.  
  5784. After usage is evaluated, Octave will print a traceback of all the function 
  5785. calls leading to the usage message. 
  5786.  
  5787. You should use this function for reporting problems errors that result from an 
  5788. improper call to a function, such as calling a function with an incorrect 
  5789. number of arguments, or with arguments of the wrong type.  For example, most 
  5790. functions distributed with Octave begin with code like this 
  5791.  
  5792. if (nargin != 2)
  5793.   usage ("foo (a, b)");
  5794. endif
  5795.  
  5796. to check for the proper number of arguments. 
  5797.  
  5798. The following pair of functions are of limited usefulness, and may be removed 
  5799. from future versions of Octave. 
  5800.  
  5801. Function File:  perror (name, num) 
  5802. Print the error message for function name corresponding to the error number 
  5803. num.  This function is intended to be used to print useful error messages for 
  5804. those functions that return numeric error codes. 
  5805.  
  5806. Function File:  strerror (name, num) 
  5807. Return the text of an error message for function name corresponding to the 
  5808. error number num.  This function is intended to be used to print useful error 
  5809. messages for those functions that return numeric error codes. 
  5810.  
  5811.  
  5812. ΓòÉΓòÉΓòÉ 16. Input and Output ΓòÉΓòÉΓòÉ
  5813.  
  5814. There are two distinct classes of input and output functions.  The first set 
  5815. are modeled after the functions available in Matlab.  The second set are 
  5816. modeled after the standard I/O library used by the C programming language and 
  5817. offer more flexibility and control over the output. 
  5818.  
  5819. When running interactively, Octave normally sends any output intended for your 
  5820. terminal that is more than one screen long to a paging program, such as less or 
  5821. more.  This avoids the problem of having a large volume of output stream by 
  5822. before you can read it.  With less (and some versions of more) you can also 
  5823. scan forward and backward, and search for specific items. 
  5824.  
  5825. Normally, no output is displayed by the pager until just before Octave is ready 
  5826. to print the top level prompt, or read from the standard input (for example, by 
  5827. using the fscanf or scanf functions). This means that there may be some delay 
  5828. before any output appears on your screen if you have asked Octave to perform a 
  5829. significant amount of work with a single command statement.  The function 
  5830. fflush may be used to force output to be sent to the pager (or any other 
  5831. stream) immediately. 
  5832.  
  5833. You can select the program to run as the pager by setting the variable PAGER, 
  5834. and you can turn paging off by setting the value of the variable 
  5835. page_screen_output to 0. 
  5836.  
  5837. Command: more 
  5838.  
  5839. Command: more on 
  5840.  
  5841. Command: more off 
  5842. Turn output pagination on or off.  Without an argument, more toggles the 
  5843. current state. 
  5844.  
  5845. Built-in Variable: PAGER 
  5846. The default value is normally "less", "more", or "pg", depending on what 
  5847. programs are installed on your system. See Installation. 
  5848.  
  5849. When running interactively, Octave sends any output intended for your terminal 
  5850. that is more than one screen long to the program named by the value of the 
  5851. variable PAGER. 
  5852.  
  5853. Built-in Variable: page_screen_output 
  5854. If the value of page_screen_output is nonzero, all output intended for the 
  5855. screen that is longer than one page is sent through a pager.  This allows you 
  5856. to view one screenful at a time.  Some pagers (such as less---see Installation) 
  5857. are also capable of moving backward on the output.  The default value is 1. 
  5858.  
  5859. Built-in Variable: page_output_immediately 
  5860. If the value of page_output_immediately is nonzero, Octave sends output to the 
  5861. pager as soon as it is available.  Otherwise, Octave buffers its output and 
  5862. waits until just before the prompt is printed to flush it to the pager.  The 
  5863. default value is 0. 
  5864.  
  5865. Built-in Function:  fflush (fid) 
  5866. Flush output to fid.  This is useful for ensuring that all pending output makes 
  5867. it to the screen before some other event occurs. For example, it is always a 
  5868. good idea to flush the standard output stream before calling input. 
  5869.  
  5870.  Basic Input and Output 
  5871.  C-Style I/O Functions 
  5872.  
  5873.  
  5874. ΓòÉΓòÉΓòÉ 16.1. Basic Input and Output ΓòÉΓòÉΓòÉ
  5875.  
  5876.  Terminal Output 
  5877.  Terminal Input 
  5878.  Simple File I/O 
  5879.  
  5880.  
  5881. ΓòÉΓòÉΓòÉ 16.1.1. Terminal Output ΓòÉΓòÉΓòÉ
  5882.  
  5883. Since Octave normally prints the value of an expression as soon as it has been 
  5884. evaluated, the simplest of all I/O functions is a simple expression.  For 
  5885. example, the following expression will display the value of pi 
  5886.  
  5887. pi
  5888.      -| pi = 3.1416
  5889.  
  5890. This works well as long as it is acceptable to have the name of the variable 
  5891. (or `ans') printed along with the value.  To print the value of a variable 
  5892. without printing its name, use the function disp. 
  5893.  
  5894. The format command offers some control over the way Octave prints values with 
  5895. disp and through the normal echoing mechanism. 
  5896.  
  5897. Built-in Variable: ans 
  5898. This variable holds the most recently computed result that was not explicitly 
  5899. assigned to a variable.  For example, after the expression 
  5900.  
  5901. 3^2 + 4^2
  5902.  
  5903. is evaluated, the value of ans is 25. 
  5904.  
  5905. Built-in Function:  disp (x) 
  5906. Display the value of x.  For example, 
  5907.  
  5908. disp ("The value of pi is:"), disp (pi)
  5909.  
  5910.      -| the value of pi is:
  5911.      -| 3.1416
  5912.  
  5913. Note that the output from disp always ends with a newline. 
  5914.  
  5915. Command: format options 
  5916. Control the format of the output produced by disp and Octave's normal echoing 
  5917. mechanism.  Valid options are listed in the following table. 
  5918.  
  5919.  short 
  5920.            Octave will try to print numbers with at least 3 significant figures 
  5921.            within a field that is a maximum of 8 characters wide. 
  5922.  
  5923.            If Octave is unable to format a matrix so that columns line up on 
  5924.            the decimal point and all the numbers fit within the maximum field 
  5925.            width, it switches to an `e' format. 
  5926.  
  5927.  long 
  5928.            Octave will try to print numbers with at least 15 significant 
  5929.            figures within a field that is a maximum of 24 characters wide. 
  5930.  
  5931.            As will the `short' format, Octave will switch to an `e' format if 
  5932.            it is unable to format a matrix so that columns line up on the 
  5933.            decimal point and all the numbers fit within the maximum field 
  5934.            width. 
  5935.  
  5936.  long e 
  5937.  short e 
  5938.            The same as `format long' or `format short' but always display 
  5939.            output with an `e' format.  For example, with the `short e' format, 
  5940.            pi is displayed as 3.14e+00. 
  5941.  
  5942.  long E 
  5943.  short E 
  5944.            The same as `format long e' or `format short e' but always display 
  5945.            output with an uppercase `E' format.  For example, with the `long E' 
  5946.            format, pi is displayed as 3.14159265358979E+00. 
  5947.  
  5948.  free 
  5949.  none 
  5950.            Print output in free format, without trying to line up columns of 
  5951.            matrices on the decimal point.  This also causes complex numbers to 
  5952.            be formatted like this `(0.604194, 0.607088)' instead of like this 
  5953.            `0.60419 + 0.60709i'. 
  5954.  
  5955.  bank 
  5956.            Print in a fixed format with two places to the right of the decimal 
  5957.            point. 
  5958.  
  5959.  + 
  5960.            Print a `+' symbol for nonzero matrix elements and a space for zero 
  5961.            matrix elements.  This format can be very useful for examining the 
  5962.            structure of a large matrix. 
  5963.  
  5964.  hex 
  5965.            Print the hexadecimal representation numbers as they are stored in 
  5966.            memory.  For example, on a workstation which stores 8 byte real 
  5967.            values in IEEE format with the least significant byte first, the 
  5968.            value of pi when printed in hex format is 400921fb54442d18. This 
  5969.            format only works for numeric values. 
  5970.  
  5971.  bit 
  5972.            Print the bit representation of numbers as stored in memory. For 
  5973.            example, the value of pi is 
  5974.  
  5975.                       01000000000010010010000111111011
  5976.                       01010100010001000010110100011000
  5977.  
  5978.            (shown here in two 32 bit sections for typesetting purposes) when 
  5979.            printed in bit format on a workstation which stores 8 byte real 
  5980.            values in IEEE format with the least significant byte first.  This 
  5981.            format only works for numeric types. 
  5982.  
  5983.  By default, Octave will try to print numbers with at least 5 significant 
  5984.  figures within a field that is a maximum of 10 characters wide. 
  5985.  
  5986.  If Octave is unable to format a matrix so that columns line up on the decimal 
  5987.  point and all the numbers fit within the maximum field width, it switches to 
  5988.  an `e' format. 
  5989.  
  5990.  If format is invoked without any options, the default format state is 
  5991.  restored. 
  5992.  
  5993.  Built-in Variable: print_answer_id_name 
  5994.  If the value of print_answer_id_name is nonzero, variable names are printed 
  5995.  along with the result.  Otherwise, only the result values are printed.  The 
  5996.  default value is 1. 
  5997.  
  5998.  
  5999. ΓòÉΓòÉΓòÉ 16.1.2. Terminal Input ΓòÉΓòÉΓòÉ
  6000.  
  6001. Octave has three functions that make it easy to prompt users for input.  The 
  6002. input and menu functions are normally used for managing an interactive dialog 
  6003. with a user, and the keyboard function is normally used for doing simple 
  6004. debugging. 
  6005.  
  6006. Built-in Function:  input (prompt) 
  6007.  
  6008. Built-in Function:  input (prompt, "s") 
  6009. Print a prompt and wait for user input.  For example, 
  6010.  
  6011. input ("Pick a number, any number! ")
  6012.  
  6013. prints the prompt 
  6014.  
  6015. Pick a number, any number!
  6016.  
  6017. and waits for the user to enter a value.  The string entered by the user is 
  6018. evaluated as an expression, so it may be a literal constant, a variable name, 
  6019. or any other valid expression. 
  6020.  
  6021. Currently, input only returns one value, regardless of the number of values 
  6022. produced by the evaluation of the expression. 
  6023.  
  6024. If you are only interested in getting a literal string value, you can call 
  6025. input with the character string "s" as the second argument.  This tells Octave 
  6026. to return the string entered by the user directly, without evaluating it first. 
  6027.  
  6028. Because there may be output waiting to be displayed by the pager, it is a good 
  6029. idea to always call fflush (stdout) before calling input.  This will ensure 
  6030. that all pending output is written to the screen before your prompt.  See Input 
  6031. and Output. 
  6032.  
  6033. Function File:  menu (title, opt1, ...) 
  6034. Print a title string followed by a series of options.  Each option will be 
  6035. printed along with a number.  The return value is the number of the option 
  6036. selected by the user.  This function is useful for interactive programs.  There 
  6037. is no limit to the number of options that may be passed in, but it may be 
  6038. confusing to present more than will fit easily on one screen. 
  6039.  
  6040. Built-in Function:  keyboard (prompt) 
  6041. This function is normally used for simple debugging.  When the keyboard 
  6042. function is executed, Octave prints a prompt and waits for user input.  The 
  6043. input strings are then evaluated and the results are printed.  This makes it 
  6044. possible to examine the values of variables within a function, and to assign 
  6045. new values to variables.  No value is returned from the keyboard function, and 
  6046. it continues to prompt for input until the user types `quit', or `exit'. 
  6047.  
  6048. If keyboard is invoked without any arguments, a default prompt of `debug> ' is 
  6049. used. 
  6050.  
  6051. For both input and keyboard, the normal command line history and editing 
  6052. functions are available at the prompt. 
  6053.  
  6054. Octave also has a function that makes it possible to get a single character 
  6055. from the keyboard without requiring the user to type a carriage return. 
  6056.  
  6057. Built-in Function:  kbhit () 
  6058. Read a single keystroke from the keyboard.  For example, 
  6059.  
  6060. x = kbhit ();
  6061.  
  6062. will set x to the next character typed at the keyboard as soon as it is typed. 
  6063.  
  6064.  
  6065. ΓòÉΓòÉΓòÉ 16.1.3. Simple File I/O ΓòÉΓòÉΓòÉ
  6066.  
  6067. The save and load commands allow data to be written to and read from disk files 
  6068. in various formats.  The default format of files written by the save command 
  6069. can be controlled using the built-in variables default_save_format and 
  6070. save_precision. 
  6071.  
  6072. Note that Octave can not yet save or load structure variables or any 
  6073. user-defined types. 
  6074.  
  6075. Command: save options file v1 v2 ... 
  6076. Save the named variables v1, v2, ... in the file file.  The special filename 
  6077. `-' can be used to write the output to your terminal.  If no variable names are 
  6078. listed, Octave saves all the variables in the current scope.  Valid options for 
  6079. the save command are listed in the following table.  Options that modify the 
  6080. output format override the format specified by the built-in variable 
  6081. default_save_format. 
  6082.  
  6083.  -ascii 
  6084.            Save the data in Octave's text data format. 
  6085.  
  6086.  -binary 
  6087.            Save the data in Octave's binary data format. 
  6088.  
  6089.  -float-binary 
  6090.            Save the data in Octave's binary data format but only using single 
  6091.            precision.  You should use this format only if you know that all the 
  6092.            values to be saved can be represented in single precision. 
  6093.  
  6094.  -mat-binary 
  6095.            Save the data in Matlab's binary data format. 
  6096.  
  6097.  -save-builtins 
  6098.            Force Octave to save the values of built-in variables too.  By 
  6099.            default, Octave does not save built-in variables. 
  6100.  
  6101.  The list of variables to save may include wildcard patterns containing the 
  6102.  following special characters: 
  6103.  
  6104.  ? 
  6105.            Match any single character. 
  6106.  
  6107.  * 
  6108.            Match zero or more characters. 
  6109.  
  6110.  [ list ] 
  6111.            Match the list of characters specified by list.  If the first 
  6112.            character is ! or ^, match all characters except those specified by 
  6113.            list.  For example, the pattern `[a-zA-Z]' will match all lower and 
  6114.            upper case alphabetic characters. 
  6115.  
  6116.  Except when using the Matlab binary data file format, saving global variables 
  6117.  also saves the global status of the variable, so that if it is restored at a 
  6118.  later time using `load', it will be restored as a global variable. 
  6119.  
  6120.  The command 
  6121.  
  6122.   save -binary data a b*
  6123.  
  6124.  saves the variable `a' and all variables beginning with `b' to the file `data' 
  6125.  in Octave's binary format. 
  6126.  
  6127.  There are two variables that modify the behavior of save and one that controls 
  6128.  whether variables are saved when Octave exits unexpectedly. 
  6129.  
  6130.  Built-in Variable: crash_dumps_octave_core 
  6131.  If this variable is set to a nonzero value, Octave tries to save all current 
  6132.  variables the the file "octave-core" if it crashes or receives a hangup, 
  6133.  terminate or similar signal.  The default value is 1. 
  6134.  
  6135.  Built-in Variable: default_save_format 
  6136.  This variable specifies the default format for the save command. It should 
  6137.  have one of the following values: "ascii", "binary", float-binary, or 
  6138.  "mat-binary".  The initial default save format is Octave's text format. 
  6139.  
  6140.  Built-in Variable: save_precision 
  6141.  This variable specifies the number of digits to keep when saving data in text 
  6142.  format.  The default value is 17. 
  6143.  
  6144.  Command: load options file v1 v2 ... 
  6145.  Load the named variables from the file file.  As with save, you may specify a 
  6146.  list of variables and load will only extract those variables with names that 
  6147.  match.  For example, to restore the variables saved in the file `data', use 
  6148.  the command 
  6149.  
  6150.   load data
  6151.  
  6152.  Octave will refuse to overwrite existing variables unless you use the option 
  6153.  `-force'. 
  6154.  
  6155.  If a variable that is not marked as global is loaded from a file when a global 
  6156.  symbol with the same name already exists, it is loaded in the global symbol 
  6157.  table.  Also, if a variable is marked as global in a file and a local symbol 
  6158.  exists, the local symbol is moved to the global symbol table and given the 
  6159.  value from the file.  Since it seems that both of these cases are likely to be 
  6160.  the result of some sort of error, they will generate warnings. 
  6161.  
  6162.  The load command can read data stored in Octave's text and binary formats, and 
  6163.  Matlab's binary format.  It will automatically detect the type of file and do 
  6164.  conversion from different floating point formats (currently only IEEE big and 
  6165.  little endian, though other formats may added in the future). 
  6166.  
  6167.  Valid options for load are listed in the following table. 
  6168.  
  6169.  -force 
  6170.            Force variables currently in memory to be overwritten by variables 
  6171.            with the same name found in the file. 
  6172.  
  6173.  -ascii 
  6174.            Force Octave to assume the file is in Octave's text format. 
  6175.  
  6176.  -binary 
  6177.            Force Octave to assume the file is in Octave's binary format. 
  6178.  
  6179.  -mat-binary 
  6180.            Force Octave to assume the file is in Matlab's binary format. 
  6181.  
  6182.  
  6183. ΓòÉΓòÉΓòÉ 16.2. C-Style I/O Functions ΓòÉΓòÉΓòÉ
  6184.  
  6185. Octave's C-style input and output functions provide most of the functionality 
  6186. of the C programming language's standard I/O library.  The argument lists for 
  6187. some of the input functions are slightly different, however, because Octave has 
  6188. no way of passing arguments by reference. 
  6189.  
  6190. In the following, file refers to a file name and fid refers to an integer file 
  6191. number, as returned by fopen. 
  6192.  
  6193. There are three files that are always available.  Although these files can be 
  6194. accessed using their corresponding numeric file ids, you should always use the 
  6195. symbolic names given in the table below, since it will make your programs 
  6196. easier to understand. 
  6197.  
  6198. Built-in Variable: stdin 
  6199. The standard input stream (file id 0).  When Octave is used interactively, this 
  6200. is filtered through the command line editing functions. 
  6201.  
  6202. Built-in Variable: stdout 
  6203. The standard output stream (file id 1).  Data written to the standard output is 
  6204. normally filtered through the pager. 
  6205.  
  6206. Built-in Variable: stderr 
  6207. The standard error stream (file id 2).  Even if paging is turned on, the 
  6208. standard error is not sent to the pager.  It is useful for error messages and 
  6209. prompts. 
  6210.  
  6211.  Opening and Closing Files 
  6212.  Simple Output 
  6213.  Line-Oriented Input 
  6214.  Formatted Output 
  6215.  Output Conversion for Matrices 
  6216.  Output Conversion Syntax 
  6217.  Table of Output Conversions 
  6218.  Integer Conversions 
  6219.  Floating-Point Conversions              Other Output Conversions:: 
  6220.  Other Output Conversions 
  6221.  Formatted Input 
  6222.  Input Conversion Syntax 
  6223.  Table of Input Conversions 
  6224.  Numeric Input Conversions 
  6225.  String Input Conversions 
  6226.  Binary I/O 
  6227.  Temporary Files 
  6228.  EOF and Errors 
  6229.  File Positioning 
  6230.  
  6231.  
  6232. ΓòÉΓòÉΓòÉ 16.2.1. Opening and Closing Files ΓòÉΓòÉΓòÉ
  6233.  
  6234. Built-in Function: [fid, msg] = fopen (name, mode, arch) 
  6235.  
  6236. Built-in Function: fid_list = fopen ("all") 
  6237.  
  6238. Built-in Function: file = fopen (fid) 
  6239. The first form of the fopen function opens the named file with the specified 
  6240. mode (read-write, read-only, etc.) and architecture interpretation (IEEE big 
  6241. endian, IEEE little endian, etc.), and returns an integer value that may be 
  6242. used to refer to the file later.  If an error occurs, fid is set to -1 and msg 
  6243. contains the corresponding system error message.  The mode is a one or two 
  6244. character string that specifies whether the file is to be opened for reading, 
  6245. writing, or both. 
  6246.  
  6247. The second form of the fopen function returns a vector of file ids 
  6248. corresponding to all the currently open files, excluding the stdin, stdout, and 
  6249. stderr streams. 
  6250.  
  6251. The third form of the fopen function returns the name of a currently open file 
  6252. given its file id. 
  6253.  
  6254. For example, 
  6255.  
  6256. myfile = fopen ("splat.dat", "r", "ieee-le");
  6257.  
  6258. opens the file `splat.dat' for reading.  If necessary, binary numeric values 
  6259. will be read assuming they are stored in IEEE format with the least significant 
  6260. bit first, and then converted to the native representation. 
  6261.  
  6262. Opening a file that is already open simply opens it again and returns a 
  6263. separate file id.  It is not an error to open a file several times, though 
  6264. writing to the same file through several different file ids may produce 
  6265. unexpected results. 
  6266.  
  6267. The possible values `mode' may have are 
  6268.  
  6269.  `r' 
  6270.            Open a file for reading. 
  6271.  
  6272.  `w' 
  6273.            Open a file for writing.  The previous contents are discared. 
  6274.  
  6275.  `a' 
  6276.            Open or create a file for writing at the end of the file. 
  6277.  
  6278.  `r+' 
  6279.            Open an existing file for reading and writing. 
  6280.  
  6281.  `w+' 
  6282.            Open a file for reading or writing.  The previous contents are 
  6283.            discarded. 
  6284.  
  6285.  `a+' 
  6286.            Open or create a file for reading or writing at the end of the file. 
  6287.  
  6288.  The parameter arch is a string specifying the default data format for the 
  6289.  file.  Valid values for arch are: `native' The format of the current machine 
  6290.  (this is the default). 
  6291.  
  6292.  `ieee-le' IEEE big endian format. 
  6293.  
  6294.  `ieee-be' IEEE little endian format. 
  6295.  
  6296.  `vaxd' VAX D floating format. 
  6297.  
  6298.  `vaxg' VAX G floating format. 
  6299.  
  6300.  `cray' Cray floating format. 
  6301.  
  6302.  however, conversions are currently only supported for `native' `ieee-be', and 
  6303.  `ieee-le' formats. 
  6304.  
  6305.  Built-in Function:  fclose (fid) 
  6306.  Closes the specified file.  If an error is encountered while trying to close 
  6307.  the file, an error message is printed and fclose returns 0.  Otherwise, it 
  6308.  returns 1. 
  6309.  
  6310.  
  6311. ΓòÉΓòÉΓòÉ 16.2.2. Simple Output ΓòÉΓòÉΓòÉ
  6312.  
  6313. Built-in Function:  fputs (fid, string) 
  6314. Write a string to a file with no formatting. 
  6315.  
  6316. Built-in Function:  puts (string) 
  6317. Write a string to the standard output with no formatting. 
  6318.  
  6319.  
  6320. ΓòÉΓòÉΓòÉ 16.2.3. Line-Oriented Input ΓòÉΓòÉΓòÉ
  6321.  
  6322. Built-in Function:  fgetl (fid, len) 
  6323. Read characters from a file, stopping at the first newline character that is 
  6324. encountered or after len characters have been read, and returning the 
  6325. characters as a string.  The newline is not included in the returned value. 
  6326.  
  6327. If len is omitted, fgetl reads until the next newline character. 
  6328.  
  6329. If there are no more characters to read, fgetl returns -1. 
  6330.  
  6331. Built-in Function:  fgets (fid, len) 
  6332. Read characters from a file, stopping at the first newline character that is 
  6333. encountered or after len characters have been read, and returning the 
  6334. characters as a string.  The newline is included in the returned value. 
  6335.  
  6336. If len is omitted, fgets reads until the next newline character. 
  6337.  
  6338. If there are no more characters to read, fgets returns -1. 
  6339.  
  6340.  
  6341. ΓòÉΓòÉΓòÉ 16.2.4. Formatted Output ΓòÉΓòÉΓòÉ
  6342.  
  6343. This section describes how to call printf and related functions. 
  6344.  
  6345. The following functions are available for formatted output.  They are modelled 
  6346. after the C language functions of the same name, but they interpret the format 
  6347. template differently in order to improve the performance of printing vector and 
  6348. matrix values. 
  6349.  
  6350. Function File:  printf (template, ...) 
  6351. The printf function prints the optional arguments under the control of the 
  6352. template string template to the stream stdout. 
  6353.  
  6354. Built-in Function:  fprintf (fid, template, ...) 
  6355. This function is just like printf, except that the output is written to the 
  6356. stream fid instead of stdout. 
  6357.  
  6358. Built-in Function:  sprintf (template, ...) 
  6359. This is like printf, except that the output is returned as a string.  Unlike 
  6360. the C library function, which requires you to provide a suitably sized string 
  6361. as an argument, Octave's sprintf function returns the string, automatically 
  6362. sized to hold all of the items converted. 
  6363.  
  6364. The printf function can be used to print any number of arguments. The template 
  6365. string argument you supply in a call provides information not only about the 
  6366. number of additional arguments, but also about their types and what style 
  6367. should be used for printing them. 
  6368.  
  6369. Ordinary characters in the template string are simply written to the output 
  6370. stream as-is, while conversion specifications introduced by a `%' character in 
  6371. the template cause subsequent arguments to be formatted and written to the 
  6372. output stream.  For example, 
  6373.  
  6374. pct = 37;
  6375. filename = "foo.txt";
  6376. printf ("Processing of `%s' is %d%% finished.\nPlease be patient.\n",
  6377.         filename, pct);
  6378.  
  6379. produces output like 
  6380.  
  6381. Processing of `foo.txt' is 37% finished.
  6382. Please be patient.
  6383.  
  6384. This example shows the use of the `%d' conversion to specify that a scalar 
  6385. argument should be printed in decimal notation, the `%s' conversion to specify 
  6386. printing of a string argument, and the `%%' conversion to print a literal `%' 
  6387. character. 
  6388.  
  6389. There are also conversions for printing an integer argument as an unsigned 
  6390. value in octal, decimal, or hexadecimal radix (`%o', `%u', or `%x', 
  6391. respectively); or as a character value (`%c'). 
  6392.  
  6393. Floating-point numbers can be printed in normal, fixed-point notation using the 
  6394. `%f' conversion or in exponential notation using the `%e' conversion.  The `%g' 
  6395. conversion uses either `%e' or `%f' format, depending on what is more 
  6396. appropriate for the magnitude of the particular number. 
  6397.  
  6398. You can control formatting more precisely by writing modifiers between the `%' 
  6399. and the character that indicates which conversion to apply.  These slightly 
  6400. alter the ordinary behavior of the conversion. For example, most conversion 
  6401. specifications permit you to specify a minimum field width and a flag 
  6402. indicating whether you want the result left- or right-justified within the 
  6403. field. 
  6404.  
  6405. The specific flags and modifiers that are permitted and their interpretation 
  6406. vary depending on the particular conversion.  They're all described in more 
  6407. detail in the following sections. 
  6408.  
  6409.  
  6410. ΓòÉΓòÉΓòÉ 16.2.5. Output Conversion for Matrices ΓòÉΓòÉΓòÉ
  6411.  
  6412. When given a matrix value, Octave's formatted output functions cycle through 
  6413. the format template until all the values in the matrix have been printed.  For 
  6414. example, 
  6415.  
  6416. printf ("%4.2f %10.2e %8.4g\n", hilb (3));
  6417.  
  6418.      -| 1.00   5.00e-01   0.3333
  6419.      -| 0.50   3.33e-01     0.25
  6420.      -| 0.33   2.50e-01      0.2
  6421.  
  6422. If more than one value is to be printed in a single call, the output functions 
  6423. do not return to the beginning of the format template when moving on from one 
  6424. value to the next.  This can lead to confusing output if the number of elements 
  6425. in the matrices are not exact multiples of the number of conversions in the 
  6426. format template.  For example, 
  6427.  
  6428. printf ("%4.2f %10.2e %8.4g\n", [1, 2], [3, 4]);
  6429.  
  6430.      -| 1.00   2.00e+00        3
  6431.      -| 4.00
  6432.  
  6433. If this is not what you want, use a series of calls instead of just one. 
  6434.  
  6435.  
  6436. ΓòÉΓòÉΓòÉ 16.2.6. Output Conversion Syntax ΓòÉΓòÉΓòÉ
  6437.  
  6438. This section provides details about the precise syntax of conversion 
  6439. specifications that can appear in a printf template string. 
  6440.  
  6441. Characters in the template string that are not part of a conversion 
  6442. specification are printed as-is to the output stream. 
  6443.  
  6444. The conversion specifications in a printf template string have the general 
  6445. form: 
  6446.  
  6447. % flags width [ . precision ] type conversion
  6448.  
  6449. For example, in the conversion specifier `%-10.8ld', the `-' is a flag, `10' 
  6450. specifies the field width, the precision is `8', the letter `l' is a type 
  6451. modifier, and `d' specifies the conversion style.  (This particular type 
  6452. specifier says to print a numeric argument in decimal notation, with a minimum 
  6453. of 8 digits left-justified in a field at least 10 characters wide.) 
  6454.  
  6455. In more detail, output conversion specifications consist of an initial `%' 
  6456. character followed in sequence by: 
  6457.  
  6458.      Zero or more flag characters that modify the normal behavior of the 
  6459.       conversion specification. 
  6460.  
  6461.      An optional decimal integer specifying the minimum field width. If the 
  6462.       normal conversion produces fewer characters than this, the field is 
  6463.       padded with spaces to the specified width.  This is a minimum value; if 
  6464.       the normal conversion produces more characters than this, the field is 
  6465.       not truncated.  Normally, the output is right-justified within the field. 
  6466.  
  6467.       You can also specify a field width of `*'.  This means that the next 
  6468.       argument in the argument list (before the actual value to be printed) is 
  6469.       used as the field width.  The value is rounded to the nearest integer. 
  6470.       If the value is negative, this means to set the `-' flag (see below) and 
  6471.       to use the absolute value as the field width. 
  6472.  
  6473.      An optional precision to specify the number of digits to be written for 
  6474.       the numeric conversions.  If the precision is specified, it consists of a 
  6475.       period (`.') followed optionally by a decimal integer (which defaults to 
  6476.       zero if omitted). 
  6477.  
  6478.       You can also specify a precision of `*'.  This means that the next 
  6479.       argument in the argument list (before the actual value to be printed) is 
  6480.       used as the precision.  The value must be an integer, and is ignored if 
  6481.       it is negative. 
  6482.  
  6483.      An optional type modifier character.  This character is ignored by 
  6484.       Octave's printf function, but is recognized to provide compatibility with 
  6485.       the C language printf. 
  6486.  
  6487.      A character that specifies the conversion to be applied. 
  6488.  
  6489.  The exact options that are permitted and how they are interpreted vary between 
  6490.  the different conversion specifiers.  See the descriptions of the individual 
  6491.  conversions for information about the particular options that they use. 
  6492.  
  6493.  
  6494. ΓòÉΓòÉΓòÉ 16.2.7. Table of Output Conversions ΓòÉΓòÉΓòÉ
  6495.  
  6496. Here is a table summarizing what all the different conversions do: 
  6497.  
  6498.  `%d', `%i' 
  6499.            Print an integer as a signed decimal number. See Integer 
  6500.            Conversions, for details.  `%d' and `%i' are synonymous for output, 
  6501.            but are different when used with scanf for input (see Table of Input 
  6502.            Conversions). 
  6503.  
  6504.  `%o' 
  6505.            Print an integer as an unsigned octal number. See Integer 
  6506.            Conversions, for details. 
  6507.  
  6508.  `%u' 
  6509.            Print an integer as an unsigned decimal number. See Integer 
  6510.            Conversions, for details. 
  6511.  
  6512.  `%x', `%X' 
  6513.            Print an integer as an unsigned hexadecimal number.  `%x' uses 
  6514.            lower-case letters and `%X' uses upper-case. See Integer 
  6515.            Conversions, for details. 
  6516.  
  6517.  `%f' 
  6518.            Print a floating-point number in normal (fixed-point) notation. See 
  6519.            Floating-Point Conversions, for details. 
  6520.  
  6521.  `%e', `%E' 
  6522.            Print a floating-point number in exponential notation.  `%e' uses 
  6523.            lower-case letters and `%E' uses upper-case. See Floating-Point 
  6524.            Conversions, for details. 
  6525.  
  6526.  `%g', `%G' 
  6527.            Print a floating-point number in either normal (fixed-point) or 
  6528.            exponential notation, whichever is more appropriate for its 
  6529.            magnitude. `%g' uses lower-case letters and `%G' uses upper-case. 
  6530.            See Floating-Point Conversions, for details. 
  6531.  
  6532.  `%c' 
  6533.            Print a single character.  See Other Output Conversions. 
  6534.  
  6535.  `%s' 
  6536.            Print a string.  See Other Output Conversions. 
  6537.  
  6538.  `%%' 
  6539.            Print a literal `%' character.  See Other Output Conversions. 
  6540.  
  6541.  If the syntax of a conversion specification is invalid, unpredictable things 
  6542.  will happen, so don't do this.  If there aren't enough function arguments 
  6543.  provided to supply values for all the conversion specifications in the 
  6544.  template string, or if the arguments are not of the correct types, the results 
  6545.  are unpredictable.  If you supply more arguments than conversion 
  6546.  specifications, the extra argument values are simply ignored; this is 
  6547.  sometimes useful. 
  6548.  
  6549.  
  6550. ΓòÉΓòÉΓòÉ 16.2.8. Integer Conversions ΓòÉΓòÉΓòÉ
  6551.  
  6552. This section describes the options for the `%d', `%i', `%o', `%u', `%x', and 
  6553. `%X' conversion specifications.  These conversions print integers in various 
  6554. formats. 
  6555.  
  6556. The `%d' and `%i' conversion specifications both print an numeric argument as a 
  6557. signed decimal number; while `%o', `%u', and `%x' print the argument as an 
  6558. unsigned octal, decimal, or hexadecimal number (respectively).  The `%X' 
  6559. conversion specification is just like `%x' except that it uses the characters 
  6560. `ABCDEF' as digits instead of `abcdef'. 
  6561.  
  6562. The following flags are meaningful: 
  6563.  
  6564.  `-' 
  6565.            Left-justify the result in the field (instead of the normal 
  6566.            right-justification). 
  6567.  
  6568.  `+' 
  6569.            For the signed `%d' and `%i' conversions, print a plus sign if the 
  6570.            value is positive. 
  6571.  
  6572.  ` ' 
  6573.            For the signed `%d' and `%i' conversions, if the result doesn't 
  6574.            start with a plus or minus sign, prefix it with a space character 
  6575.            instead.  Since the `+' flag ensures that the result includes a 
  6576.            sign, this flag is ignored if you supply both of them. 
  6577.  
  6578.  `#' 
  6579.            For the `%o' conversion, this forces the leading digit to be `0', as 
  6580.            if by increasing the precision.  For `%x' or `%X', this prefixes a 
  6581.            leading `0x' or `0X' (respectively) to the result.  This doesn't do 
  6582.            anything useful for the `%d', `%i', or `%u' conversions. 
  6583.  
  6584.  `0' 
  6585.            Pad the field with zeros instead of spaces.  The zeros are placed 
  6586.            after any indication of sign or base.  This flag is ignored if the 
  6587.            `-' flag is also specified, or if a precision is specified. 
  6588.  
  6589.  If a precision is supplied, it specifies the minimum number of digits to 
  6590.  appear; leading zeros are produced if necessary.  If you don't specify a 
  6591.  precision, the number is printed with as many digits as it needs.  If you 
  6592.  convert a value of zero with an explicit precision of zero, then no characters 
  6593.  at all are produced. 
  6594.  
  6595.  
  6596. ΓòÉΓòÉΓòÉ 16.2.9. Floating-Point Conversions ΓòÉΓòÉΓòÉ
  6597.  
  6598. This section discusses the conversion specifications for floating-point 
  6599. numbers: the `%f', `%e', `%E', `%g', and `%G' conversions. 
  6600.  
  6601. The `%f' conversion prints its argument in fixed-point notation, producing 
  6602. output of the form [-]ddd.ddd, where the number of digits following the decimal 
  6603. point is controlled by the precision you specify. 
  6604.  
  6605. The `%e' conversion prints its argument in exponential notation, producing 
  6606. output of the form [-]d.ddde[+|-]dd. Again, the number of digits following the 
  6607. decimal point is controlled by the precision.  The exponent always contains at 
  6608. least two digits.  The `%E' conversion is similar but the exponent is marked 
  6609. with the letter `E' instead of `e'. 
  6610.  
  6611. The `%g' and `%G' conversions print the argument in the style of `%e' or `%E' 
  6612. (respectively) if the exponent would be less than -4 or greater than or equal 
  6613. to the precision; otherwise they use the `%f' style.  Trailing zeros are 
  6614. removed from the fractional portion of the result and a decimal-point character 
  6615. appears only if it is followed by a digit. 
  6616.  
  6617. The following flags can be used to modify the behavior: 
  6618.  
  6619.  `-' 
  6620.            Left-justify the result in the field.  Normally the result is 
  6621.            right-justified. 
  6622.  
  6623.  `+' 
  6624.            Always include a plus or minus sign in the result. 
  6625.  
  6626.  ` ' 
  6627.            If the result doesn't start with a plus or minus sign, prefix it 
  6628.            with a space instead.  Since the `+' flag ensures that the result 
  6629.            includes a sign, this flag is ignored if you supply both of them. 
  6630.  
  6631.  `#' 
  6632.            Specifies that the result should always include a decimal point, 
  6633.            even if no digits follow it.  For the `%g' and `%G' conversions, 
  6634.            this also forces trailing zeros after the decimal point to be left 
  6635.            in place where they would otherwise be removed. 
  6636.  
  6637.  `0' 
  6638.            Pad the field with zeros instead of spaces; the zeros are placed 
  6639.            after any sign.  This flag is ignored if the `-' flag is also 
  6640.            specified. 
  6641.  
  6642.  The precision specifies how many digits follow the decimal-point character for 
  6643.  the `%f', `%e', and `%E' conversions.  For these conversions, the default 
  6644.  precision is 6.  If the precision is explicitly 0, this suppresses the decimal 
  6645.  point character entirely.  For the `%g' and `%G' conversions, the precision 
  6646.  specifies how many significant digits to print.  Significant digits are the 
  6647.  first digit before the decimal point, and all the digits after it. If the 
  6648.  precision is 0 or not specified for `%g' or `%G', it is treated like a value 
  6649.  of 1.  If the value being printed cannot be expressed precisely in the 
  6650.  specified number of digits, the value is rounded to the nearest number that 
  6651.  fits. 
  6652.  
  6653.  
  6654. ΓòÉΓòÉΓòÉ 16.2.10. Other Output Conversions ΓòÉΓòÉΓòÉ
  6655.  
  6656. This section describes miscellaneous conversions for printf. 
  6657.  
  6658. The `%c' conversion prints a single character.  The `-' flag can be used to 
  6659. specify left-justification in the field, but no other flags are defined, and no 
  6660. precision or type modifier can be given. For example: 
  6661.  
  6662. printf ("%c%c%c%c%c", "h", "e", "l", "l", "o");
  6663.  
  6664. prints `hello'. 
  6665.  
  6666. The `%s' conversion prints a string.  The corresponding argument must be a 
  6667. string.  A precision can be specified to indicate the maximum number of 
  6668. characters to write; otherwise characters in the string up to but not including 
  6669. the terminating null character are written to the output stream.  The `-' flag 
  6670. can be used to specify left-justification in the field, but no other flags or 
  6671. type modifiers are defined for this conversion.  For example: 
  6672.  
  6673. printf ("%3s%-6s", "no", "where");
  6674.  
  6675. prints `nowhere ' (note the leading and trailing spaces). 
  6676.  
  6677.  
  6678. ΓòÉΓòÉΓòÉ 16.2.11. Formatted Input ΓòÉΓòÉΓòÉ
  6679.  
  6680. Octave provides the scanf, fscanf, and sscanf functions to read formatted 
  6681. input.  There are two forms of each of these functions.  One can be used to 
  6682. extract vectors of data from a file, and the other is more `C-like'. 
  6683.  
  6684. Built-in Function: [val, count] = fscanf (fid, template, size) 
  6685.  
  6686. Built-in Function: [v1, v2, ...] =  fscanf (fid, template, "C") 
  6687. In the first form, read from fid according to template, returning the result in 
  6688. the matrix val. 
  6689.  
  6690. The optional argument size specifies the amount of data to read and may be one 
  6691. of 
  6692.  
  6693.  Inf 
  6694.            Read as much as possible, returning a column vector. 
  6695.  
  6696.  nr 
  6697.  [nr, Inf] 
  6698.            Read as much as possible, returning a matrix with nr rows.  If the 
  6699.            number of elements read is not an exact multiple of nr, the last 
  6700.            column is padded with zeros. 
  6701.  
  6702.  [nr, nc] 
  6703.            Read up to nr * nc elements, returning a matrix with nr rows.  If 
  6704.            the number of elements read is not an exact multiple of nr, the last 
  6705.            column is padded with zeros. 
  6706.  
  6707.  If size is omitted, a value of Inf is assumed. 
  6708.  
  6709.  A string is returned if template specifies only character conversions. 
  6710.  
  6711.  The number of items successfully read is returned in count. 
  6712.  
  6713.  In the second form, read from fid according to template, with each conversion 
  6714.  specifier in template corresponding to a single scalar return value.  This 
  6715.  form is more `C-like', and also compatible with previous versions of Octave. 
  6716.  
  6717.  Built-in Function: [val, count] = sscanf (string, template, size) 
  6718.  
  6719.  Built-in Function: [v1, v2, ...] =  sscanf (string, template, "C") 
  6720.  This is like fscanf, except that the characters are taken from the string 
  6721.  string instead of from a stream.  Reaching the end of the string is treated as 
  6722.  an end-of-file condition. 
  6723.  
  6724.  Built-in Function: [val, count] = scanf (template, size) 
  6725.  
  6726.  Built-in Function: [v1, v2, ...] =  scanf (template, "C") 
  6727.  This is equivalent to calling fscanf with fid = stdin. 
  6728.  
  6729.  It is currently not useful to call scanf in interactive programs. 
  6730.  
  6731.  Calls to scanf are superficially similar to calls to printf in that arbitrary 
  6732.  arguments are read under the control of a template string.  While the syntax 
  6733.  of the conversion specifications in the template is very similar to that for 
  6734.  printf, the interpretation of the template is oriented more towards 
  6735.  free-format input and simple pattern matching, rather than fixed-field 
  6736.  formatting. For example, most scanf conversions skip over any amount of 
  6737.  ``white space'' (including spaces, tabs, and newlines) in the input file, and 
  6738.  there is no concept of precision for the numeric input conversions as there is 
  6739.  for the corresponding output conversions. Ordinarily, non-whitespace 
  6740.  characters in the template are expected to match characters in the input 
  6741.  stream exactly. 
  6742.  
  6743.  When a matching failure occurs, scanf returns immediately, leaving the first 
  6744.  non-matching character as the next character to be read from the stream, and 
  6745.  scanf returns all the items that were successfully converted. 
  6746.  
  6747.  The formatted input functions are not used as frequently as the formatted 
  6748.  output functions.  Partly, this is because it takes some care to use them 
  6749.  properly.  Another reason is that it is difficult to recover from a matching 
  6750.  error. 
  6751.  
  6752.  
  6753. ΓòÉΓòÉΓòÉ 16.2.12. Input Conversion Syntax ΓòÉΓòÉΓòÉ
  6754.  
  6755. A scanf template string is a string that contains ordinary multibyte characters 
  6756. interspersed with conversion specifications that start with `%'. 
  6757.  
  6758. Any whitespace character in the template causes any number of whitespace 
  6759. characters in the input stream to be read and discarded.  The whitespace 
  6760. characters that are matched need not be exactly the same whitespace characters 
  6761. that appear in the template string.  For example, write `, ' in the template to 
  6762. recognize a comma with optional whitespace before and after. 
  6763.  
  6764. Other characters in the template string that are not part of conversion 
  6765. specifications must match characters in the input stream exactly; if this is 
  6766. not the case, a matching failure occurs. 
  6767.  
  6768. The conversion specifications in a scanf template string have the general form: 
  6769.  
  6770. % flags width type conversion
  6771.  
  6772. In more detail, an input conversion specification consists of an initial `%' 
  6773. character followed in sequence by: 
  6774.  
  6775.      An optional flag character `*', which says to ignore the text read for 
  6776.       this specification.  When scanf finds a conversion specification that 
  6777.       uses this flag, it reads input as directed by the rest of the conversion 
  6778.       specification, but it discards this input, does not use a pointer 
  6779.       argument, and does not increment the count of successful assignments. 
  6780.  
  6781.      An optional decimal integer that specifies the maximum field width. 
  6782.       Reading of characters from the input stream stops either when this 
  6783.       maximum is reached or when a non-matching character is found, whichever 
  6784.       happens first.  Most conversions discard initial whitespace characters 
  6785.       (those that don't are explicitly documented), and these discarded 
  6786.       characters don't count towards the maximum field width. 
  6787.  
  6788.      An optional type modifier character.  This character is ignored by 
  6789.       Octave's scanf function, but is recognized to provide compatibility with 
  6790.       the C language scanf. 
  6791.  
  6792.      A character that specifies the conversion to be applied. 
  6793.  
  6794.  The exact options that are permitted and how they are interpreted vary between 
  6795.  the different conversion specifiers.  See the descriptions of the individual 
  6796.  conversions for information about the particular options that they allow. 
  6797.  
  6798.  
  6799. ΓòÉΓòÉΓòÉ 16.2.13. Table of Input Conversions ΓòÉΓòÉΓòÉ
  6800.  
  6801. Here is a table that summarizes the various conversion specifications: 
  6802.  
  6803.  `%d' 
  6804.            Matches an optionally signed integer written in decimal. See Numeric 
  6805.            Input Conversions. 
  6806.  
  6807.  `%i' 
  6808.            Matches an optionally signed integer in any of the formats that the 
  6809.            C language defines for specifying an integer constant. See Numeric 
  6810.            Input Conversions. 
  6811.  
  6812.  `%o' 
  6813.            Matches an unsigned integer written in octal radix. See Numeric 
  6814.            Input Conversions. 
  6815.  
  6816.  `%u' 
  6817.            Matches an unsigned integer written in decimal radix. See Numeric 
  6818.            Input Conversions. 
  6819.  
  6820.  `%x', `%X' 
  6821.            Matches an unsigned integer written in hexadecimal radix. See 
  6822.            Numeric Input Conversions. 
  6823.  
  6824.  `%e', `%f', `%g', `%E', `%G' 
  6825.            Matches an optionally signed floating-point number. See Numeric 
  6826.            Input Conversions. 
  6827.  
  6828.  `%s' 
  6829.            Matches a string containing only non-whitespace characters. See 
  6830.            String Input Conversions. 
  6831.  
  6832.  `%c' 
  6833.            Matches a string of one or more characters; the number of characters 
  6834.            read is controlled by the maximum field width given for the 
  6835.            conversion. See String Input Conversions. 
  6836.  
  6837.  `%%' 
  6838.            This matches a literal `%' character in the input stream.  No 
  6839.            corresponding argument is used. 
  6840.  
  6841.  If the syntax of a conversion specification is invalid, the behavior is 
  6842.  undefined.  If there aren't enough function arguments provided to supply 
  6843.  addresses for all the conversion specifications in the template strings that 
  6844.  perform assignments, or if the arguments are not of the correct types, the 
  6845.  behavior is also undefined.  On the other hand, extra arguments are simply 
  6846.  ignored. 
  6847.  
  6848.  
  6849. ΓòÉΓòÉΓòÉ 16.2.14. Numeric Input Conversions ΓòÉΓòÉΓòÉ
  6850.  
  6851. This section describes the scanf conversions for reading numeric values. 
  6852.  
  6853. The `%d' conversion matches an optionally signed integer in decimal radix. 
  6854.  
  6855. The `%i' conversion matches an optionally signed integer in any of the formats 
  6856. that the C language defines for specifying an integer constant. 
  6857.  
  6858. For example, any of the strings `10', `0xa', or `012' could be read in as 
  6859. integers under the `%i' conversion.  Each of these specifies a number with 
  6860. decimal value 10. 
  6861.  
  6862. The `%o', `%u', and `%x' conversions match unsigned integers in octal, decimal, 
  6863. and hexadecimal radices, respectively. 
  6864.  
  6865. The `%X' conversion is identical to the `%x' conversion.  They both permit 
  6866. either uppercase or lowercase letters to be used as digits. 
  6867.  
  6868. Unlike the C language scanf, Octave ignores the `h', `l', and `L' modifiers. 
  6869.  
  6870.  
  6871. ΓòÉΓòÉΓòÉ 16.2.15. String Input Conversions ΓòÉΓòÉΓòÉ
  6872.  
  6873. This section describes the scanf input conversions for reading string and 
  6874. character values: `%s' and `%c'. 
  6875.  
  6876. The `%c' conversion is the simplest: it matches a fixed number of characters, 
  6877. always.  The maximum field with says how many characters to read; if you don't 
  6878. specify the maximum, the default is 1.  This conversion does not skip over 
  6879. initial whitespace characters.  It reads precisely the next n characters, and 
  6880. fails if it cannot get that many. 
  6881.  
  6882. The `%s' conversion matches a string of non-whitespace characters. It skips and 
  6883. discards initial whitespace, but stops when it encounters more whitespace after 
  6884. having read something. 
  6885.  
  6886. For example, reading the input: 
  6887.  
  6888.  hello, world
  6889.  
  6890. with the conversion `%10c' produces " hello, wo", but reading the same input 
  6891. with the conversion `%10s' produces "hello,". 
  6892.  
  6893.  
  6894. ΓòÉΓòÉΓòÉ 16.2.16. Binary I/O ΓòÉΓòÉΓòÉ
  6895.  
  6896. Octave can read and write binary data using the functions fread and fwrite, 
  6897. which are patterned after the standard C functions with the same names.  The 
  6898. are able to automatically swap the byte order of integer data and convert among 
  6899. ths supported floating point formats as the data are read. 
  6900.  
  6901. Built-in Function: [val, count] = fread (fid, size, precision, skip, arch) 
  6902. Read binary data of type precision from the specified file ID fid. 
  6903.  
  6904. The optional argument size specifies the amount of data to read and may be one 
  6905. of 
  6906.  
  6907.  Inf 
  6908.            Read as much as possible, returning a column vector. 
  6909.  
  6910.  nr 
  6911.  [nr, Inf] 
  6912.            Read as much as possible, returning a matrix with nr rows.  If the 
  6913.            number of elements read is not an exact multiple of nr, the last 
  6914.            column is padded with zeros. 
  6915.  
  6916.  [nr, nc] 
  6917.            Read up to nr * nc elements, returning a matrix with nr rows.  If 
  6918.            the number of elements read is not an exact multiple of nr, the last 
  6919.            column is padded with zeros. 
  6920.  
  6921.  If size is omitted, a value of Inf is assumed. 
  6922.  
  6923.  The optional argument precision is a string specifying the type of data to 
  6924.  read and may be one of 
  6925.  
  6926.  "char" 
  6927.  "char*1" 
  6928.  "integer*1" 
  6929.  "int8" 
  6930.            Single character. 
  6931.  
  6932.  "signed char" 
  6933.  "schar" 
  6934.            Signed character. 
  6935.  
  6936.  "unsigned char" 
  6937.  "uchar" 
  6938.            Unsigned character. 
  6939.  
  6940.  "short" 
  6941.            Short integer. 
  6942.  
  6943.  "unsigned short" 
  6944.  "ushort" 
  6945.            Unsigned short integer. 
  6946.  
  6947.  "int" 
  6948.            Integer. 
  6949.  
  6950.  "unsigned int" 
  6951.  "uint" 
  6952.            Unsigned integer. 
  6953.  
  6954.  "long" 
  6955.            Long integer. 
  6956.  
  6957.  "unsigned long" 
  6958.  "ulong" 
  6959.            Unsigned long integer. 
  6960.  
  6961.  "float" 
  6962.  "float32" 
  6963.  "real*4" 
  6964.            Single precision float. 
  6965.  
  6966.  "double" 
  6967.  "float64" 
  6968.  "real*8" 
  6969.            Double precision float. 
  6970.  
  6971.  "integer*2" 
  6972.  "int16" 
  6973.            Two byte integer. 
  6974.  
  6975.  "integer*4" 
  6976.  "int32" 
  6977.            Four byte integer. 
  6978.  
  6979.  The default precision is "uchar". 
  6980.  
  6981.  The optional argument skip specifies the number of bytes to skip before each 
  6982.  element is read.  If it is not specified, a value of 0 is assumed. 
  6983.  
  6984.  The optional argument arch is a string specifying the data format for the 
  6985.  file.  Valid values are 
  6986.  
  6987.  "native" 
  6988.            The format of the current machine. 
  6989.  
  6990.  "ieee-le" 
  6991.            IEEE big endian. 
  6992.  
  6993.  "ieee-be" 
  6994.            IEEE little endian. 
  6995.  
  6996.  "vaxd" 
  6997.            VAX D floating format. 
  6998.  
  6999.  "vaxg" 
  7000.            VAX G floating format. 
  7001.  
  7002.  "cray" 
  7003.            Cray floating format. 
  7004.  
  7005.  Conversions are currently only supported for "ieee-be" and "ieee-le" formats. 
  7006.  
  7007.  The data read from the file is returned in val, and the number of values read 
  7008.  is returned in count 
  7009.  
  7010.  Built-in Function: count = fwrite (fid, data, precision, skip, arch) 
  7011.  Write data in binary form of type precision to the specified file ID fid, 
  7012.  returning the number of values successfully written to the file. 
  7013.  
  7014.  The argument data is a matrix of values that are to be written to the file. 
  7015.  The values are extracted in column-major order. 
  7016.  
  7017.  The remaining arguments precision, skip, and arch are optional, and are 
  7018.  interpreted as described for fread. 
  7019.  
  7020.  The behavior of fwrite is undefined if the values in data are too large to fit 
  7021.  in the specified precision. 
  7022.  
  7023.  
  7024. ΓòÉΓòÉΓòÉ 16.2.17. Temporary Files ΓòÉΓòÉΓòÉ
  7025.  
  7026. Built-in Function:  tmpnam () 
  7027. Return a unique temporary file name as a string. 
  7028.  
  7029. Since the named file is not opened, by tmpnam, it is possible (though 
  7030. relatively unlikely) that it will not be available by the time your program 
  7031. attempts to open it. 
  7032.  
  7033.  
  7034. ΓòÉΓòÉΓòÉ 16.2.18. End of File and Errors ΓòÉΓòÉΓòÉ
  7035.  
  7036. Built-in Function:  feof (fid) 
  7037. Return 1 if an end-of-file condition has been encountered for a given file and 
  7038. 0 otherwise.  Note that it will only return 1 if the end of the file has 
  7039. already been encountered, not if the next read operation will result in an 
  7040. end-of-file condition. 
  7041.  
  7042. Built-in Function:  ferror (fid) 
  7043. Return 1 if an error condition has been encountered for a given file and 0 
  7044. otherwise.  Note that it will only return 1 if an error has already been 
  7045. encountered, not if the next operation will result in an error condition. 
  7046.  
  7047. Built-in Function:  freport () 
  7048. Print a list of which files have been opened, and whether they are open for 
  7049. reading, writing, or both.  For example, 
  7050.  
  7051. freport ()
  7052.  
  7053.      -|  number  mode  name
  7054.      -|
  7055.      -|       0     r  stdin
  7056.      -|       1     w  stdout
  7057.      -|       2     w  stderr
  7058.      -|       3     r  myfile
  7059.  
  7060.  
  7061. ΓòÉΓòÉΓòÉ 16.2.19. File Positioning ΓòÉΓòÉΓòÉ
  7062.  
  7063. Three functions are available for setting and determining the position of the 
  7064. file pointer for a given file. 
  7065.  
  7066. Built-in Function:  ftell (fid) 
  7067. Return the position of the file pointer as the number of characters from the 
  7068. beginning of the file fid. 
  7069.  
  7070. Built-in Function:  fseek (fid, offset, origin) 
  7071. Set the file pointer to any location within the file fid.  The pointer is 
  7072. positioned offset characters from the origin, which may be one of the 
  7073. predefined variables SEEK_CUR (current position), SEEK_SET (beginning), or 
  7074. SEEK_END (end of file). If origin is omitted, SEEK_SET is assumed.  The offset 
  7075. must be zero, or a value returned by ftell (in which case origin must be 
  7076. SEEK_SET. 
  7077.  
  7078. Built-in Variable: SEEK_SET 
  7079.  
  7080. Built-in Variable: SEEK_CUR 
  7081.  
  7082. Built-in Variable: SEEK_END 
  7083. These variables may be used as the optional third argument for the function 
  7084. fseek. 
  7085.  
  7086. Built-in Function:  frewind (fid) 
  7087. Move the file pointer to the beginning of the file fid, returning 1 for 
  7088. success, and 0 if an error was encountered.  It is equivalent to fseek (fid, 0, 
  7089. SEEK_SET). 
  7090.  
  7091. The following example stores the current file position in the variable marker, 
  7092. moves the pointer to the beginning of the file, reads four characters, and then 
  7093. returns to the original position. 
  7094.  
  7095. marker = ftell (myfile);
  7096. frewind (myfile);
  7097. fourch = fgets (myfile, 4);
  7098. fseek (myfile, marker, SEEK_SET);
  7099.  
  7100.  
  7101. ΓòÉΓòÉΓòÉ 17. Plotting ΓòÉΓòÉΓòÉ
  7102.  
  7103. All of Octave's plotting functions use gnuplot to handle the actual graphics. 
  7104. There are two low-level functions, gplot and gsplot, that behave almost exactly 
  7105. like the corresponding gnuplot functions plot and splot.  A number of other 
  7106. higher level plotting functions, patterned after the graphics functions found 
  7107. in Matlab version 3.5, are also available. These higher level functions are all 
  7108. implemented in terms of the two low-level plotting functions. 
  7109.  
  7110.  Two-Dimensional Plotting 
  7111.  Specialized Two-Dimensional Plots 
  7112.  Three-Dimensional Plotting 
  7113.  Plot Annotations 
  7114.  Multiple Plots on One Page 
  7115.  
  7116.  
  7117. ΓòÉΓòÉΓòÉ 17.1. Two-Dimensional Plotting ΓòÉΓòÉΓòÉ
  7118.  
  7119. Command: gplot ranges expression using title style 
  7120. Generate a 2-dimensional plot. 
  7121.  
  7122. The ranges, using, title, and style arguments are optional, and the using, 
  7123. title and style qualifiers may appear in any order after the expression.  You 
  7124. may plot multiple expressions with a single command by separating them with 
  7125. commas.  Each expression may have its own set of qualifiers. 
  7126.  
  7127. The optional item ranges has the syntax 
  7128.  
  7129. [ x_lo : x_up ] [ y_lo : y_up ]
  7130.  
  7131. and may be used to specify the ranges for the axes of the plot, independent of 
  7132. the actual range of the data.  The range for the y axes and any of the 
  7133. individual limits may be omitted.  A range [:] indicates that the default 
  7134. limits should be used.  This normally means that a range just large enough to 
  7135. include all the data points will be used. 
  7136.  
  7137. The expression to be plotted must not contain any literal matrices (e.g. [ 1, 
  7138. 2; 3, 4 ]) since it is nearly impossible to distinguish a plot range from a 
  7139. matrix of data. 
  7140.  
  7141. See the help for gnuplot for a description of the syntax for the optional 
  7142. items. 
  7143.  
  7144. By default, the gplot command plots the second column of a matrix versus the 
  7145. first.  If the matrix only has one column, it is taken as a vector of 
  7146. y-coordinates and the x-coordinate is taken as the element index, starting with 
  7147. zero.  For example, 
  7148.  
  7149. gplot rand (100,1) with linespoints
  7150.  
  7151. will plot 100 random values and connect them with lines.  When gplot is used to 
  7152. plot a column vector, the indices of the elements are taken as x values. 
  7153.  
  7154.  If there are more than two columns, you can choose which columns to plot with 
  7155. the using qualifier. For example, given the data 
  7156.  
  7157. x = (-10:0.1:10)';
  7158. data = [x, sin(x), cos(x)];
  7159.  
  7160. the command 
  7161.  
  7162. gplot [-11:11] [-1.1:1.1] \
  7163.   data with lines, data using 1:3 with impulses
  7164.  
  7165. will plot two lines.  The first line is generated by the command data with 
  7166. lines, and is a graph of the sine function over the range -10 to 10.  The data 
  7167. is taken from the first two columns of the matrix because columns to plot were 
  7168. not specified with the using qualifier. 
  7169.  
  7170. The clause using 1:3 in the second part of this plot command specifies that the 
  7171. first and third columns of the matrix data should be taken as the values to 
  7172. plot. 
  7173.  
  7174. In this example, the ranges have been explicitly specified to be a bit larger 
  7175. than the actual range of the data so that the curves do not touch the border of 
  7176. the plot. 
  7177.  
  7178. Command: gset options 
  7179.  
  7180. Command: gshow options 
  7181.  
  7182. Command: replot options 
  7183. In addition to the basic plotting commands, the whole range of gset and gshow 
  7184. commands from gnuplot are available, as is replot. 
  7185.  
  7186. Note that in Octave 2.0, the set and show commands were renamed to gset and 
  7187. gshow in order to allow for compatibility with the Matlab graphics and GUI 
  7188. commands in a future version of Octave.  (For now, the old set and show 
  7189. commands do work, but they print an annoying warning message to try to get 
  7190. people to switch to using gset and gshow.) 
  7191.  
  7192. The gset and gshow commands allow you to set and show gnuplot parameters.  For 
  7193. more information about the gset and gshow commands, see the documentation for 
  7194. set and show in the gnuplot user's guide (also available on line if you run 
  7195. gnuplot directly, instead of running it from Octave). 
  7196.  
  7197. The replot command allows you to force the plot to be redisplayed.  This is 
  7198. useful if you have changed something about the plot, such as the title or axis 
  7199. labels.  The replot command also accepts the same arguments as gplot or gsplot 
  7200. (except for data ranges) so you can add additional lines to existing plots. 
  7201.  
  7202. For example, 
  7203.  
  7204. gset term tek40
  7205. gset output "/dev/plotter"
  7206. gset title "sine with lines and cosine with impulses"
  7207. replot "sin (x) w l"
  7208.  
  7209. will change the terminal type for plotting, add a title to the current plot, 
  7210. add a graph of sin (x) to the plot, and force the new plot to be sent to the 
  7211. plot device.  This last step is normally required in order to update the plot. 
  7212. This default is reasonable for slow terminals or hardcopy output devices 
  7213. because even when you are adding additional lines with a replot command, 
  7214. gnuplot always redraws the entire plot, and you probably don't want to have a 
  7215. completely new plot generated every time something as minor as an axis label 
  7216. changes. 
  7217.  
  7218. The command shg is equivalent to executing replot without any arguments. 
  7219.  
  7220. Built-in Variable: automatic_replot 
  7221. You can tell Octave to redisplay the plot each time anything about it changes 
  7222. by setting the value of the builtin variable automatic_replot to a nonzero 
  7223. value.  Since this is fairly inefficient, the default value is 0. 
  7224.  
  7225. Note that NaN values in the plot data are automatically omitted, and Inf values 
  7226. are converted to a very large value before calling gnuplot. 
  7227.  
  7228. The Matlab-style two-dimensional plotting commands are: 
  7229.  
  7230. Function File:  plot (args) 
  7231. This function produces two-dimensional plots.  Many different combinations of 
  7232. arguments are possible.  The simplest form is 
  7233.  
  7234. plot (y)
  7235.  
  7236. where the argument is taken as the set of y coordinates and the x coordinates 
  7237. are taken to be the indices of the elements, starting with 1. 
  7238.  
  7239. If more than one argument is given, they are interpreted as 
  7240.  
  7241. plot (x, y, fmt ...)
  7242.  
  7243. where y and fmt are optional, and any number of argument sets may appear.  The 
  7244. x and y values are interpreted as follows: 
  7245.  
  7246.      If a single data argument is supplied, it is taken as the set of y 
  7247.       coordinates and the x coordinates are taken to be the indices of the 
  7248.       elements, starting with 1. 
  7249.  
  7250.      If the first argument is a vector and the second is a matrix, the the 
  7251.       vector is plotted versus the columns (or rows) of the matrix. (using 
  7252.       whichever combination matches, with columns tried first.) 
  7253.  
  7254.      If the first argument is a matrix and the second is a vector, the the 
  7255.       columns (or rows) of the matrix are plotted versus the vector. (using 
  7256.       whichever combination matches, with columns tried first.) 
  7257.  
  7258.      If both arguments are vectors, the elements of y are plotted versus the 
  7259.       elements of x. 
  7260.  
  7261.      If both arguments are matrices, the columns of y are plotted versus the 
  7262.       columns of x.  In this case, both matrices must have the same number of 
  7263.       rows and columns and no attempt is made to transpose the arguments to 
  7264.       make the number of rows match. 
  7265.  
  7266.       If both arguments are scalars, a single point is plotted. 
  7267.  
  7268.  The fmt argument, if present is interpreted as follows.  If fmt is missing, 
  7269.  the default gnuplot line style is assumed. 
  7270.  
  7271.  `-' 
  7272.            Set lines plot style (default). 
  7273.  
  7274.  `.' 
  7275.            Set dots plot style. 
  7276.  
  7277.  `@' 
  7278.            Set points plot style. 
  7279.  
  7280.  `-@' 
  7281.            Set linespoints plot style. 
  7282.  
  7283.  `^' 
  7284.            Set impulses plot style. 
  7285.  
  7286.  `L' 
  7287.            Set steps plot style. 
  7288.  
  7289.  `#' 
  7290.            Set boxes plot style. 
  7291.  
  7292.  `~' 
  7293.            Set errorbars plot style. 
  7294.  
  7295.  `#~' 
  7296.            Set boxerrorbars plot style. 
  7297.  
  7298.  `n' 
  7299.            Interpreted as the plot color if n is an integer in the range 1 to 
  7300.            6. 
  7301.  
  7302.  `nm' 
  7303.            If nm is a two digit integer and m is an integer in the range 1 to 
  7304.            6, m is interpreted as the point style.  This is only valid in 
  7305.            combination with the @ or -@ specifiers. 
  7306.  
  7307.  `c' 
  7308.            If c is one of "r", "g", "b", "m", "c", or "w", it is interpreted as 
  7309.            the plot color (red, green, blue, magenta, cyan, or white). 
  7310.  
  7311.  `+' 
  7312.  `*' 
  7313.  `o' 
  7314.  `x' 
  7315.            Used in combination with the points or linespoints styles, set the 
  7316.            point style. 
  7317.  
  7318.  The color line styles have the following meanings on terminals that support 
  7319.  color. 
  7320.  
  7321.   Number  Gnuplot colors  (lines)points style
  7322.     1       red                   *
  7323.     2       green                 +
  7324.     3       blue                  o
  7325.     4       magenta               x
  7326.     5       cyan                house
  7327.     6       brown            there exists
  7328.  
  7329.  Here are some plot examples: 
  7330.  
  7331.   plot (x, y, "@12", x, y2, x, y3, "4", x, y4, "+")
  7332.  
  7333.  This command will plot y with points of type 2 (displayed as `+') and color 1 
  7334.  (red), y2 with lines, y3 with lines of color 4 (magenta) and y4 with points 
  7335.  displayed as `+'. 
  7336.  
  7337.   plot (b, "*")
  7338.  
  7339.  This command will plot the data in the variable b will be plotted with points 
  7340.  displayed as `*'. 
  7341.  
  7342.  Function File:  hold args 
  7343.  Tell Octave to `hold' the current data on the plot when executing subsequent 
  7344.  plotting commands.  This allows you to execute a series of plot commands and 
  7345.  have all the lines end up on the same figure.  The default is for each new 
  7346.  plot command to clear the plot device first. For example, the command 
  7347.  
  7348.   hold on
  7349.  
  7350.  turns the hold state on.  An argument of off turns the hold state off, and 
  7351.  hold with no arguments toggles the current hold state. 
  7352.  
  7353.  Function File:  ishold 
  7354.  Return 1 if the next line will be added to the current plot, or 0 if the plot 
  7355.  device will be cleared before drawing the next line. 
  7356.  
  7357.  Function File:  clearplot 
  7358.  
  7359.  Function File:  clg 
  7360.  Clear the plot window and any titles or axis labels.  The name clg is aliased 
  7361.  to clearplot for compatibility with Matlab. 
  7362.  
  7363.  The commands gplot clear, gsplot clear, and replot clear are equivalent to 
  7364.  clearplot.  (Previously, commands like gplot clear would evaluate clear as an 
  7365.  ordinary expression and clear all the visible variables.) 
  7366.  
  7367.  Function File:  closeplot 
  7368.  Close stream to the gnuplot subprocess.  If you are using X11, this will close 
  7369.  the plot window. 
  7370.  
  7371.  Function File:  purge_tmp_files 
  7372.  Delete the temporary files created by the plotting commands. 
  7373.  
  7374.  Octave creates temporary data files for gnuplot and then sends commands to 
  7375.  gnuplot through a pipe.  Octave will delete the temporary files on exit, but 
  7376.  if you are doing a lot of plotting you may want to clean up in the middle of a 
  7377.  session. 
  7378.  
  7379.  A future version of Octave will eliminate the need to use temporary files to 
  7380.  hold the plot data. 
  7381.  
  7382.  Function File:  axis (limits) 
  7383.  Sets the axis limits for plots. 
  7384.  
  7385.  The argument limits should be a 2, 4, or 6 element vector.  The first and 
  7386.  second elements specify the lower and upper limits for the x axis.  The third 
  7387.  and fourth specify the limits for the y axis, and the fifth and sixth specify 
  7388.  the limits for the z axis. 
  7389.  
  7390.  With no arguments, axis turns autoscaling on. 
  7391.  
  7392.  If your plot is already drawn, then you need to use replot before the new axis 
  7393.  limits will take effect.  You can get this to happen automatically by setting 
  7394.  the built-in variable automatic_replot to a nonzero value. 
  7395.  
  7396.  
  7397. ΓòÉΓòÉΓòÉ 17.2. Specialized Two-Dimensional Plots ΓòÉΓòÉΓòÉ
  7398.  
  7399. Function File:  bar (x, y) 
  7400. Given two vectors of x-y data, bar produces a bar graph. 
  7401.  
  7402. If only one argument is given, it is taken as a vector of y-values and the x 
  7403. coordinates are taken to be the indices of the elements. 
  7404.  
  7405. If two output arguments are specified, the data are generated but not plotted. 
  7406. For example, 
  7407.  
  7408. bar (x, y);
  7409.  
  7410. and 
  7411.  
  7412. [xb, yb] = bar (x, y);
  7413. plot (xb, yb);
  7414.  
  7415. are equivalent. 
  7416.  
  7417. Function File:  contour (z, n, x, y) 
  7418. Make a contour plot of the three-dimensional surface described by z.  Someone 
  7419. needs to improve gnuplot's contour routines before this will be very useful. 
  7420.  
  7421. Function File:  hist (y, x) 
  7422. Produce histogram counts or plots. 
  7423.  
  7424. With one vector input argument, plot a histogram of the values with 10 bins. 
  7425. The range of the histogram bins is determined by the range of the data. 
  7426.  
  7427. Given a second scalar argument, use that as the number of bins. 
  7428.  
  7429. Given a second vector argument, use that as the centers of the bins, with the 
  7430. width of the bins determined from the adjacent values in the vector. 
  7431.  
  7432. Extreme values are lumped in the first and last bins. 
  7433.  
  7434. With two output arguments, produce the values nn and xx such that bar (xx, nn) 
  7435. will plot the histogram. 
  7436.  
  7437. Function File:  loglog (args) 
  7438. Make a two-dimensional plot using log scales for both axes.  See the 
  7439. description of plot above for a description of the arguments that loglog will 
  7440. accept. 
  7441.  
  7442. Function File:  polar (theta, rho) 
  7443. Make a two-dimensional plot given polar the coordinates theta and rho. 
  7444.  
  7445. Function File:  semilogx (args) 
  7446. Make a two-dimensional plot using a log scale for the x axis.  See the 
  7447. description of plot above for a description of the arguments that semilogx will 
  7448. accept. 
  7449.  
  7450. Function File:  semilogy (args) 
  7451. Make a two-dimensional plot using a log scale for the y axis.  See the 
  7452. description of plot above for a description of the arguments that semilogy will 
  7453. accept. 
  7454.  
  7455. Function File:  stairs (x, y) 
  7456. Given two vectors of x-y data, bar produces a `stairstep' plot. 
  7457.  
  7458. If only one argument is given, it is taken as a vector of y-values and the x 
  7459. coordinates are taken to be the indices of the elements. 
  7460.  
  7461. If two output arguments are specified, the data are generated but not plotted. 
  7462. For example, 
  7463.  
  7464. stairs (x, y);
  7465.  
  7466. and 
  7467.  
  7468. [xs, ys] = stairs (x, y);
  7469. plot (xs, ys);
  7470.  
  7471. are equivalent. 
  7472.  
  7473.  
  7474. ΓòÉΓòÉΓòÉ 17.3. Three-Dimensional Plotting ΓòÉΓòÉΓòÉ
  7475.  
  7476. Command: gsplot ranges expression using title style 
  7477. Generate a 3-dimensional plot. 
  7478.  
  7479. The ranges, using, title, and style arguments are optional, and the using, 
  7480. title and style qualifiers may appear in any order after the expression.  You 
  7481. may plot multiple expressions with a single command by separating them with 
  7482. commas.  Each expression may have its own set of qualifiers. 
  7483.  
  7484. The optional item ranges has the syntax 
  7485.  
  7486. [ x_lo : x_up ] [ y_lo : y_up ] [ z_lo : z_up ]
  7487.  
  7488. and may be used to specify the ranges for the axes of the plot, independent of 
  7489. the actual range of the data.  The range for the y and z axes and any of the 
  7490. individual limits may be omitted.  A range [:] indicates that the default 
  7491. limits should be used.  This normally means that a range just large enough to 
  7492. include all the data points will be used. 
  7493.  
  7494. The expression to be plotted must not contain any literal matrices (e.g. [ 1, 
  7495. 2; 3, 4 ]) since it is nearly impossible to distinguish a plot range from a 
  7496. matrix of data. 
  7497.  
  7498. See the help for gnuplot for a description of the syntax for the optional 
  7499. items. 
  7500.  
  7501. By default, the gsplot command plots each column of the expression as the z 
  7502. value, using the row index as the x value, and the column index as the y value. 
  7503. The indices are counted from zero, not one.  For example, 
  7504.  
  7505. gsplot rand (5, 2)
  7506.  
  7507. will plot a random surface, with the x and y values taken from the row and 
  7508. column indices of the matrix. 
  7509.  
  7510. If parametric plotting mode is set (using the command gset parametric, then 
  7511. gsplot takes the columns of the matrix three at a time as the x, y and z values 
  7512. that define a line in three space.  Any extra columns are ignored, and the x 
  7513. and y values are expected to be sorted.  For example, with parametric set, it 
  7514. makes sense to plot a matrix like 
  7515.  
  7516. 1 1 3 2 1 6 3 1 9
  7517. 1 2 2 2 2 5 3 2 8
  7518. 1 3 1 2 3 4 3 3 7
  7519.  
  7520. but not rand (5, 30). 
  7521.  
  7522. The Matlab-style three-dimensional plotting commands are: 
  7523.  
  7524. Function File:  mesh (x, y, z) 
  7525. Plot a mesh given matrices x, and y from meshdom and a matrix z corresponding 
  7526. to the x and y coordinates of the mesh. 
  7527.  
  7528. Function File:  meshdom (x, y) 
  7529. Given vectors of x and y coordinates, return two matrices corresponding to the 
  7530. x and y coordinates of the mesh. 
  7531.  
  7532. See the file `sombrero.m' for an example of using mesh and meshdom. 
  7533.  
  7534. Built-in Variable: gnuplot_binary 
  7535. The name of the program invoked by the plot command.  The default value is 
  7536. "gnuplot".  See Installation. 
  7537.  
  7538. Built-in Variable: gnuplot_has_frames 
  7539. If the value of this variable is nonzero, Octave assumes that your copy of 
  7540. gnuplot has support for multiple frames that is included in recent 3.6beta 
  7541. releases.  It's initial value is determined by configure, but it can be changed 
  7542. in your startup script or at the command line in case configure got it wrong, 
  7543. or if you upgrade your gnuplot installation. 
  7544.  
  7545. Function File:  figure (n) 
  7546. Set the current plot window to plot window n.  This function currently requires 
  7547. X11 and a version of gnuplot that supports multiple frames. 
  7548.  
  7549. Built-in Variable: gnuplot_has_multiplot 
  7550. If the value of this variable is nonzero, Octave assumes that your copy of 
  7551. gnuplot has the multiplot support that is included in recent 3.6beta releases. 
  7552. It's initial value is determined by configure, but it can be changed in your 
  7553. startup script or at the command line in case configure got it wrong, or if you 
  7554. upgrade your gnuplot installation. 
  7555.  
  7556.  
  7557. ΓòÉΓòÉΓòÉ 17.4. Plot Annotations ΓòÉΓòÉΓòÉ
  7558.  
  7559. Function File:  grid 
  7560. For two-dimensional plotting, force the display of a grid on the plot. 
  7561.  
  7562. Function File:  title (string) 
  7563. Specify a title for the plot.  If you already have a plot displayed, use the 
  7564. command replot to redisplay it with the new title. 
  7565.  
  7566. Function File:  xlabel (string) 
  7567.  
  7568. Function File:  ylabel (string) 
  7569.  
  7570. Function File:  zlabel (string) 
  7571. Specify x, y, and z axis labels for the plot.  If you already have a plot 
  7572. displayed, use the command replot to redisplay it with the new labels. 
  7573.  
  7574.  
  7575. ΓòÉΓòÉΓòÉ 17.5. Multiple Plots on One Page ΓòÉΓòÉΓòÉ
  7576.  
  7577. The following functions all require a version of gnuplot that supports the 
  7578. multiplot feature. 
  7579.  
  7580. Function File:  mplot (x, y) 
  7581.  
  7582. Function File:  mplot (x, y, fmt) 
  7583.  
  7584. Function File:  mplot (x1, y1, x2, y2) 
  7585. This is a modified version of the plot function that works with the multiplot 
  7586. version of gnuplot to plot multiple plots per page. This plot version 
  7587. automatically advances to the next subplot position after each set of arguments 
  7588. are processed. 
  7589.  
  7590. See the description of the plot function for the various options. 
  7591.  
  7592. Function File:  multiplot (xn, yn) 
  7593. Sets and resets multiplot mode. 
  7594.  
  7595. If the arguments are non-zero, multiplot will set up multiplot mode with xn, yn 
  7596. subplots along the x and y axes.  If both arguments are zero, multiplot closes 
  7597. multiplot mode. 
  7598.  
  7599. Function File:  oneplot () 
  7600. If in multiplot mode, switches to single plot mode. 
  7601.  
  7602. Function File:  plot_border (...) 
  7603. Multiple arguments allowed to specify the sides on which the border is shown. 
  7604. Allowed arguments include: 
  7605.  
  7606.  "blank" 
  7607.            No borders displayed. 
  7608.  
  7609.  "all" 
  7610.            All borders displayed 
  7611.  
  7612.  "north" 
  7613.            North Border 
  7614.  
  7615.  "south" 
  7616.            South Border 
  7617.  
  7618.  "east" 
  7619.            East Border 
  7620.  
  7621.  "west" 
  7622.            West Border 
  7623.  
  7624.  The arguments may be abbreviated to single characters.  Without any arguments, 
  7625.  plot_border turns borders off. 
  7626.  
  7627.  Function File:  subplot (rows, cols, index) 
  7628.  
  7629.  Function File:  subplot (rcn) 
  7630.  Sets gnuplot in multiplot mode and plots in location given by index (there are 
  7631.  cols by rows subwindows). 
  7632.  
  7633.  Input: 
  7634.  
  7635.  rows 
  7636.            Number of rows in subplot grid. 
  7637.  
  7638.  columns 
  7639.            Number of columns in subplot grid. 
  7640.  
  7641.  index 
  7642.            Index of subplot where to make the next plot. 
  7643.  
  7644.  If only one argument is supplied, then it must be a three digit value 
  7645.  specifying the location in digits 1 (rows) and 2 (columns) and the plot index 
  7646.  in digit 3. 
  7647.  
  7648.  The plot index runs row-wise.  First all the columns in a row are filled and 
  7649.  then the next row is filled. 
  7650.  
  7651.  For example, a plot with 4 by 2 grid will have plot indices running as 
  7652.  follows: 
  7653.  
  7654.   +-----+-----+-----+-----+
  7655.   |  1  |  2  |  3  |  4  |
  7656.   +-----+-----+-----+-----+
  7657.   |  5  |  6  |  7  |  8  |
  7658.   +-----+-----+-----+-----+
  7659.  
  7660.  Function File:  subwindow (xn, yn) 
  7661.  Sets the subwindow position in multiplot mode for the next plot.  The 
  7662.  multiplot mode has to be previously initialized using the multiplot function, 
  7663.  otherwise this command just becomes an alias to multiplot 
  7664.  
  7665.  Function File:  top_title (string) 
  7666.  
  7667.  Function File:  bottom_title (string) 
  7668.  Makes a title with text string at the top (bottom) of the plot. 
  7669.  
  7670.  
  7671. ΓòÉΓòÉΓòÉ 18. Matrix Manipulation ΓòÉΓòÉΓòÉ
  7672.  
  7673. There are a number of functions available for checking to see if the elements 
  7674. of a matrix meet some condition, and for rearranging the elements of a matrix. 
  7675. For example, Octave can easily tell you if all the elements of a matrix are 
  7676. finite, or are less than some specified value.  Octave can also rotate the 
  7677. elements, extract the upper- or lower-triangular parts, or sort the columns of 
  7678. a matrix. 
  7679.  
  7680.  Finding Elements and Checking Conditions 
  7681.  Rearranging Matrices 
  7682.  Special Utility Matrices 
  7683.  Famous Matrices 
  7684.  
  7685.  
  7686. ΓòÉΓòÉΓòÉ 18.1. Finding Elements and Checking Conditions ΓòÉΓòÉΓòÉ
  7687.  
  7688. The functions any and all are useful for determining whether any or all of the 
  7689. elements of a matrix satisfy some condition. The find function is also useful 
  7690. in determining which elements of a matrix meet a specified condition. 
  7691.  
  7692. Built-in Function:  any (x) 
  7693. For a vector argument, return 1 if any element of the vector is nonzero. 
  7694.  
  7695. For a matrix argument, return a row vector of ones and zeros with each element 
  7696. indicating whether any of the elements of the corresponding column of the 
  7697. matrix are nonzero.  For example, 
  7698.  
  7699. any (eye (2, 4))
  7700.      => [ 1, 1, 0, 0 ]
  7701.  
  7702. To see if any of the elements of a matrix are nonzero, you can use a statement 
  7703. like 
  7704.  
  7705. any (any (a))
  7706.  
  7707. Built-in Function:  all (x) 
  7708. The function all behaves like the function any, except that it returns true 
  7709. only if all the elements of a vector, or all the elements in a column of a 
  7710. matrix, are nonzero. 
  7711.  
  7712. Since the comparison operators (see Comparison Ops) return matrices of ones and 
  7713. zeros, it is easy to test a matrix for many things, not just whether the 
  7714. elements are nonzero.  For example, 
  7715.  
  7716. all (all (rand (5) < 0.9))
  7717.      => 0
  7718.  
  7719. tests a random 5 by 5 matrix to see if all of its elements are less than 0.9. 
  7720.  
  7721. Note that in conditional contexts (like the test clause of if and while 
  7722. statements) Octave treats the test as if you had typed all (all (condition)). 
  7723.  
  7724. Function File: [err, y1, ...] = common_size (x1, ...) 
  7725. Determine if all input arguments are either scalar or of common size.  If so, 
  7726. err is zero, and yi is a matrix of the common size with all entries equal to xi 
  7727. if this is a scalar or xi otherwise.  If the inputs cannot be brought to a 
  7728. common size, errorcode is 1, and yi is xi.  For example, 
  7729.  
  7730. [errorcode, a, b] = common_size ([1 2; 3 4], 5)
  7731.      => errorcode = 0
  7732.      => a = [ 1, 2; 3, 4 ]
  7733.      => b = [ 5, 5; 5, 5 ]
  7734.  
  7735. This is useful for implementing functions where arguments can either be scalars 
  7736. or of common size. 
  7737.  
  7738. Function File:  diff (x, k) 
  7739. If x is a vector of length n, diff (x) is the vector of first differences  x(2) 
  7740. - x(1), ..., x(n) - x(n-1). 
  7741.  
  7742. If x is a matrix, diff (x) is the matrix of column differences. 
  7743.  
  7744. The second argument is optional.  If supplied, diff (x, k), where k is a 
  7745. nonnegative integer, returns the k-th differences. 
  7746.  
  7747. Mapping Function:  isinf (x) 
  7748. Return 1 for elements of x that are infinite and zero otherwise. For example, 
  7749.  
  7750. isinf ([13, Inf, NaN])
  7751.      => [ 0, 1, 0 ]
  7752.  
  7753. Mapping Function:  isnan (x) 
  7754. Return 1 for elements of x that are NaN values and zero otherwise. For example, 
  7755.  
  7756. isnan ([13, Inf, NaN])
  7757.      => [ 0, 0, 1 ]
  7758.  
  7759. Mapping Function:  finite (x) 
  7760. Return 1 for elements of x that are NaN values and zero otherwise. For example, 
  7761.  
  7762. finite ([13, Inf, NaN])
  7763.      => [ 1, 0, 0 ]
  7764.  
  7765. Loadable Function:  find (x) 
  7766. Return a vector of indices of nonzero elements of a matrix.  To obtain a single 
  7767. index for each matrix element, Octave pretends that the columns of a matrix 
  7768. form one long vector (like Fortran arrays are stored).  For example, 
  7769.  
  7770. find (eye (2))
  7771.      => [ 1; 4 ]
  7772.  
  7773. If two outputs are requested, find returns the row and column indices of 
  7774. nonzero elements of a matrix.  For example, 
  7775.  
  7776. [i, j] = find (2 * eye (2))
  7777.      => i = [ 1; 2 ]
  7778.      => j = [ 1; 2 ]
  7779.  
  7780. If three outputs are requested, find also returns a vector containing the 
  7781. nonzero values.  For example, 
  7782.  
  7783. [i, j, v] = find (3 * eye (2))
  7784.      => i = [ 1; 2 ]
  7785.      => j = [ 1; 2 ]
  7786.      => v = [ 3; 3 ]
  7787.  
  7788.  
  7789. ΓòÉΓòÉΓòÉ 18.2. Rearranging Matrices ΓòÉΓòÉΓòÉ
  7790.  
  7791. Function File:  fliplr (x) 
  7792. Return a copy of x with the order of the columns reversed.  For example, 
  7793.  
  7794. fliplr ([1, 2; 3, 4])
  7795.      =>  2  1
  7796.          4  3
  7797.  
  7798. Function File:  flipud (x) 
  7799. Return a copy of x with the order of the rows reversed.  For example, 
  7800.  
  7801. flipud ([1, 2; 3, 4])
  7802.      =>  3  4
  7803.          1  2
  7804.  
  7805. Function File:  rot90 (x, n) 
  7806. Return a copy of x with the elements rotated counterclockwise in 90-degree 
  7807. increments.  The second argument is optional, and specifies how many 90-degree 
  7808. rotations are to be applied (the default value is 1). Negative values of n 
  7809. rotate the matrix in a clockwise direction. For example, 
  7810.  
  7811. rot90 ([1, 2; 3, 4], -1)
  7812.      =>  3  1
  7813.          4  2
  7814.  
  7815. rotates the given matrix clockwise by 90 degrees.  The following are all 
  7816. equivalent statements: 
  7817.  
  7818. rot90 ([1, 2; 3, 4], -1)
  7819. ==
  7820. rot90 ([1, 2; 3, 4], 3)
  7821. ==
  7822. rot90 ([1, 2; 3, 4], 7)
  7823.  
  7824. Function File:  reshape (a, m, n) 
  7825. Return a matrix with m rows and n columns whose elements are taken from the 
  7826. matrix a.  To decide how to order the elements, Octave pretends that the 
  7827. elements of a matrix are stored in column-major order (like Fortran arrays are 
  7828. stored). 
  7829.  
  7830. For example, 
  7831.  
  7832. reshape ([1, 2, 3, 4], 2, 2)
  7833.      =>  1  3
  7834.          2  4
  7835.  
  7836. If the variable do_fortran_indexing is nonzero, the reshape function is 
  7837. equivalent to 
  7838.  
  7839. retval = zeros (m, n);
  7840. retval (:) = a;
  7841.  
  7842. but it is somewhat less cryptic to use reshape instead of the colon operator. 
  7843. Note that the total number of elements in the original matrix must match the 
  7844. total number of elements in the new matrix. 
  7845.  
  7846. Function File:  shift (x, b) 
  7847. If x is a vector, perform a circular shift of length b of the elements of x. 
  7848.  
  7849. If x is a matrix, do the same for each column of x. 
  7850.  
  7851. Loadable Function: [s, i] = sort (x) 
  7852. Return a copy of x with the elements elements arranged in increasing order. 
  7853. For matrices, sort orders the elements in each column. 
  7854.  
  7855. For example, 
  7856.  
  7857. sort ([1, 2; 2, 3; 3, 1])
  7858.      =>  1  1
  7859.          2  2
  7860.          3  3
  7861.  
  7862. The sort function may also be used to produce a matrix containing the original 
  7863. row indices of the elements in the sorted matrix.  For example, 
  7864.  
  7865. [s, i] = sort ([1, 2; 2, 3; 3, 1])
  7866.      => s = 1  1
  7867.             2  2
  7868.             3  3
  7869.      => i = 1  3
  7870.             2  1
  7871.             3  2
  7872.  
  7873. Since the sort function does not allow sort keys to be specified, it can't be 
  7874. used to order the rows of a matrix according to the values of the elements in 
  7875. various columns(6) in a single call.  Using the second output, however, it is 
  7876. possible to sort all rows based on the values in a given column.  Here's an 
  7877. example that sorts the rows of a matrix based on the values in the second 
  7878. column. 
  7879.  
  7880. a = [1, 2; 2, 3; 3, 1];
  7881. [s, i] = sort (a (:, 2));
  7882. a (i, :)
  7883.      =>  3  1
  7884.          1  2
  7885.          2  3
  7886.  
  7887. Function File:  tril (a, k) 
  7888.  
  7889. Function File:  triu (a, k) 
  7890. Return a new matrix formed by extracting extract the lower (tril) or upper 
  7891. (triu) triangular part of the matrix a, and setting all other elements to zero. 
  7892. The second argument is optional, and specifies how many diagonals above or 
  7893. below the main diagonal should also be set to zero. 
  7894.  
  7895. The default value of k is zero, so that triu and tril normally include the main 
  7896. diagonal as part of the result matrix. 
  7897.  
  7898. If the value of k is negative, additional elements above (for tril) or below 
  7899. (for triu) the main diagonal are also selected. 
  7900.  
  7901. The absolute value of k must not be greater than the number of sub- or 
  7902. super-diagonals. 
  7903.  
  7904. For example, 
  7905.  
  7906. tril (ones (3), -1)
  7907.      =>  0  0  0
  7908.          1  0  0
  7909.          1  1  0
  7910.  
  7911. and 
  7912.  
  7913. tril (ones (3), 1)
  7914.      =>  1  1  0
  7915.          1  1  1
  7916.          1  1  1
  7917.  
  7918. Function File:  vec (x) 
  7919. Return the vector obtained by stacking the columns of the matrix x one above 
  7920. the other. 
  7921.  
  7922. Function File:  vech (x) 
  7923. Return the vector obtained by eliminating all supradiagonal elements of the 
  7924. square matrix x and stacking the result one column above the other. 
  7925.  
  7926.  
  7927. ΓòÉΓòÉΓòÉ 18.3. Special Utility Matrices ΓòÉΓòÉΓòÉ
  7928.  
  7929. Built-in Function:  eye (x) 
  7930.  
  7931. Built-in Function:  eye (n, m) 
  7932. Return an identity matrix.  If invoked with a single scalar argument, eye 
  7933. returns a square matrix with the dimension specified.  If you supply two scalar 
  7934. arguments, eye takes them to be the number of rows and columns.  If given a 
  7935. vector with two elements, eye uses the values of the elements as the number of 
  7936. rows and columns, respectively.  For example, 
  7937.  
  7938. eye (3)
  7939.      =>  1  0  0
  7940.          0  1  0
  7941.          0  0  1
  7942.  
  7943. The following expressions all produce the same result: 
  7944.  
  7945. eye (2)
  7946. ==
  7947. eye (2, 2)
  7948. ==
  7949. eye (size ([1, 2; 3, 4])
  7950.  
  7951. For compatibility with Matlab, calling eye with no arguments is equivalent to 
  7952. calling it with an argument of 1. 
  7953.  
  7954. Built-in Function:  ones (x) 
  7955.  
  7956. Built-in Function:  ones (n, m) 
  7957. Return a matrix whose elements are all 1.  The arguments are handled the same 
  7958. as the arguments for eye. 
  7959.  
  7960. If you need to create a matrix whose values are all the same, you should use an 
  7961. expression like 
  7962.  
  7963. val_matrix = val * ones (n, m)
  7964.  
  7965. Built-in Function:  zeros (x) 
  7966.  
  7967. Built-in Function:  zeros (n, m) 
  7968. Return a matrix whose elements are all 0.  The arguments are handled the same 
  7969. as the arguments for eye. 
  7970.  
  7971. Loadable Function:  rand (x) 
  7972.  
  7973. Loadable Function:  rand (n, m) 
  7974.  
  7975. Loadable Function:  rand ("seed", x) 
  7976. Return a matrix with random elements uniformly distributed on the interval (0, 
  7977. 1).  The arguments are handled the same as the arguments for eye.  In addition, 
  7978. you can set the seed for the random number generator using the form 
  7979.  
  7980. rand ("seed", x)
  7981.  
  7982. where x is a scalar value.  If called as 
  7983.  
  7984. rand ("seed")
  7985.  
  7986. rand returns the current value of the seed. 
  7987.  
  7988. Loadable Function:  randn (x) 
  7989.  
  7990. Loadable Function:  randn (n, m) 
  7991.  
  7992. Loadable Function:  randn ("seed", x) 
  7993. Return a matrix with normally distributed random elements.  The arguments are 
  7994. handled the same as the arguments for eye.  In addition, you can set the seed 
  7995. for the random number generator using the form 
  7996.  
  7997. randn ("seed", x)
  7998.  
  7999. where x is a scalar value.  If called as 
  8000.  
  8001. randn ("seed")
  8002.  
  8003. randn returns the current value of the seed. 
  8004.  
  8005. The rand and randn functions use separate generators. This ensures that 
  8006.  
  8007. rand ("seed", 13);
  8008. randn ("seed", 13);
  8009. u = rand (100, 1);
  8010. n = randn (100, 1);
  8011.  
  8012. and 
  8013.  
  8014. rand ("seed", 13);
  8015. randn ("seed", 13);
  8016. u = zeros (100, 1);
  8017. n = zeros (100, 1);
  8018. for i = 1:100
  8019.   u(i) = rand ();
  8020.   n(i) = randn ();
  8021. end
  8022.  
  8023. produce equivalent results. 
  8024.  
  8025. Normally, rand and randn obtain their initial seeds from the system clock, so 
  8026. that the sequence of random numbers is not the same each time you run Octave. 
  8027. If you really do need for to reproduce a sequence of numbers exactly, you can 
  8028. set the seed to a specific value. 
  8029.  
  8030. If it is invoked without arguments, rand and randn return a single element of a 
  8031. random sequence. 
  8032.  
  8033. The rand and randn functions use Fortran code from Ranlib, a library of fortran 
  8034. routines for random number generation, compiled by Barry W. Brown and James 
  8035. Lovato of the Department of Biomathematics at The University of Texas, M.D. 
  8036. Anderson Cancer Center, Houston, TX 77030. 
  8037.  
  8038. Built-in Function:  diag (v, k) 
  8039. Return a diagonal matrix with vector v on diagonal k.  The second argument is 
  8040. optional.  If it is positive, the vector is placed on the k-th super-diagonal. 
  8041. If it is negative, it is placed on the -k-th sub-diagonal.  The default value 
  8042. of k is 0, and the vector is placed on the main diagonal.  For example, 
  8043.  
  8044. diag ([1, 2, 3], 1)
  8045.      =>  0  1  0  0
  8046.          0  0  2  0
  8047.          0  0  0  3
  8048.          0  0  0  0
  8049.  
  8050. The functions linspace and logspace make it very easy to create vectors with 
  8051. evenly or logarithmically spaced elements. See Ranges. 
  8052.  
  8053. Function File:  linspace (base, limit, n) 
  8054. Return a row vector with n linearly spaced elements between base and limit. 
  8055. The number of elements, n, must be greater than 1.  The base and limit are 
  8056. always included in the range.  If base is greater than limit, the elements are 
  8057. stored in decreasing order.  If the number of points is not specified, a value 
  8058. of 100 is used. 
  8059.  
  8060. The linspace function always returns a row vector, regardless of the value of 
  8061. prefer_column_vectors. 
  8062.  
  8063. Function File:  logspace (base, limit, n) 
  8064. Similar to linspace except that the values are logarithmically spaced from 
  8065. 10^base to 10^limit. 
  8066.  
  8067. If limit is equal to pi, the points are between 10^base and pi, not 10^base and 
  8068. 10^pi, in order to  be compatible with the corresponding Matlab function. 
  8069.  
  8070. Built-in Variable: treat_neg_dim_as_zero 
  8071. If the value of treat_neg_dim_as_zero is nonzero, expressions like 
  8072.  
  8073. eye (-1)
  8074.  
  8075. produce an empty matrix (i.e., row and column dimensions are zero). Otherwise, 
  8076. an error message is printed and control is returned to the top level.  The 
  8077. default value is 0. 
  8078.  
  8079.  
  8080. ΓòÉΓòÉΓòÉ 18.4. Famous Matrices ΓòÉΓòÉΓòÉ
  8081.  
  8082. The following functions return famous matrix forms. 
  8083.  
  8084. Function File:  hankel (c, r) 
  8085. Return the Hankel matrix constructed given the first column c, and (optionally) 
  8086. the last row r.  If the last element of c is not the same as the first element 
  8087. of r, the last element of c is used.  If the second argument is omitted, the 
  8088. last row is taken to be the same as the first column. 
  8089.  
  8090. A Hankel matrix formed from an m-vector c, and an n-vector r, has the elements 
  8091.  
  8092. H (i, j) = c (i+j-1),  i+j-1 <= m;
  8093. H (i, j) = r (i+j-m),  otherwise
  8094.  
  8095. Function File:  hilb (n) 
  8096. Return the Hilbert matrix of order n.  The i, j element of a Hilbert matrix is 
  8097. defined as 
  8098.  
  8099. H (i, j) = 1 / (i + j - 1)
  8100.  
  8101. Function File:  invhilb (n) 
  8102. Return the inverse of a Hilbert matrix of order n.  This is exact. Compare with 
  8103. the numerical calculation of inverse (hilb (n)), which suffers from the 
  8104. ill-conditioning of the Hilbert matrix, and the finite precision of your 
  8105. computer's floating point arithmetic. 
  8106.  
  8107. Function File:  sylvester_matrix (k) 
  8108. Return the Sylvester matrix of order n = 2^k. 
  8109.  
  8110. Function File:  toeplitz (c, r) 
  8111. Return the Toeplitz matrix constructed given the first column c, and 
  8112. (optionally) the first row r.  If the first element of c is not the same as the 
  8113. first element of r, the first element of c is used.  If the second argument is 
  8114. omitted, the first row is taken to be the same as the first column. 
  8115.  
  8116. A square Toeplitz matrix has the form 
  8117.  
  8118. c(0)  r(1)   r(2)  ...  r(n)
  8119. c(1)  c(0)   r(1)      r(n-1)
  8120. c(2)  c(1)   c(0)      r(n-2)
  8121.  .                       .
  8122.  .                       .
  8123.  .                       .
  8124.  
  8125. c(n) c(n-1) c(n-2) ...  c(0)
  8126.  
  8127. Function File:  vander (c) 
  8128. Return the Vandermonde matrix whose next to last column is c. 
  8129.  
  8130. A Vandermonde matrix has the form 
  8131.  
  8132. c(0)^n ... c(0)^2  c(0)  1
  8133. c(1)^n ... c(1)^2  c(1)  1
  8134.  .           .      .    .
  8135.  .           .      .    .
  8136.  .           .      .    .
  8137.  
  8138. c(n)^n ... c(n)^2  c(n)  1
  8139.  
  8140.  
  8141. ΓòÉΓòÉΓòÉ 19. Arithmetic ΓòÉΓòÉΓòÉ
  8142.  
  8143. Unless otherwise noted, all of the functions described in this chapter will 
  8144. work for real and complex scalar or matrix arguments. 
  8145.  
  8146.  Utility Functions 
  8147.  Complex Arithmetic 
  8148.  Trigonometry 
  8149.  Sums and Products 
  8150.  Special Functions 
  8151.  Mathematical Constants 
  8152.  
  8153.  
  8154. ΓòÉΓòÉΓòÉ 19.1. Utility Functions ΓòÉΓòÉΓòÉ
  8155.  
  8156. The following functions are available for working with complex numbers. Each 
  8157. expects a single argument.  They are called mapping functions because when 
  8158. given a matrix argument, they apply the given function to each element of the 
  8159. matrix. 
  8160.  
  8161. Mapping Function:  ceil (x) 
  8162. Return the smallest integer not less than x.  If x is complex, return ceil 
  8163. (real (x)) + ceil (imag (x)) * I. 
  8164.  
  8165. Mapping Function:  exp (x) 
  8166. Compute the exponential of x.  To compute the matrix exponential, see Linear 
  8167. Algebra. 
  8168.  
  8169. Mapping Function:  fix (x) 
  8170. Truncate x toward zero.  If x is complex, return fix (real (x)) + fix (imag 
  8171. (x)) * I. 
  8172.  
  8173. Mapping Function:  floor (x) 
  8174. Return the largest integer not greater than x.  If x is complex, return floor 
  8175. (real (x)) + floor (imag (x)) * I. 
  8176.  
  8177. Mapping Function:  gcd (x, ...) 
  8178. Compute the greatest common divisor of the elements of x, or the list of all 
  8179. the arguments.  For example, 
  8180.  
  8181. gcd (a1, ..., ak)
  8182.  
  8183. is the same as 
  8184.  
  8185. gcd ([a1, ..., ak])
  8186.  
  8187. An optional second return value, v contains an integer vector such that 
  8188.  
  8189. g = v(1) * a(k) + ... + v(k) * a(k)
  8190.  
  8191. Mapping Function:  lcm (x, ...) 
  8192. Compute the least common multiple of the elements elements of x, or the list of 
  8193. all the arguments.  For example, 
  8194.  
  8195. lcm (a1, ..., ak)
  8196.  
  8197. is the same as 
  8198.  
  8199. lcm ([a1, ..., ak]).
  8200.  
  8201. Mapping Function:  log (x) 
  8202. Compute the natural logarithm of x.  To compute the matrix logarithm, see 
  8203. Linear Algebra. 
  8204.  
  8205. Mapping Function:  log10 (x) 
  8206. Compute the base-10 logarithm of x. 
  8207.  
  8208. Mapping Function: y = log2 (x) 
  8209.  
  8210. Mapping Function: [f, e] log2 (x) 
  8211. Compute the base-2 logarithm of x.  With two outputs, returns f and e such that 
  8212. 1/2 <= abs(f) < 1 and x = f * 2^e. 
  8213.  
  8214. Loadable Function:  max (x) 
  8215. For a vector argument, return the maximum value.  For a matrix argument, return 
  8216. the maximum value from each column, as a row vector.  Thus, 
  8217.  
  8218. max (max (x))
  8219.  
  8220. returns the largest element of x. 
  8221.  
  8222. For complex arguments, the magnitude of the elements are used for comparison. 
  8223.  
  8224. Loadable Function:  min (x) 
  8225. Like max, but return the minimum value. 
  8226.  
  8227. Function File:  nextpow2 (x) 
  8228. If x is a scalar, returns the first integer n such that  2^n >= abs (x). 
  8229.  
  8230. If x is a vector, return nextpow2 (length (x)). 
  8231.  
  8232. Mapping Function:  pow2 (x) 
  8233.  
  8234. Mapping Function:  pow2 (f, e) 
  8235. With one argument, computes  2 .^ x for each element of x.  With two arguments, 
  8236. returns  f .* (2 .^ e). 
  8237.  
  8238. Mapping Function:  rem (x, y) 
  8239. Return the remainder of x / y, computed using the expression 
  8240.  
  8241. x - y .* fix (x ./ y)
  8242.  
  8243. An error message is printed if the dimensions of the arguments do not agree, or 
  8244. if either of the arguments is complex. 
  8245.  
  8246. Mapping Function:  round (x) 
  8247. Return the integer nearest to x.  If x is complex, return round (real (x)) + 
  8248. round (imag (x)) * I. 
  8249.  
  8250. Mapping Function:  sign (x) 
  8251. Compute the signum function, which is defined as 
  8252.  
  8253.            -1, x < 0;
  8254. sign (x) =  0, x = 0;
  8255.             1, x > 0.
  8256.  
  8257. For complex arguments, sign returns x ./ abs (x). 
  8258.  
  8259. Mapping Function:  sqrt (x) 
  8260. Compute the square root of x.  If x is negative, a complex result is returned. 
  8261. To compute the matrix square root, see Linear Algebra. 
  8262.  
  8263. Mapping Function:  xor (x, y) 
  8264. Return the `exclusive or' of the entries of x and y. For boolean expressions x 
  8265. and y, xor (x, y) is true if and only if x or y is true, but not if both x and 
  8266. y are true. 
  8267.  
  8268.  
  8269. ΓòÉΓòÉΓòÉ 19.2. Complex Arithmetic ΓòÉΓòÉΓòÉ
  8270.  
  8271. The following functions are available for working with complex numbers.  Each 
  8272. expects a single argument.  Given a matrix they work on an element by element 
  8273. basis.  In the descriptions of the following functions, z is the complex number 
  8274. x + iy, where i is defined as sqrt (-1). 
  8275.  
  8276. Mapping Function:  abs (z) 
  8277. Compute the magnitude of z, defined as |z| = sqrt (x^2 + y^2). 
  8278.  
  8279. For example, 
  8280.  
  8281. abs (3 + 4i)
  8282.      => 5
  8283.  
  8284. Mapping Function:  arg (z) 
  8285.  
  8286. Mapping Function:  angle (z) 
  8287. Compute the argument of z, defined as theta = atan (y/x). 
  8288.  
  8289. in radians. 
  8290.  
  8291. For example, 
  8292.  
  8293. arg (3 + 4i)
  8294.      => 0.92730
  8295.  
  8296. Mapping Function:  conj (z) 
  8297. Return the complex conjugate of z, defined as conj (z) = x - iy. 
  8298.  
  8299. Mapping Function:  imag (z) 
  8300. Return the imaginary part of z as a real number. 
  8301.  
  8302. Mapping Function:  real (z) 
  8303. Return the real part of z. 
  8304.  
  8305.  
  8306. ΓòÉΓòÉΓòÉ 19.3. Trigonometry ΓòÉΓòÉΓòÉ
  8307.  
  8308. Octave provides the following trigonometric functions: 
  8309.  
  8310. Mapping Function:  sin (z) 
  8311.  
  8312. Mapping Function:  cos (z) 
  8313.  
  8314. Mapping Function:  tan (z) 
  8315.  
  8316. Mapping Function:  sec (z) 
  8317.  
  8318. Mapping Function:  csc (z) 
  8319.  
  8320. Mapping Function:  cot (z) 
  8321. The ordinary trigonometric functions. 
  8322.  
  8323. Mapping Function:  asin (z) 
  8324.  
  8325. Mapping Function:  acos (z) 
  8326.  
  8327. Mapping Function:  atan (z) 
  8328.  
  8329. Mapping Function:  asec (z) 
  8330.  
  8331. Mapping Function:  acsc (z) 
  8332.  
  8333. Mapping Function:  acot (z) 
  8334. The ordinary inverse trigonometric functions. 
  8335.  
  8336. Mapping Function:  sinh (z) 
  8337.  
  8338. Mapping Function:  cosh (z) 
  8339.  
  8340. Mapping Function:  tanh (z) 
  8341.  
  8342. Mapping Function:  sech (z) 
  8343.  
  8344. Mapping Function:  csch (z) 
  8345.  
  8346. Mapping Function:  coth (z) 
  8347. Hyperbolic trigonometric functions. 
  8348.  
  8349. Mapping Function:  asinh (z) 
  8350.  
  8351. Mapping Function:  acosh (z) 
  8352.  
  8353. Mapping Function:  atanh (z) 
  8354.  
  8355. Mapping Function:  asech (z) 
  8356.  
  8357. Mapping Function:  acsch (z) 
  8358.  
  8359. Mapping Function:  acoth (z) 
  8360. Inverse hyperbolic trigonometric functions. 
  8361.  
  8362. Each of these functions expect a single argument.  For matrix arguments, they 
  8363. work on an element by element basis.  For example, 
  8364.  
  8365. sin ([1, 2; 3, 4])
  8366.      =>  0.84147   0.90930
  8367.          0.14112  -0.75680
  8368.  
  8369. Mapping Function:  atan2 (y, x) 
  8370. Return the arctangent of y/x.  The signs of the arguments are used to determine 
  8371. the quadrant of the result, which is in the range pi to -pi. 
  8372.  
  8373.  
  8374. ΓòÉΓòÉΓòÉ 19.4. Sums and Products ΓòÉΓòÉΓòÉ
  8375.  
  8376. Built-in Function:  sum (x) 
  8377. For a vector argument, return the sum of all the elements.  For a matrix 
  8378. argument, return the sum of the elements in each column, as a row vector.  The 
  8379. sum of an empty matrix is 0 if it has no columns, or a vector of zeros if it 
  8380. has no rows (see Empty Matrices). 
  8381.  
  8382. Built-in Function:  prod (x) 
  8383. For a vector argument, return the product of all the elements.  For a matrix 
  8384. argument, return the product of the elements in each column, as a row vector. 
  8385. The product of an empty matrix is 1 if it has no columns, or a vector of ones 
  8386. if it has no rows (see Empty Matrices). 
  8387.  
  8388. Built-in Function:  cumsum (x) 
  8389. Return the cumulative sum of each column of x.  For example, 
  8390.  
  8391. cumsum ([1, 2; 3, 4])
  8392.      =>  1  2
  8393.          4  6
  8394.  
  8395. Built-in Function:  cumprod (x) 
  8396. Return the cumulative product of each column of x.  For example, 
  8397.  
  8398. cumprod ([1, 2; 3, 4])
  8399.      =>  1  2
  8400.          3  8
  8401.  
  8402. Built-in Function:  sumsq (x) 
  8403. For a vector argument, return the sum of the squares of all the elements.  For 
  8404. a matrix argument, return the sum of the squares of the elements in each 
  8405. column, as a row vector. 
  8406.  
  8407.  
  8408. ΓòÉΓòÉΓòÉ 19.5. Special Functions ΓòÉΓòÉΓòÉ
  8409.  
  8410. Mapping Function:  besseli (alpha, x) 
  8411.  
  8412. Mapping Function:  besselj (alpha, x) 
  8413.  
  8414. Mapping Function:  besselk (alpha, x) 
  8415.  
  8416. Mapping Function:  bessely (alpha, x) 
  8417. Compute Bessel functions of the following types: 
  8418.  
  8419.  besselj 
  8420.            Bessel functions of the first kind. 
  8421.  
  8422.  bessely 
  8423.            Bessel functions of the second kind. 
  8424.  
  8425.  besseli 
  8426.            Modified Bessel functions of the first kind. 
  8427.  
  8428.  besselk 
  8429.            Modified Bessel functions of the second kind. 
  8430.  
  8431.  The second argument, x, must be a real matrix, vector, or scalar. 
  8432.  
  8433.  The first argument, alpha, must be greater than or equal to zero. If alpha is 
  8434.  a range, it must have an increment equal to one. 
  8435.  
  8436.  If alpha is a scalar, the result is the same size as x. 
  8437.  
  8438.  If alpha is a range, x must be a vector or scalar, and the result is a matrix 
  8439.  with length(x) rows and length(alpha) columns. 
  8440.  
  8441.  Mapping Function:  beta (a, b) 
  8442.  Return the Beta function, 
  8443.  
  8444.   beta (a, b) = gamma (a) * gamma (b) / gamma (a + b).
  8445.  
  8446.  Mapping Function:  betai (a, b, x) 
  8447.  Return the incomplete Beta function, 
  8448.  
  8449.                                       x
  8450.                                      /
  8451.   betai (a, b, x) = beta (a, b)^(-1) | t^(a-1) (1-t)^(b-1) dt.
  8452.                                      /
  8453.                                   t=0
  8454.  
  8455.  If x has more than one component, both a and b must be scalars.  If x is a 
  8456.  scalar, a and b must be of compatible dimensions. 
  8457.  
  8458.  Mapping Function:  bincoeff (n, k) 
  8459.  Return the binomial coefficient of n and k, defined as 
  8460.  
  8461.    /   \
  8462.    | n |    n (n-1) (n-2) ... (n-k+1)
  8463.    |   |  = -------------------------
  8464.    | k |               k!
  8465.    \   /
  8466.  
  8467.  For example, 
  8468.  
  8469.   bincoeff (5, 2)
  8470.        => 10
  8471.  
  8472.  Mapping Function:  erf (z) 
  8473.  Computes the error function, 
  8474.  
  8475.                            z
  8476.                           /
  8477.   erf (z) = (2/sqrt (pi)) | e^(-t^2) dt
  8478.                           /
  8479.                        t=0
  8480.  
  8481.  Mapping Function:  erfc (z) 
  8482.  Computes the complementary error function, 1 - erf (z). 
  8483.  
  8484.  Mapping Function:  erfinv (z) 
  8485.  Computes the inverse of the error function, 
  8486.  
  8487.  Mapping Function:  gamma (z) 
  8488.  Computes the Gamma function, 
  8489.  
  8490.               infinity
  8491.               /
  8492.   gamma (z) = | t^(z-1) exp (-t) dt.
  8493.               /
  8494.            t=0
  8495.  
  8496.  Mapping Function:  gammai (a, x) 
  8497.  Computes the incomplete gamma function, 
  8498.  
  8499.                                 x
  8500.                       1        /
  8501.   gammai (a, x) = ---------    | exp (-t) t^(a-1) dt
  8502.                   gamma (a)    /
  8503.                             t=0
  8504.  
  8505.  If a is scalar, then gammai (a, x) is returned for each element of x and vice 
  8506.  versa. 
  8507.  
  8508.  If neither a nor x is scalar, the sizes of a and x must agree, and gammai is 
  8509.  applied element-by-element. 
  8510.  
  8511.  Mapping Function:  lgamma (a, x) 
  8512.  
  8513.  Mapping Function:  gammaln (a, x) 
  8514.  Return the natural logarithm of the gamma function. 
  8515.  
  8516.  Function File:  cross (x, y) 
  8517.  Computes the vector cross product of the two 3-dimensional vectors x and y. 
  8518.  For example, 
  8519.  
  8520.   cross ([1,1,0], [0,1,1])
  8521.        => [ 1; -1; 1 ]
  8522.  
  8523.  Function File:  commutation_matrix (m, n) 
  8524.  Return the commutation matrix  K(m,n)  which is the unique  m*n by m*n  matrix 
  8525.  such that  K(m,n) * vec (A) = vec (A')  for all  m by n  matrices  A. 
  8526.  
  8527.  If only one argument m is given,  K(m,m)  is returned. 
  8528.  
  8529.  See Magnus and Neudecker (1988), Matrix differential calculus with 
  8530.  applications in statistics and econometrics. 
  8531.  
  8532.  Function File:  duplication_matrix (n) 
  8533.  Return the duplication matrix  D_n  which is the unique  n^2 by n*(n+1)/2 
  8534.  matrix such that  D_n \cdot vech (A) = vec (A)  for all symmetric  n by n 
  8535.  matrices  A. 
  8536.  
  8537.  See Magnus and Neudecker (1988), Matrix differential calculus with 
  8538.  applications in statistics and econometrics. 
  8539.  
  8540.  
  8541. ΓòÉΓòÉΓòÉ 19.6. Mathematical Constants ΓòÉΓòÉΓòÉ
  8542.  
  8543. Built-in Variable: I 
  8544.  
  8545. Built-in Variable: J 
  8546.  
  8547. Built-in Variable: i 
  8548.  
  8549. Built-in Variable: j 
  8550. A pure imaginary number, defined as  sqrt (-1). The I and J forms are true 
  8551. constants, and cannot be modified.  The i and j forms are like ordinary 
  8552. variables, and may be used for other purposes.  However, unlike other 
  8553. variables, they once again assume their special predefined values if they are 
  8554. cleared See Status of Variables. 
  8555.  
  8556. Built-in Variable: Inf 
  8557.  
  8558. Built-in Variable: inf 
  8559. Infinity.  This is the result of an operation like 1/0, or an operation that 
  8560. results in a floating point overflow. 
  8561.  
  8562. Built-in Variable: NaN 
  8563.  
  8564. Built-in Variable: nan 
  8565. Not a number.  This is the result of an operation like 0/0, or `Inf - Inf', or 
  8566. any operation with a NaN. 
  8567.  
  8568. Note that NaN always compares not equal to NaN.  This behavior is specified by 
  8569. the IEEE standard for floating point arithmetic.  To find NaN values, you must 
  8570. use the isnan function. 
  8571.  
  8572. Built-in Variable: pi 
  8573. The ratio of the circumference of a circle to its diameter. Internally, pi is 
  8574. computed as `4.0 * atan (1.0)'. 
  8575.  
  8576. Built-in Variable: e 
  8577. The base of natural logarithms.  The constant  e  satisfies the equation  log 
  8578. (e) = 1. 
  8579.  
  8580. Built-in Variable: eps 
  8581. The machine precision.  More precisely, eps is the largest relative spacing 
  8582. between any two adjacent numbers in the machine's floating point system.  This 
  8583. number is obviously system-dependent.  On machines that support 64 bit IEEE 
  8584. floating point arithmetic, eps is approximately  2.2204e-16. 
  8585.  
  8586. Built-in Variable: realmax 
  8587. The largest floating point number that is representable.  The actual value is 
  8588. system-dependent.  On machines that support 64 bit IEEE floating point 
  8589. arithmetic, realmax is approximately  1.7977e+308 
  8590.  
  8591. Built-in Variable: realmin 
  8592. The smallest floating point number that is representable.  The actual value is 
  8593. system-dependent.  On machines that support 64 bit IEEE floating point 
  8594. arithmetic, realmin is approximately  2.2251e-308 
  8595.  
  8596.  
  8597. ΓòÉΓòÉΓòÉ 20. Linear Algebra ΓòÉΓòÉΓòÉ
  8598.  
  8599. This chapter documents the linear algebra functions of Octave. Reference 
  8600. material for many of these functions may be found in Golub and Van Loan, Matrix 
  8601. Computations, 2nd Ed., Johns Hopkins, 1989, and in Lapack Users' Guide, SIAM, 
  8602. 1992. 
  8603.  
  8604.  Basic Matrix Functions 
  8605.  Matrix Factorizations 
  8606.  Functions of a Matrix 
  8607.  
  8608.  
  8609. ΓòÉΓòÉΓòÉ 20.1. Basic Matrix Functions ΓòÉΓòÉΓòÉ
  8610.  
  8611. Loadable Function: aa = balance (a, opt) 
  8612.  
  8613. Loadable Function: [dd, aa] = balance (a, opt) 
  8614.  
  8615. Loadable Function: [cc, dd, aa, bb] = balance (a, b, opt) 
  8616.  
  8617. [dd, aa] = balance (a) returns aa = dd \ a * dd. aa is a matrix whose row and 
  8618. column norms are roughly equal in magnitude, and dd = p * d, where p is a 
  8619. permutation matrix and d is a diagonal matrix of powers of two.  This allows 
  8620. the equilibration to be computed without roundoff.  Results of eigenvalue 
  8621. calculation are typically improved by balancing first. 
  8622.  
  8623. [cc, dd, aa, bb] = balance (a, b) returns aa = cc*a*dd and bb = cc*b*dd), where 
  8624. aa and bb have non-zero elements of approximately the same magnitude and cc and 
  8625. dd are permuted diagonal matrices as in dd for the algebraic eigenvalue 
  8626. problem. 
  8627.  
  8628. The eigenvalue balancing option opt is selected as follows: 
  8629.  
  8630.  "N", "n" 
  8631.            No balancing; arguments copied, transformation(s) set to identity. 
  8632.  
  8633.  "P", "p" 
  8634.            Permute argument(s) to isolate eigenvalues where possible. 
  8635.  
  8636.  "S", "s" 
  8637.            Scale to improve accuracy of computed eigenvalues. 
  8638.  
  8639.  "B", "b" 
  8640.            Permute and scale, in that order. Rows/columns of a (and b) that are 
  8641.            isolated by permutation are not scaled.  This is the default 
  8642.            behavior. 
  8643.  
  8644.  Algebraic eigenvalue balancing uses standard Lapack routines. 
  8645.  
  8646.  Generalized eigenvalue problem balancing uses Ward's algorithm (SIAM Journal 
  8647.  on Scientific and Statistical Computing, 1981). 
  8648.  
  8649.  :  cond (a) 
  8650.  Compute the (two-norm) condition number of a matrix. cond (a) is defined as 
  8651.  norm (a) * norm (inv (a)), and is computed via a singular value decomposition. 
  8652.  
  8653.  Loadable Function:  det (a) 
  8654.  Compute the determinant of a using Linpack. 
  8655.  
  8656.  Loadable Function: lambda = eig (a) 
  8657.  
  8658.  Loadable Function: [v, lambda] = eig (a) 
  8659.  The eigenvalues (and eigenvectors) of a matrix are computed in a several step 
  8660.  process which begins with a Hessenberg decomposition, followed by a Schur 
  8661.  decomposition, from which the eigenvalues are apparent.  The eigenvectors, 
  8662.  when desired, are computed by further manipulations of the Schur 
  8663.  decomposition. 
  8664.  
  8665.  Loadable Function: G = givens (x, y) 
  8666.  
  8667.  Loadable Function: [c, s] = givens (x, y) 
  8668.  Return a 2 by 2 orthogonal matrix G = [c s; -s' c] such that G [x; y] = [*; 0] 
  8669.  with x and y scalars. 
  8670.  
  8671.  For example, 
  8672.  
  8673.   givens (1, 1)
  8674.        =>   0.70711   0.70711
  8675.            -0.70711   0.70711
  8676.  
  8677.  Loadable Function:  inv (a) 
  8678.  
  8679.  Loadable Function:  inverse (a) 
  8680.  Compute the inverse of the square matrix a. 
  8681.  
  8682.  Function File:  norm (a, p) 
  8683.  Compute the p-norm of the matrix a.  If the second argument is missing, p = 2 
  8684.  is assumed. 
  8685.  
  8686.  If a is a matrix: 
  8687.  
  8688.  p = 1 
  8689.            1-norm, the largest column sum of a. 
  8690.  
  8691.  p = 2 
  8692.            Largest singular value of a. 
  8693.  
  8694.  p = Inf 
  8695.            Infinity norm, the largest row sum of a. 
  8696.  
  8697.  p = "fro" 
  8698.            Frobenius norm of a, sqrt (sum (diag (a' * a))). 
  8699.  
  8700.  If a is a vector or a scalar: 
  8701.  
  8702.  p = Inf 
  8703.            max (abs (a)). 
  8704.  
  8705.  p = -Inf 
  8706.            min (abs (a)). 
  8707.  
  8708.  other 
  8709.            p-norm of a, (sum (abs (a) .^ p)) ^ (1/p). 
  8710.  
  8711.  Function File:  null (a, tol) 
  8712.  Return an orthonormal basis of the null space of a. 
  8713.  
  8714.  The dimension of the null space is taken as the number of singular values of a 
  8715.  not greater than tol.  If the argument tol is missing, it is computed as 
  8716.  
  8717.   max (size (a)) * max (svd (a)) * eps
  8718.  
  8719.  Function File:  orth (a, tol) 
  8720.  Return an orthonormal basis of the range space of a. 
  8721.  
  8722.  The dimension of the range space is taken as the number of singular values of 
  8723.  a greater than tol.  If the argument tol is missing, it is computed as 
  8724.  
  8725.   max (size (a)) * max (svd (a)) * eps
  8726.  
  8727.  Function File:  pinv (x, tol) 
  8728.  Return the pseudoinverse of x.  Singular values less than tol are ignored. 
  8729.  
  8730.  If the second argument is omitted, it is assumed that 
  8731.  
  8732.   tol = max (size (x)) * sigma_max (x) * eps,
  8733.  
  8734.  where sigma_max (x) is the maximal singular value of x. 
  8735.  
  8736.  Function File:  rank (a, tol) 
  8737.  Compute the rank of a, using the singular value decomposition. The rank is 
  8738.  taken to be the number  of singular values of a that are greater than the 
  8739.  specified tolerance tol.  If the second argument is omitted, it is taken to be 
  8740.  
  8741.   tol = max (size (a)) * sigma (1) * eps;
  8742.  
  8743.  where eps is machine precision and sigma is the largest singular value of a. 
  8744.  
  8745.  Function File:  trace (a) 
  8746.  Compute the trace of a, sum (diag (a)). 
  8747.  
  8748.  
  8749. ΓòÉΓòÉΓòÉ 20.2. Matrix Factorizations ΓòÉΓòÉΓòÉ
  8750.  
  8751. Loadable Function:  chol (a) 
  8752. Compute the Cholesky factor, r, of the symmetric positive definite matrix a, 
  8753. where 
  8754.  
  8755. r' * r = a.
  8756.  
  8757. Loadable Function: h = hess (a) 
  8758.  
  8759. Loadable Function: [p, h] = hess (a) 
  8760. Compute the Hessenberg decomposition of the matrix a. 
  8761.  
  8762. The Hessenberg decomposition is usually used as the first step in an eigenvalue 
  8763. computation, but has other applications as well (see Golub, Nash, and Van Loan, 
  8764. IEEE Transactions on Automatic Control, 1979.  The Hessenberg decomposition is 
  8765. p * h * p' = a where p is a square unitary matrix (p' * p = I, using 
  8766. complex-conjugate transposition) and h is upper Hessenberg (i >= j+1 => h (i, 
  8767. j) = 0). 
  8768.  
  8769. Loadable Function: [l, u, p] = lu (a) 
  8770. Compute the LU decomposition of a, using subroutines from Lapack.  The result 
  8771. is returned in a permuted form, according to the optional return value p.  For 
  8772. example, given the matrix a = [1, 2; 3, 4], 
  8773.  
  8774. [l, u, p] = lu (a)
  8775.  
  8776. returns 
  8777.  
  8778. l =
  8779.  
  8780.   1.00000  0.00000
  8781.   0.33333  1.00000
  8782.  
  8783. u =
  8784.  
  8785.   3.00000  4.00000
  8786.   0.00000  0.66667
  8787.  
  8788. p =
  8789.  
  8790.   0  1
  8791.   1  0
  8792.  
  8793. Loadable Function: [q, r, p] = qr (a) 
  8794. Compute the QR factorization of a, using standard Lapack subroutines.  For 
  8795. example, given the matrix a = [1, 2; 3, 4], 
  8796.  
  8797. [q, r] = qr (a)
  8798.  
  8799. returns 
  8800.  
  8801. q =
  8802.  
  8803.   -0.31623  -0.94868
  8804.   -0.94868   0.31623
  8805.  
  8806. r =
  8807.  
  8808.   -3.16228  -4.42719
  8809.    0.00000  -0.63246
  8810.  
  8811. The qr factorization has applications in the solution of least squares problems 
  8812.  
  8813. min norm(A x - b)
  8814.  
  8815. for overdetermined systems of equations (i.e., a  is a tall, thin matrix).  The 
  8816. QR factorization is q * r = a where q is an orthogonal matrix and r is upper 
  8817. triangular. 
  8818.  
  8819. The permuted QR factorization [q, r, p] = qr (a) forms the QR factorization 
  8820. such that the diagonal entries of r are decreasing in magnitude order.  For 
  8821. example, given the matrix a = [1, 2; 3, 4], 
  8822.  
  8823. [q, r, pi] = qr(a)
  8824.  
  8825. returns 
  8826.  
  8827. q =
  8828.  
  8829.   -0.44721  -0.89443
  8830.   -0.89443   0.44721
  8831.  
  8832. r =
  8833.  
  8834.   -4.47214  -3.13050
  8835.    0.00000   0.44721
  8836.  
  8837. p =
  8838.  
  8839.    0  1
  8840.    1  0
  8841.  
  8842. The permuted qr factorization [q, r, p] = qr (a) factorization allows the 
  8843. construction of an orthogonal basis of span (a). 
  8844.  
  8845. Function File: lambda = qz (a, b) 
  8846. Generalized eigenvalue problem A x = s B x, QZ decomposition.  Three ways to 
  8847. call: 
  8848.  
  8849.    1. lambda = qz(A,B) 
  8850.  
  8851.       Computes the generalized eigenvalues lambda of (A - sB). 
  8852.  
  8853.    2. [AA, BB, Q, Z {, V, W, lambda}] = qz (A, B) 
  8854.  
  8855.       Computes qz decomposition, generalized eigenvectors, and     generalized 
  8856.       eigenvalues of (A - sB) 
  8857.  
  8858.                     A V = B V diag(lambda)
  8859.                     W' A = diag(lambda) W' B
  8860.                     AA = Q'*A*Z, BB = Q'*B*Z  with Q, Z orthogonal (unitary)= I
  8861.  
  8862.    3. [AA,BB,Z{,lambda}] = qz(A,B,opt) 
  8863.  
  8864.       As in form [2], but allows ordering of generalized eigenpairs     for 
  8865.       (e.g.) solution of discrete time algebraic Riccati equations.     Form 3 
  8866.       is not available for complex matrices and does not compute     the 
  8867.       generalized eigenvectors V, W, nor the orthogonal matrix Q. 
  8868.  
  8869.       opt 
  8870.                       for ordering eigenvalues of the GEP pencil.  The leading 
  8871.                      block        of the revised pencil contains all 
  8872.                      eigenvalues that satisfy: 
  8873.  
  8874.                      "N" 
  8875.                                      = unordered (default) 
  8876.  
  8877.                      "S" 
  8878.                                     = small: leading block has all |lambda| <=1 
  8879.  
  8880.                      "B" 
  8881.                                      = big: leading block has all |lambda >= 1 
  8882.  
  8883.                      "-" 
  8884.                                      = negative real part: leading  block has 
  8885.                                     all eigenvalues          in the open left 
  8886.                                     half-plant 
  8887.  
  8888.                      "+" 
  8889.                                      = nonnegative real part:  leading block 
  8890.                                     has all eigenvalues          in the closed 
  8891.                                     right half-plane 
  8892.  
  8893.  Note: qz performs permutation balancing, but not scaling (see balance). 
  8894.  Order of output arguments was selected for compatibility with MATLAB 
  8895.  
  8896.  See also: balance, dare, eig, schur 
  8897.  
  8898.  Function File: [aa, bb, q, z] = qzhess (a, b) 
  8899.  Compute the Hessenberg-triangular decomposition of the matrix pencil (a, b), 
  8900.  returning aa = q * a * z, bb = q * b * z, with q and z orthogonal.  For 
  8901.  example, 
  8902.  
  8903.   [aa, bb, q, z] = qzhess ([1, 2; 3, 4], [5, 6; 7, 8])
  8904.        => aa = [ -3.02244, -4.41741;  0.92998,  0.69749 ]
  8905.        => bb = [ -8.60233, -9.99730;  0.00000, -0.23250 ]
  8906.        =>  q = [ -0.58124, -0.81373; -0.81373,  0.58124 ]
  8907.        =>  z = [ 1, 0; 0, 1 ]
  8908.  
  8909.  The Hessenberg-triangular decomposition is the first step in Moler and 
  8910.  Stewart's QZ decomposition algorithm. 
  8911.  
  8912.  Algorithm taken from Golub and Van Loan, Matrix Computations, 2nd edition. 
  8913.  
  8914.  Loadable Function:  qzval (a, b) 
  8915.  Compute generalized eigenvalues of the matrix pencil a - lambda b. 
  8916.  
  8917.  The arguments a and b must be real matrices. 
  8918.  
  8919.  Loadable Function: s = schur (a) 
  8920.  
  8921.  Loadable Function: [u, s] = schur (a, opt) 
  8922.  The Schur decomposition is used to compute eigenvalues of a square matrix, and 
  8923.  has applications in the solution of algebraic Riccati equations in control 
  8924.  (see are and dare). schur always returns s = u' * a * u where u  is a unitary 
  8925.  matrix (u'* u is identity) and s is upper triangular.  The eigenvalues of a 
  8926.  (and s) are the diagonal elements of s If the matrix a is real, then the real 
  8927.  Schur decomposition is computed, in which the matrix u is orthogonal and s is 
  8928.  block upper triangular with blocks of size at most 2 x 2 blocks along the 
  8929.  diagonal.  The diagonal elements of s (or the eigenvalues of the 2 x 2 blocks, 
  8930.  when appropriate) are the eigenvalues of a and s. 
  8931.  
  8932.  The eigenvalues are optionally ordered along the diagonal according to the 
  8933.  value of opt.  opt = "a" indicates that all eigenvalues with negative real 
  8934.  parts should be moved to the leading block of s (used in are), opt = "d" 
  8935.  indicates that all eigenvalues with magnitude less than one should be moved to 
  8936.  the leading block of s (used in dare), and opt = "u", the default, indicates 
  8937.  that no ordering of eigenvalues should occur.  The leading k columns of u 
  8938.  always span the a-invariant subspace corresponding to the k leading 
  8939.  eigenvalues of s. 
  8940.  
  8941.  Loadable Function: s = svd (a) 
  8942.  
  8943.  Loadable Function: [u, s, v] = svd (a) 
  8944.  Compute the singular value decomposition of a 
  8945.  
  8946.   a = u * sigma * v'
  8947.  
  8948.  The function svd normally returns the vector of singular values. If asked for 
  8949.  three return values, it computes U, S, and V. For example, 
  8950.  
  8951.   svd (hilb (3))
  8952.  
  8953.  returns 
  8954.  
  8955.   ans =
  8956.  
  8957.     1.4083189
  8958.     0.1223271
  8959.     0.0026873
  8960.  
  8961.  and 
  8962.  
  8963.   [u, s, v] = svd (hilb (3))
  8964.  
  8965.  returns 
  8966.  
  8967.   u =
  8968.  
  8969.     -0.82704   0.54745   0.12766
  8970.     -0.45986  -0.52829  -0.71375
  8971.     -0.32330  -0.64901   0.68867
  8972.  
  8973.   s =
  8974.  
  8975.     1.40832  0.00000  0.00000
  8976.     0.00000  0.12233  0.00000
  8977.     0.00000  0.00000  0.00269
  8978.  
  8979.   v =
  8980.  
  8981.     -0.82704   0.54745   0.12766
  8982.     -0.45986  -0.52829  -0.71375
  8983.     -0.32330  -0.64901   0.68867
  8984.  
  8985.  If given a second argument, svd returns an economy-sized decomposition, 
  8986.  eliminating the unnecessary rows or columns of u or v. 
  8987.  
  8988.  
  8989. ΓòÉΓòÉΓòÉ 20.3. Functions of a Matrix ΓòÉΓòÉΓòÉ
  8990.  
  8991. Loadable Function:  expm (a) 
  8992. Return the exponential of a matrix, defined as the infinite Taylor series 
  8993.  
  8994. expm(a) = I + a + a^2/2! + a^3/3! + ...
  8995.  
  8996. The Taylor series is not the way to compute the matrix exponential; see Moler 
  8997. and Van Loan, Nineteen Dubious Ways to Compute the Exponential of a Matrix, 
  8998. SIAM Review, 1978.  This routine uses Ward's diagonal Pade' approximation 
  8999. method with three step preconditioning (SIAM Journal on Numerical Analysis, 
  9000. 1977).  Diagonal Pade'  approximations are rational polynomials of matrices 
  9001.  
  9002.      -1
  9003. D (a)   N (a)
  9004.  
  9005.  whose Taylor series matches the first 2q+1 terms of the Taylor series above; 
  9006. direct evaluation of the Taylor series (with the same preconditioning steps) 
  9007. may be desirable in lieu of the Pade' approximation when Dq(a) is 
  9008. ill-conditioned. 
  9009.  
  9010. Loadable Function:  logm (a) 
  9011. Compute the matrix logarithm of the square matrix a.  Note that this is 
  9012. currently implemented in terms of an eigenvalue expansion and needs to be 
  9013. improved to be more robust. 
  9014.  
  9015. Loadable Function:  sqrtm (a) 
  9016. Compute the matrix square root of the square matrix a.  Note that this is 
  9017. currently implemented in terms of an eigenvalue expansion and needs to be 
  9018. improved to be more robust. 
  9019.  
  9020. Function File:  kron (a, b) 
  9021. Form the kronecker product of two matrices, defined block by block as 
  9022.  
  9023. x = [a(i, j) b]
  9024.  
  9025. For example, 
  9026.  
  9027. kron (1:4, ones (3, 1))
  9028.      =>  1  2  3  4
  9029.          1  2  3  4
  9030.          1  2  3  4
  9031.  
  9032. Loadable Function: x = syl (a, b, c) 
  9033. Solve the Sylvester equation 
  9034.  
  9035. A X + X B + C = 0
  9036.  
  9037. using standard Lapack subroutines.  For example, 
  9038.  
  9039. syl ([1, 2; 3, 4], [5, 6; 7, 8], [9, 10; 11, 12])
  9040.      => [ -0.50000, -0.66667; -0.66667, -0.50000 ]
  9041.  
  9042.  
  9043. ΓòÉΓòÉΓòÉ 21. Nonlinear Equations ΓòÉΓòÉΓòÉ
  9044.  
  9045. Octave can solve sets of nonlinear equations of the form 
  9046.  
  9047. F (x) = 0
  9048.  
  9049. using the function fsolve, which is based on the Minpack subroutine hybrd. 
  9050.  
  9051. Loadable Function: [x, info] = fsolve (fcn, x0) 
  9052. Given fcn, the name of a function of the form f (x) and an initial starting 
  9053. point x0, fsolve solves the set of equations such that f(x) == 0. 
  9054.  
  9055. Loadable Function:  fsolve_options (opt, val) 
  9056. When called with two arguments, this function allows you set options parameters 
  9057. for the function fsolve.  Given one argument, fsolve_options returns the value 
  9058. of the corresponding option.  If no arguments are supplied, the names of all 
  9059. the available options and their current values are displayed. 
  9060.  
  9061. Here is a complete example.  To solve the set of equations 
  9062.  
  9063. -2x^2 + 3xy   + 4 sin(y) = 6
  9064.  3x^2 - 2xy^2 + 3 cos(x) = -4
  9065.  
  9066. you first need to write a function to compute the value of the given function. 
  9067. For example: 
  9068.  
  9069. function y = f (x)
  9070.   y(1) = -2*x(1)^2 + 3*x(1)*x(2)   + 4*sin(x(2)) - 6;
  9071.   y(2) =  3*x(1)^2 - 2*x(1)*x(2)^2 + 3*cos(x(1)) + 4;
  9072. endfunction
  9073.  
  9074. Then, call fsolve with a specified initial condition to find the roots of the 
  9075. system of equations.  For example, given the function f defined above, 
  9076.  
  9077. [x, info] = fsolve ("f", [1; 2])
  9078.  
  9079. results in the solution 
  9080.  
  9081. x =
  9082.  
  9083.   0.57983
  9084.   2.54621
  9085.  
  9086. info = 1
  9087.  
  9088. A value of info = 1 indicates that the solution has converged. 
  9089.  
  9090. The function perror may be used to print English messages corresponding to the 
  9091. numeric error codes.  For example, 
  9092.  
  9093. perror ("fsolve", 1)
  9094.      -| solution converged to requested tolerance
  9095.  
  9096.  
  9097. ΓòÉΓòÉΓòÉ 22. Quadrature ΓòÉΓòÉΓòÉ
  9098.  
  9099.  Functions of One Variable 
  9100.  Orthogonal Collocation 
  9101.  
  9102.  
  9103. ΓòÉΓòÉΓòÉ 22.1. Functions of One Variable ΓòÉΓòÉΓòÉ
  9104.  
  9105. Loadable Function: [v, ier, nfun, err] = quad (f, a, b, tol, sing) 
  9106. Integrate a nonlinear function of one variable using Quadpack. The first 
  9107. argument is the name of the  function to call to compute the value of the 
  9108. integrand.  It must have the form 
  9109.  
  9110. y = f (x)
  9111.  
  9112. where y and x are scalars. 
  9113.  
  9114. The second and third arguments are limits of integration.  Either or both may 
  9115. be infinite. 
  9116.  
  9117. The optional argument tol is a vector that specifies the desired accuracy of 
  9118. the result.  The first element of the vector is the desired absolute tolerance, 
  9119. and the second element is the desired relative tolerance.  To choose a relative 
  9120. test only, set the absolute tolerance to zero.  To choose an absolute test 
  9121. only, set the relative tolerance to zero. 
  9122.  
  9123. The optional argument sing is a vector of values at which the integrand is 
  9124. known to be singular. 
  9125.  
  9126. The result of the integration is returned in v and ier contains an integer 
  9127. error code (0 indicates a successful integration). The value of nfun indicates 
  9128. how many function evaluations were required, and err contains an estimate of 
  9129. the error in the solution. 
  9130.  
  9131. Loadable Function:  quad_options (opt, val) 
  9132. When called with two arguments, this function allows you set options parameters 
  9133. for the function quad.  Given one argument, quad_options returns the value of 
  9134. the corresponding option.  If no arguments are supplied, the names of all the 
  9135. available options and their current values are displayed. 
  9136.  
  9137. Here is an example of using quad to integrate the function 
  9138.  
  9139.   f(x) = x * sin (1/x) * sqrt (abs (1 - x))
  9140.  
  9141. from x = 0 to x = 3. 
  9142.  
  9143. This is a fairly difficult integration (plot the function over the range of 
  9144. integration to see why). 
  9145.  
  9146. The first step is to define the function: 
  9147.  
  9148. function y = f (x)
  9149.   y = x .* sin (1 ./ x) .* sqrt (abs (1 - x));
  9150. endfunction
  9151.  
  9152. Note the use of the `dot' forms of the operators.  This is not necessary for 
  9153. the call to quad, but it makes it much easier to generate a set of points for 
  9154. plotting (because it makes it possible to call the function with a vector 
  9155. argument to produce a vector result). 
  9156.  
  9157. Then we simply call quad: 
  9158.  
  9159. [v, ier, nfun, err] = quad ("f", 0, 3)
  9160.      => 1.9819
  9161.      => 1
  9162.      => 5061
  9163.      => 1.1522e-07
  9164.  
  9165. Although quad returns a nonzero value for ier, the result is reasonably 
  9166. accurate (to see why, examine what happens to the result if you move the lower 
  9167. bound to 0.1, then 0.01, then 0.001, etc.). 
  9168.  
  9169.  
  9170. ΓòÉΓòÉΓòÉ 22.2. Orthogonal Collocation ΓòÉΓòÉΓòÉ
  9171.  
  9172. Loadable Function: [r, A, B, q] = colloc (n, "left", "right") 
  9173. Compute derivative and integral weight matrices for orthogonal collocation 
  9174. using the subroutines given in J. Villadsen and M. L. Michelsen, Solution of 
  9175. Differential Equation Models by Polynomial Approximation. 
  9176.  
  9177. Here is an example of using colloc to generate weight matrices for solving the 
  9178. second order differential equation u' - alpha * u'' = 0 with the boundary 
  9179. conditions u(0) = 0 and u(1) = 1. 
  9180.  
  9181. First, we can generate the weight matrices for n points (including the 
  9182. endpoints of the interval), and incorporate the boundary conditions in the 
  9183. right hand side (for a specific value of alpha). 
  9184.  
  9185. n = 7;
  9186. alpha = 0.1;
  9187. [r, a, b] = colloc (n-2, "left", "right");
  9188. at = a(2:n-1,2:n-1);
  9189. bt = b(2:n-1,2:n-1);
  9190. rhs = alpha * b(2:n-1,n) - a(2:n-1,n);
  9191.  
  9192. Then the solution at the roots r is 
  9193.  
  9194. u = [ 0; (at - alpha * bt) \ rhs; 1]
  9195.      => [ 0.00; 0.004; 0.01 0.00; 0.12; 0.62; 1.00 ]
  9196.  
  9197.  
  9198. ΓòÉΓòÉΓòÉ 23. Differential Equations ΓòÉΓòÉΓòÉ
  9199.  
  9200. Octave has two built-in functions for solving differential equations. Both are 
  9201. based on reliable ODE solvers written in Fortran. 
  9202.  
  9203.  Ordinary Differential Equations 
  9204.  Differential-Algebraic Equations 
  9205.  
  9206.  
  9207. ΓòÉΓòÉΓòÉ 23.1. Ordinary Differential Equations ΓòÉΓòÉΓòÉ
  9208.  
  9209. The function lsode can be used Solve ODEs of the form 
  9210.  
  9211. dx
  9212. -- = f (x, t)
  9213. dt
  9214.  
  9215. using Hindmarsh's ODE solver Lsode. 
  9216.  
  9217. Loadable Function:  lsode (fcn, x0, t, t_crit) 
  9218. Return a matrix of x as a function of t, given the initial state of the system 
  9219. x0.  Each row in the result matrix corresponds to one of the elements in the 
  9220. vector t.  The first element of t corresponds to the initial state x0, so that 
  9221. the first row of the output is x0. 
  9222.  
  9223. The first argument, fcn, is a string that names the function to call to compute 
  9224. the vector of right hand sides for the set of equations. It must have the form 
  9225.  
  9226. xdot = f (x, t)
  9227.  
  9228. where xdot and x are vectors and t is a scalar. 
  9229.  
  9230. The fourth argument is optional, and may be used to specify a set of times that 
  9231. the ODE solver should not integrate past.  It is useful for avoiding 
  9232. difficulties with singularities and points where there is a discontinuity in 
  9233. the derivative. 
  9234.  
  9235. Here is an example of solving a set of three differential equations using 
  9236. lsode.  Given the function 
  9237.  
  9238. function xdot = f (x, t)
  9239.  
  9240.   xdot = zeros (3,1);
  9241.  
  9242.   xdot(1) = 77.27 * (x(2) - x(1)*x(2) + x(1) \
  9243.             - 8.375e-06*x(1)^2);
  9244.   xdot(2) = (x(3) - x(1)*x(2) - x(2)) / 77.27;
  9245.   xdot(3) = 0.161*(x(1) - x(3));
  9246.  
  9247. endfunction
  9248.  
  9249. and the initial condition x0 = [ 4; 1.1; 4 ], the set of equations can be 
  9250. integrated using the command 
  9251.  
  9252. t = linspace (0, 500, 1000);
  9253.  
  9254. y = lsode ("f", x0, t);
  9255.  
  9256. If you try this, you will see that the value of the result changes dramatically 
  9257. between t = 0 and 5, and again around t = 305. A more efficient set of output 
  9258. points might be 
  9259.  
  9260. t = [0, logspace (-1, log10(303), 150), \
  9261.         logspace (log10(304), log10(500), 150)];
  9262.  
  9263. Loadable Function:  lsode_options (opt, val) 
  9264. When called with two arguments, this function allows you set options parameters 
  9265. for the function lsode.  Given one argument, lsode_options returns the value of 
  9266. the corresponding option.  If no arguments are supplied, the names of all the 
  9267. available options and their current values are displayed. 
  9268.  
  9269. See Alan C. Hindmarsh, ODEPACK, A Systematized Collection of ODE Solvers, in 
  9270. Scientific Computing, R. S. Stepleman, editor, (1983) for more information 
  9271. about the inner workings of lsode. 
  9272.  
  9273.  
  9274. ΓòÉΓòÉΓòÉ 23.2. Differential-Algebraic Equations ΓòÉΓòÉΓòÉ
  9275.  
  9276. The function dassl can be used Solve DAEs of the form 
  9277.  
  9278. 0 = f (x-dot, x, t),    x(t=0) = x_0, x-dot(t=0) = x-dot_0
  9279.  
  9280. using Petzold's DAE solver Dassl. 
  9281.  
  9282. Loadable Function: [x, xdot] = dassl (fcn, x0, xdot0, t, t_crit) 
  9283. Return a matrix of states and their first derivatives with respect to t.  Each 
  9284. row in the result matrices correspond to one of the elements in the vector t. 
  9285. The first element of t corresponds to the initial state x0 and derivative 
  9286. xdot0, so that the first row of the output x is x0 and the first row of the 
  9287. output xdot is xdot0. 
  9288.  
  9289. The first argument, fcn, is a string that names the function to call to compute 
  9290. the vector of residuals for the set of equations. It must have the form 
  9291.  
  9292. res = f (x, xdot, t)
  9293.  
  9294. where x, xdot, and res are vectors, and t is a scalar. 
  9295.  
  9296. The second and third arguments to dassl specify the initial condition of the 
  9297. states and their derivatives, and the fourth argument specifies a vector of 
  9298. output times at which the solution is desired, including the time corresponding 
  9299. to the initial condition. 
  9300.  
  9301. The set of initial states and derivatives are not strictly required to be 
  9302. consistent.  In practice, however, Dassl is not very good at determining a 
  9303. consistent set for you, so it is best if you ensure that the initial values 
  9304. result in the function evaluating to zero. 
  9305.  
  9306. The fifth argument is optional, and may be used to specify a set of times that 
  9307. the DAE solver should not integrate past.  It is useful for avoiding 
  9308. difficulties with singularities and points where there is a discontinuity in 
  9309. the derivative. 
  9310.  
  9311. Loadable Function:  dassl_options (opt, val) 
  9312. When called with two arguments, this function allows you set options parameters 
  9313. for the function lsode.  Given one argument, dassl_options returns the value of 
  9314. the corresponding option.  If no arguments are supplied, the names of all the 
  9315. available options and their current values are displayed. 
  9316.  
  9317. See K. E. Brenan, et al., Numerical Solution of Initial-Value Problems in 
  9318. Differential-Algebraic Equations, North-Holland (1989) for more information 
  9319. about the implementation of Dassl. 
  9320.  
  9321.  
  9322. ΓòÉΓòÉΓòÉ 24. Optimization ΓòÉΓòÉΓòÉ
  9323.  
  9324.  Quadratic Programming 
  9325.  Nonlinear Programming 
  9326.  Linear Least Squares 
  9327.  
  9328.  
  9329. ΓòÉΓòÉΓòÉ 24.1. Quadratic Programming ΓòÉΓòÉΓòÉ
  9330.  
  9331.  
  9332. ΓòÉΓòÉΓòÉ 24.2. Nonlinear Programming ΓòÉΓòÉΓòÉ
  9333.  
  9334.  
  9335. ΓòÉΓòÉΓòÉ 24.3. Linear Least Squares ΓòÉΓòÉΓòÉ
  9336.  
  9337. Function File: [beta, v, r] = gls (y, x, o) 
  9338. Generalized least squares estimation for the multivariate model y = x * b + e 
  9339. with mean (e) = 0 and cov (vec (e)) = (s^2)*o,  where Y is a T by p matrix, X 
  9340. is a T by k matrix, B is a k by p matrix, E is a T by p matrix, and O is a Tp 
  9341. by Tp matrix. 
  9342.  
  9343. Each row of Y and X is an observation and each column a variable. 
  9344.  
  9345. The return values beta, v, and r are defined as follows. 
  9346.  
  9347.  beta 
  9348.            The GLS estimator for b. 
  9349.  
  9350.  v 
  9351.            The GLS estimator for s^2. 
  9352.  
  9353.  r 
  9354.            The matrix of GLS residuals, r = y - x * beta. 
  9355.  
  9356.  Function File: [beta, sigma, r] = ols (y, x) 
  9357.  Ordinary least squares estimation for the multivariate model y = x*b + e with 
  9358.  mean (e) = 0 and cov (vec (e)) = kron (s, I).  where y is a t by p matrix, X 
  9359.  is a t by k matrix, B is a k by p matrix, and e is a t by p matrix. 
  9360.  
  9361.  Each row of y and x is an observation and each column a variable. 
  9362.  
  9363.  The return values beta, sigma, and r are defined as follows. 
  9364.  
  9365.  beta 
  9366.            The OLS estimator for b, beta = pinv (x) * y, where pinv (x) denotes 
  9367.            the pseudoinverse of x. 
  9368.  
  9369.  sigma 
  9370.            The OLS estimator for the matrix s, 
  9371.  
  9372.                       sigma = (y-x*beta)' * (y-x*beta) / (t-rank(x))
  9373.  
  9374.  r 
  9375.            The matrix of OLS residuals, r = y - x * beta. 
  9376.  
  9377.  
  9378. ΓòÉΓòÉΓòÉ 25. Statistics ΓòÉΓòÉΓòÉ
  9379.  
  9380. I hope that someday Octave will include more statistics functions.  If you 
  9381. would like to help improve Octave in this area, please contact 
  9382. bug-octave@bevo.che.wisc.edu. 
  9383.  
  9384. Function File:  mean (x) 
  9385. If x is a vector, compute the mean of the elements of x 
  9386.  
  9387. mean (x) = SUM_i x(i) / N
  9388.  
  9389. If x is a matrix, compute the mean for each column and return them in a row 
  9390. vector. 
  9391.  
  9392. Function File:  median (x) 
  9393. If x is a vector, compute the median value of the elements of x. 
  9394.  
  9395.             x(ceil(N/2)),             N odd
  9396. median(x) =
  9397.             (x(N/2) + x((N/2)+1))/2,  N even
  9398.  
  9399. If x is a matrix, compute the median value for each column and return them in a 
  9400. row vector. 
  9401.  
  9402. Function File:  std (x) 
  9403. If x is a vector, compute the standard deviation of the elements of x. 
  9404.  
  9405. std (x) = sqrt (sumsq (x - mean (x)) / (n - 1))
  9406.  
  9407. If x is a matrix, compute the standard deviation for each column and return 
  9408. them in a row vector. 
  9409.  
  9410. Function File:  cov (x, y) 
  9411. If each row of x and y is an observation and each column is a variable, the 
  9412. (i,j)-th entry of cov (x, y) is the covariance between the i-th variable in x 
  9413. and the j-th variable in y.  If called with one argument, compute cov (x, x). 
  9414.  
  9415. Function File:  corrcoef (x, y) 
  9416. If each row of x and y is an observation and each column is a variable, the 
  9417. (i,j)-th entry of corrcoef (x, y) is the correlation between the i-th variable 
  9418. in x and the j-th variable in y. If called with one argument, compute corrcoef 
  9419. (x, x). 
  9420.  
  9421. Function File:  kurtosis (x) 
  9422. If x is a vector of length N, return the kurtosis 
  9423.  
  9424. kurtosis (x) = N^(-1) std(x)^(-4) sum ((x - mean(x)).^4) - 3
  9425.  
  9426. of x.  If x is a matrix, return the row vector containing the kurtosis of each 
  9427. column. 
  9428.  
  9429. Function File:  mahalanobis (x, y) 
  9430. Return the Mahalanobis' D-square distance between the multivariate samples x 
  9431. and y, which must have the same number of components (columns), but may have a 
  9432. different number of observations (rows). 
  9433.  
  9434. Function File:  skewness (x) 
  9435. If x is a vector of length N, return the skewness 
  9436.  
  9437. skewness (x) = N^(-1) std(x)^(-3) sum ((x - mean(x)).^3)
  9438.  
  9439. of x.  If x is a matrix, return the row vector containing the skewness of each 
  9440. column. 
  9441.  
  9442.  
  9443. ΓòÉΓòÉΓòÉ 26. Sets ΓòÉΓòÉΓòÉ
  9444.  
  9445. Octave has a limited set of functions for managing sets of data, where a set is 
  9446. defined as a collection unique elements. 
  9447.  
  9448. Function File:  create_set (x) 
  9449. Return a row vector containing the unique values in x, sorted in ascending 
  9450. order.  For example, 
  9451.  
  9452. create_set ([ 1, 2; 3, 4; 4, 2 ])
  9453.      => [ 1, 2, 3, 4 ]
  9454.  
  9455. Function File:  union (x, y) 
  9456. Return the set of elements that are in either of the sets x and y.  For 
  9457. example, 
  9458.  
  9459. union ([ 1, 2, 4 ], [ 2, 3, 5 ])
  9460.      => [ 1, 2, 3, 4, 5 ]
  9461.  
  9462. Function File:  intersection (x, y) 
  9463. Return the set of elements that are in both sets x and y. For example, 
  9464.  
  9465. intersection ([ 1, 2, 3 ], [ 2, 3, 5 ])
  9466.      => [ 2, 3 ]
  9467.  
  9468. Function File:  complement (x, y) 
  9469. Return the elements of set y that are not in set x.  For example, 
  9470.  
  9471. complement ([ 1, 2, 3 ], [ 2, 3, 5 ])
  9472.      => 5
  9473.  
  9474.  
  9475. ΓòÉΓòÉΓòÉ 27. Polynomial Manipulations ΓòÉΓòÉΓòÉ
  9476.  
  9477. In Octave, a polynomial is represented by its coefficients (arranged in 
  9478. descending order).  For example, a vector  c of length  N+1  corresponds to the 
  9479. following polynomial of order  N 
  9480.  
  9481. p(x) = c(1) x^N + ... + c(N) x + c(N+1).
  9482.  
  9483. Function File:  compan (c) 
  9484. Compute the companion matrix corresponding to polynomial coefficient vector c. 
  9485.  
  9486. The companion matrix is 
  9487.  
  9488.      _                                                        _
  9489.     |  -c(2)/c(1)   -c(3)/c(1)  ...  -c(N)/c(1)  -c(N+1)/c(1)  |
  9490.     |       1            0      ...       0             0      |
  9491.     |       0            1      ...       0             0      |
  9492. A = |       .            .   .            .             .      |
  9493.     |       .            .       .        .             .      |
  9494.     |       .            .           .    .             .      |
  9495.     |_      0            0      ...       1             0     _|
  9496.  
  9497. The eigenvalues of the companion matrix are equal to the roots of the 
  9498. polynomial. 
  9499.  
  9500. Function File:  conv (a, b) 
  9501. Convolve two vectors. 
  9502.  
  9503. y = conv (a, b) returns a vector of length equal to length (a) + length (b) - 
  9504. 1. If a and b are polynomial coefficient vectors, conv returns the coefficients 
  9505. of the product polynomial. 
  9506.  
  9507. Function File:  deconv (y, a) 
  9508. Deconvolve two vectors. 
  9509.  
  9510. [b, r] = deconv (y, a) solves for b and r such that y = conv (a, b) + r. 
  9511.  
  9512. If y and a are polynomial coefficient vectors, b will contain the coefficients 
  9513. of the polynomial quotient and r will be a remander polynomial of lowest order. 
  9514.  
  9515. Function File:  poly (a) 
  9516. If a is a square N-by-N matrix, poly (a) is the row vector of the coefficients 
  9517. of det (z * eye (N) - a), the characteristic polynomial of a.  If x is a 
  9518. vector, poly (x) is a vector of coefficients of the polynomial whose roots are 
  9519. the elements of x. 
  9520.  
  9521. Function File:  polyderiv (c) 
  9522. Return the coefficients of the derivative of the polynomial whose coefficients 
  9523. are given by vector c. 
  9524.  
  9525. Function File: [p, yf] = polyfit (x, y, n) 
  9526. Return the coefficients of a polynomial p(x) of degree n that minimizes sumsq 
  9527. (p(x(i)) - y(i)),  to best fit the data in the least squares sense. 
  9528.  
  9529. If two output arguments are requested, the second contains the values of the 
  9530. polynomial for each value of x. 
  9531.  
  9532. Function File:  polyinteg (c) 
  9533. Return the coefficients of the integral of the polynomial whose coefficients 
  9534. are represented by the vector c. 
  9535.  
  9536. The constant of integration is set to zero. 
  9537.  
  9538. Function File:  polyreduce (c) 
  9539. Reduces a polynomial coefficient vector to a minimum number of terms by 
  9540. stripping off any leading zeros. 
  9541.  
  9542. Function File:  polyval (c, x) 
  9543. Evaluate a polynomial. 
  9544.  
  9545. polyval (c, x) will evaluate the polynomial at the specified value of x. 
  9546.  
  9547. If x is a vector or matrix, the polynomial is evaluated at each of the elements 
  9548. of x. 
  9549.  
  9550. Function File:  polyvalm (c, x) 
  9551. Evaluate a polynomial in the matrix sense. 
  9552.  
  9553. polyvalm (c, x) will evaluate the polynomial in the matrix sense, i.e. matrix 
  9554. multiplication is used instead of element by element multiplication as is used 
  9555. in polyval. 
  9556.  
  9557. The argument x must be a square matrix. 
  9558.  
  9559. Function File:  residue (b, a, tol) 
  9560. If b and a are vectors of polynomial coefficients, then residue calculates the 
  9561. partial fraction expansion corresponding to the ratio of the two polynomials. 
  9562.  
  9563. The function residue returns r, p, k, and e, where the vector r contains the 
  9564. residue terms, p contains the pole values, k contains the coefficients of a 
  9565. direct polynomial term (if it exists) and e is a vector containing the powers 
  9566. of the denominators in the partial fraction terms. 
  9567.  
  9568. Assuming b and a represent polynomials  P (s) and Q(s)  we have: 
  9569.  
  9570.  P(s)    M       r(m)         N
  9571.  ---- = SUM -------------  + SUM k(i)*s^(N-i)
  9572.  Q(s)   m=1 (s-p(m))^e(m)    i=1
  9573.  
  9574. where M is the number of poles (the length of the r, p, and e vectors) and N is 
  9575. the length of the k vector. 
  9576.  
  9577. The argument tol is optional, and if not specified, a default value of 0.001 is 
  9578. assumed.  The tolerance value is used to determine whether poles with small 
  9579. imaginary components are declared real.  It is also used to determine if two 
  9580. poles are distinct.  If the ratio of the imaginary part of a pole to the real 
  9581. part is less than tol, the imaginary part is discarded.  If two poles are 
  9582. farther apart than tol they are distinct.  For example, 
  9583.  
  9584.  b = [1, 1, 1];
  9585.  a = [1, -5, 8, -4];
  9586.  [r, p, k, e] = residue (b, a);
  9587.      => r = [-2, 7, 3]
  9588.      => p = [2, 2, 1]
  9589.      => k = [](0x0)
  9590.      => e = [1, 2, 1]
  9591.  
  9592. which implies the following partial fraction expansion 
  9593.  
  9594.         s^2 + s + 1       -2        7        3
  9595.    ------------------- = ----- + ------- + -----
  9596.    s^3 - 5s^2 + 8s - 4   (s-2)   (s-2)^2   (s-1)
  9597.  
  9598. Function File:  roots (v) 
  9599.  
  9600. For a vector v with N components, return the roots of the polynomial 
  9601.  
  9602. v(1) * z^(N-1) + ... + v(N-1) * z + v(N).
  9603.  
  9604.  
  9605. ΓòÉΓòÉΓòÉ 28. Control Theory ΓòÉΓòÉΓòÉ
  9606.  
  9607. The Octave Control Systems Toolbox (OCST) was initially developed by Dr. A. 
  9608. Scottedward Hodel a.s.hodel@eng.auburn.edu with the assistance of his students 
  9609.  
  9610.      R. Bruce Tenison btenison@dibbs.net, 
  9611.  
  9612.      David C. Clem, 
  9613.  
  9614.      John E. Ingram John.Ingram@sea.siemans.com, and 
  9615.  
  9616.      Kristi McGowan. 
  9617.  
  9618.  This development was supported in part by NASA's Marshall Space Flight Center 
  9619.  as part of an in-house CACSD environment.  Additional important contributions 
  9620.  were made by Dr. Kai Mueller mueller@ifr.ing.tu-bs.de and Jose Daniel Munoz 
  9621.  Frias (place.m). 
  9622.  
  9623.  An on-line menu-driven tutorial is available via DEMOcontrol; beginning OCST 
  9624.  users should start with this program. 
  9625.  
  9626.  * OCST demonstration/tutorial:DEMOcontrol. * System Data Structure:sysstruct. 
  9627.  * System Construction and Interface Functions:sysinterface. * System display 
  9628.  functions:sysdisp. * Block Diagram Manipulations:blockdiag. * Numerical 
  9629.  Functions:numerical. * System Analysis-Properties:sysprop. * System 
  9630.  Analysis-Time Domain:systime. * System Analysis-Frequency Domain:sysfreq. * 
  9631.  Controller Design:cacsd. * Miscellaneous Functions:misc. 
  9632.  
  9633.  
  9634. ΓòÉΓòÉΓòÉ 28.1. OCST demo program ΓòÉΓòÉΓòÉ
  9635.  
  9636. Function File :  DEMOcontrol 
  9637. Octave Control Systems Toolbox demo/tutorial program.  The demo allows the user 
  9638. to select among several categories of OCST function: 
  9639.  
  9640. octave:1> DEMOcontrol
  9641.  O C T A V E    C O N T R O L   S Y S T E M S   T O O L B O X
  9642. Octave Controls System Toolbox Demo
  9643.  
  9644.   [ 1] System representation
  9645.   [ 2] Block diagram manipulations
  9646.   [ 3] Frequency response functions
  9647.   [ 4] State space analysis functions
  9648.   [ 5] Root locus functions
  9649.   [ 6] LQG/H2/Hinfinity functions
  9650.   [ 7] End
  9651.  
  9652. Command examples are interactively run for users to observe the use of OCST 
  9653. functions. 
  9654.  
  9655.  
  9656. ΓòÉΓòÉΓòÉ 28.2. System Data Structure ΓòÉΓòÉΓòÉ
  9657.  
  9658. * Demo program:sysrepdemo. * Variables common to all OCST system 
  9659. formats:sysstructvars. * tf format variables:sysstructtf. * zp format 
  9660. variables:sysstructzp. * ss format variables:sysstructss. The OCST stores all 
  9661. dynamic systems in a single data structure format that can represent continuous 
  9662. systems, discrete-systems, and mixed (hybrid) systems in state-space form, and 
  9663. can also represent purely continuous/discrete systems in either transfer 
  9664. function or pole-zero form. In order to provide more flexibility in treatment 
  9665. of discrete/hybrid systems, the OCST also keeps a record of which system 
  9666. outputs are sampled. 
  9667.  
  9668. Octave structures are accessed with a syntax much like that used by the C 
  9669. programming language.  For consistency in use of the data structure used in the 
  9670. OCST, it is recommended that the system structure access m-files be used (See 
  9671. sysinterface). Some elements of the data structure are absent depending on the 
  9672. internal system representation(s) used.  More than one system representation 
  9673. can be used for SISO systems; the OCST m-files ensure that all representations 
  9674. used are consistent with one another. 
  9675.  
  9676.  
  9677. ΓòÉΓòÉΓòÉ 28.3. System representation demo program ΓòÉΓòÉΓòÉ
  9678.  
  9679. Function File :  sysrepdemo 
  9680. Tutorial for the use of the system data structure functions. 
  9681.  
  9682.  
  9683. ΓòÉΓòÉΓòÉ 28.3.1. Variables common to all OCST system formats ΓòÉΓòÉΓòÉ
  9684.  
  9685. The data structure elements (and variable types) common to all  system 
  9686. representations are listed below; examples of the initialization and use of the 
  9687. system data structures are given in subsequent sections and in the online demo 
  9688. DEMOcontrol. 
  9689.  
  9690.  n,nz 
  9691.            The respective number of continuous and discrete states in the 
  9692.            system (scalar) 
  9693.  
  9694.  inname, outname 
  9695.            list of name(s) of the system input, output signal(s). (list of 
  9696.            strings) 
  9697.  
  9698.  sys 
  9699.             System status vector.  (vector) 
  9700.  
  9701.            This vector indicates both what    representation was used to 
  9702.            initialize the  system data structure    (called the primary system 
  9703.            type) and which other representations    are currently up-to-date 
  9704.            with the primary system type (See sysupdate). 
  9705.  
  9706.            sys(0) 
  9707.                           primary system type 
  9708.  
  9709.                                 =0 for tf form (initialized with tf2sys or 
  9710.                           fir2sys) 
  9711.  
  9712.                                 =1 for zp form (initialized with zp2sys) 
  9713.  
  9714.                                 =2 for ss form (initialized with ss2sys) 
  9715.  
  9716.            sys(1:3) 
  9717.                            boolean flags to indicate whether tf, zp, or ss, 
  9718.                           respectively,     are ``up to date" (whether it is 
  9719.                           safe to use the variables      associated with these 
  9720.                           representations). These flags are changed when calls 
  9721.                           are made to the sysupdate command. 
  9722.  
  9723.  tsam 
  9724.             Discrete time sampling period  (nonnegative scalar).  tsam is set 
  9725.            to 0 for continuous time systems. 
  9726.  
  9727.  yd 
  9728.             Discrete-time output list (vector) 
  9729.  
  9730.             indicates which outputs are discrete time (i.e.,   produced by D/A 
  9731.            converters) and which are continuous time.   yd(ii) = 0 if output ii 
  9732.            is continuous, = 1 if discrete. 
  9733.  
  9734.  The remaining variables of the  system data structure are only present if the 
  9735.  corresponding entry of the sys vector is true (=1). 
  9736.  
  9737.  
  9738. ΓòÉΓòÉΓòÉ 28.3.2. tf format variables ΓòÉΓòÉΓòÉ
  9739.  
  9740.  num 
  9741.             numerator coefficients  (vector) 
  9742.  
  9743.  den 
  9744.             denominator coefficients  (vector) 
  9745.  
  9746.  
  9747. ΓòÉΓòÉΓòÉ 28.3.3. zp format variables ΓòÉΓòÉΓòÉ
  9748.  
  9749.  zer 
  9750.             system zeros  (vector) 
  9751.  
  9752.  pol 
  9753.             system poles   (vector) 
  9754.  
  9755.  k 
  9756.             leading coefficient  (scalar) 
  9757.  
  9758.  
  9759. ΓòÉΓòÉΓòÉ 28.3.4. ss format variables ΓòÉΓòÉΓòÉ
  9760.  
  9761.  a,b,c,d 
  9762.            The usual state-space matrices. If a system has both     continuous 
  9763.            and discrete states, they are sorted so that     continuous states 
  9764.            come first, then discrete states 
  9765.  
  9766.            *Note* some functions (e.g., bode, hinfsyn) will not accept systems 
  9767.            with both discrete and continuous states/outputs 
  9768.  
  9769.  stname 
  9770.            names of system states  (list of strings) 
  9771.  
  9772.  
  9773. ΓòÉΓòÉΓòÉ 28.4. System Construction and Interface Functions ΓòÉΓòÉΓòÉ
  9774.  
  9775. Construction and manipulations of the OCST system data structure (See 
  9776. sysstruct) requires attention to many details in order to ensure that data 
  9777. structure contents remain consistent.  Users are strongly encouraged to use the 
  9778. system interface functions in this section.  Functions for the formatted 
  9779. display in of system data structures are given in sysdisp. 
  9780.  
  9781. * Finite impulse response system interface functions:fir2sys. 
  9782.  
  9783.  sys2fir 
  9784.  * State space system interface functions:ss2sys. 
  9785.  
  9786.  sys2ss 
  9787.  * Transfer function system interface functions:tf2sys. 
  9788.  
  9789.  sys2tf 
  9790.  * Zero-pole system interface functions:zp2sys. 
  9791.  
  9792.  sys2zp 
  9793.  * Data structure access functions:structaccess. * Data structure internal 
  9794.  functions:structintern 
  9795.  
  9796.  
  9797. ΓòÉΓòÉΓòÉ 28.4.1. Finite impulse response system interface functions ΓòÉΓòÉΓòÉ
  9798.  
  9799. Function File : sys = fir2sys ( num{, tsam, inname, outname } ) 
  9800.  construct a system data structure from FIR description 
  9801.  
  9802. *Inputs:* 
  9803.  
  9804.  num 
  9805.             vector of coefficients [c_0 c_1 ... c_n] of the SISO FIR transfer 
  9806.            function 
  9807.  
  9808.            C(z) = c0 + c1*z^{-1} + c2*z^{-2} + ... + znz^{-n} 
  9809.  
  9810.  tsam 
  9811.              sampling time (default: 1) 
  9812.  
  9813.  inname 
  9814.            name of input signal;  may be a string or a list with a single 
  9815.            entry. 
  9816.  
  9817.  outname 
  9818.             name of output signal; may be a string or a list with a single 
  9819.            entry. 
  9820.  
  9821.  *Outputs*  sys (system data structure) 
  9822.  
  9823.  *Example* 
  9824.  
  9825.   octave:1> sys = fir2sys([1 -1 2 4],0.342,"A/D input","filter output");
  9826.   octave:2> sysout(sys)
  9827.   Input(s)
  9828.           1: A/D input
  9829.  
  9830.   Output(s):
  9831.           1: filter output (discrete)
  9832.  
  9833.   Sampling interval: 0.342
  9834.   transfer function form:
  9835.   1*z^3 - 1*z^2 + 2*z^1 + 4
  9836.   -------------------------
  9837.   1*z^3 + 0*z^2 + 0*z^1 + 0
  9838.  
  9839.  
  9840. ΓòÉΓòÉΓòÉ 29. sys2fir ΓòÉΓòÉΓòÉ
  9841.  
  9842. Function File : [c, tsam, input, output] = sys2fir (sys) 
  9843.  
  9844. Extract FIR data from system data structure; see fir2sys for parameter 
  9845. descriptions. 
  9846.  
  9847.  
  9848. ΓòÉΓòÉΓòÉ 29.1. State space system interface functions ΓòÉΓòÉΓòÉ
  9849.  
  9850. Function File : sys = ss2sys  (a,b,c{,d, tsam, n, nz, stname, inname, outname, 
  9851. outlist}) 
  9852.  Create system structure from state-space data.  May be continous,  discrete, 
  9853. or mixed (sampeld-data) 
  9854.  
  9855. *Inputs* 
  9856.  
  9857.  a, b, c, d 
  9858.             usual state space matrices. 
  9859.  
  9860.                    default: d = zero matrix 
  9861.  
  9862.  tsam 
  9863.             sampling rate.  Default: tsam = 0 (continuous system) 
  9864.  
  9865.  n, nz 
  9866.             number of continuous, discrete states in the system 
  9867.  
  9868.                default: 
  9869.  
  9870.            tsam = 0 
  9871.                           n = rows(a), nz = 0 
  9872.  
  9873.            tsam > 0 
  9874.                           n = 0,    nz = rows(a) 
  9875.  
  9876.                               see below for system partitioning 
  9877.  
  9878.  stname 
  9879.             list of strings of state signal names 
  9880.  
  9881.                  default (stname=[] on input): x_n for continuous states, 
  9882.            xd_n for discrete states 
  9883.  
  9884.  inname 
  9885.             list of strings of input signal names 
  9886.  
  9887.                  default (inname = [] on input): u_n 
  9888.  
  9889.  outname 
  9890.             list of strings of input signal names 
  9891.  
  9892.                  default (outname = [] on input): y_n 
  9893.  
  9894.  outlist 
  9895.             list of indices of outputs y that are sampled 
  9896.  
  9897.                  default: 
  9898.  
  9899.            tsam = 0 
  9900.                           outlist = [] 
  9901.  
  9902.            tsam > 0 
  9903.                           outlist = 1:rows(c) 
  9904.  
  9905.            Unlike states, discrete/continous outputs may appear in any order. 
  9906.  
  9907.            *Note* sys2ss returns a vector yd where yd(outlist) = 1; all other 
  9908.            entries of yd are 0. 
  9909.  
  9910.  *Outputs* outsys = system data structure 
  9911.  
  9912.  *System partitioning* 
  9913.  
  9914.   Suppose for simplicity that outlist specified  that the first several outputs 
  9915.  were continuous and the remaining outputs  were discrete.  Then the system is 
  9916.  partitioned as 
  9917.  
  9918.   x = [ xc ]  (n x 1)
  9919.       [ xd ]  (nz x 1 discrete states)
  9920.   a = [ acc acd ]  b = [ bc ]
  9921.       [ adc add ]      [ bd ]
  9922.   c = [ ccc ccd ]  d = [ dc ]
  9923.       [ cdc cdd ]      [ dd ]
  9924.  
  9925.       (cdc = c(outlist,1:n), etc.)
  9926.  
  9927.  with dynamic equations: d/dt xc(t)   = acc*xc(t)    + acd*xd(k*tsam) + bc*u(t) 
  9928.  
  9929.  xd((k+1)*tsam) = adc*xc(k*tsam) + add*xd(k*tsam) + bd*u(k*tsam) 
  9930.  
  9931.  yc(t)    = ccc*xc(t)    + ccd*xd(k*tsam) + dc*u(t) 
  9932.  
  9933.  yd(k*tsam) = cdc*xc(k*tsam) + cdd*xd(k*tsam) + dd*u(k*tsam) 
  9934.  
  9935.  *Signal partitions* 
  9936.  
  9937.           | continuous      | discrete               |
  9938.   ----------------------------------------------------
  9939.   states  | stname(1:n,:)   | stname((n+1):(n+nz),:) |
  9940.   ----------------------------------------------------
  9941.   outputs | outname(cout,:) | outname(outlist,:)     |
  9942.   ----------------------------------------------------
  9943.  
  9944.  where cout is the list of in 1:rows(p) that are not contained in outlist. 
  9945.  (Discrete/continuous outputs may be entered in any order desired by the user.) 
  9946.  
  9947.  *Example* 
  9948.  
  9949.   octave:1> a = [1 2 3; 4 5 6; 7 8 10];
  9950.   octave:2> b = [0 0 ; 0 1 ; 1 0];
  9951.   octave:3> c = eye(3);
  9952.   octave:4> sys = ss2sys(a,b,c,[],0,3,0,list("volts","amps","joules"));
  9953.   octave:5> sysout(sys);
  9954.   Input(s)
  9955.           1: u_1
  9956.           2: u_2
  9957.  
  9958.   Output(s):
  9959.           1: y_1
  9960.           2: y_2
  9961.           3: y_3
  9962.  
  9963.   state-space form:
  9964.   3 continuous states, 0 discrete states
  9965.   State(s):
  9966.           1: volts
  9967.           2: amps
  9968.           3: joules
  9969.  
  9970.   A matrix: 3 x 3
  9971.      1   2   3
  9972.      4   5   6
  9973.      7   8  10
  9974.   B matrix: 3 x 2
  9975.     0  0
  9976.     0  1
  9977.     1  0
  9978.   C matrix: 3 x 3
  9979.     1  0  0
  9980.     0  1  0
  9981.     0  0  1
  9982.   D matrix: 3 x 3
  9983.     0  0
  9984.     0  0
  9985.     0  0
  9986.  
  9987.  Notice that the D matrix is constructed  by default to the correct dimensions. 
  9988.  Default input and output signals names were assigned since none were given. 
  9989.  
  9990.  
  9991. ΓòÉΓòÉΓòÉ 30. sys2ss ΓòÉΓòÉΓòÉ
  9992.  
  9993. Function File : [a,b,c,d,tsam,n,nz,stname,inname,outname,yd] = sys2ss (sys) 
  9994. Extract state space representation from system data structure. 
  9995.  
  9996. *Inputs* sys system data structure (See sysstruct) 
  9997.  
  9998. *Outputs* 
  9999.  
  10000.  a,b,c,d 
  10001.             state space matrices for sys 
  10002.  
  10003.  tsam 
  10004.             sampling time of sys (0 if continuous) 
  10005.  
  10006.  n, nz 
  10007.             number of continuous, discrete states (discrete states come 
  10008.            last in state vector x) 
  10009.  
  10010.  stname, inname, outname 
  10011.             signal names (lists of strings);  names of states,      inputs, and 
  10012.            outputs, respectively 
  10013.  
  10014.  yd 
  10015.             binary vector; yd(ii) is 1 if output y(ii)$  is discrete (sampled); 
  10016.            otherwise  yd(ii) 0. 
  10017.  
  10018.  *Example* 
  10019.  
  10020.   octave:1> sys=tf2sys([1 2],[3 4 5]);
  10021.   octave:2> [a,b,c,d] = sys2ss(sys)
  10022.   a =
  10023.      0.00000   1.00000
  10024.     -1.66667  -1.33333
  10025.   b =
  10026.     0
  10027.     1
  10028.   c = 0.66667  0.33333
  10029.   d = 0
  10030.  
  10031.  
  10032. ΓòÉΓòÉΓòÉ 30.1. Transfer function system interface functions ΓòÉΓòÉΓòÉ
  10033.  
  10034. Function File : sys =  tf2sys( num, den {, tsam, inname, outname }) 
  10035.  build system data structure from transfer function format data 
  10036.  
  10037. *Inputs* 
  10038.  
  10039.  num, den 
  10040.             coefficients of numerator/denominator polynomials 
  10041.  
  10042.  tsam 
  10043.             sampling interval. default: 0 (continuous time) 
  10044.  
  10045.  inname, outname 
  10046.             input/output signal names; may be a string or list with a single 
  10047.            string entry. 
  10048.  
  10049.  *Outputs*  sys = system data structure 
  10050.  
  10051.  *Example* 
  10052.  
  10053.   octave:1> sys=tf2sys([2 1],[1 2 1],0.1);
  10054.   octave:2> sysout(sys)
  10055.   Input(s)
  10056.           1: u_1
  10057.   Output(s):
  10058.           1: y_1 (discrete)
  10059.   Sampling interval: 0.1
  10060.   transfer function form:
  10061.   2*z^1 + 1
  10062.   -----------------
  10063.   1*z^2 + 2*z^1 + 1
  10064.  
  10065.  
  10066. ΓòÉΓòÉΓòÉ 31. sys2tf ΓòÉΓòÉΓòÉ
  10067.  
  10068. Function File : [num,den,tsam,inname,outname] = sys2tf (sys) 
  10069. Extract transfer function data from a system data structure 
  10070.  
  10071. See tf2sys for parameter descriptions. 
  10072.  
  10073. *Example* 
  10074.  
  10075. octave:1> sys=ss2sys([1 -2; -1.1,-2.1],[0;1],[1 1]);
  10076. octave:2> [num,den] = sys2tf(sys)
  10077. num = 1.0000  -3.0000
  10078. den = 1.0000   1.1000  -4.3000
  10079.  
  10080.  
  10081. ΓòÉΓòÉΓòÉ 31.1. Zero-pole system interface functions ΓòÉΓòÉΓòÉ
  10082.  
  10083. Function File : sys = zp2sys (zer,pol,k{,tsam,inname,outname}) 
  10084.  Create system data structure from zero-pole data 
  10085.  
  10086. *Inputs* 
  10087.  
  10088.  zer 
  10089.             vector of system zeros 
  10090.  
  10091.  pol 
  10092.             vector of system poles 
  10093.  
  10094.  k 
  10095.             scalar leading coefficient 
  10096.  
  10097.  tsam 
  10098.             sampling period. default: 0 (continuous system) 
  10099.  
  10100.  inname, outname 
  10101.             input/output signal names (lists of strings) 
  10102.  
  10103.  *Outputs*  sys: system data structure 
  10104.  
  10105.  *Example* 
  10106.  
  10107.   octave:1> sys=zp2sys([1 -1],[-2 -2 0],1);
  10108.   octave:2> sysout(sys)
  10109.   Input(s)
  10110.           1: u_1
  10111.   Output(s):
  10112.           1: y_1
  10113.   zero-pole form:
  10114.   1 (s - 1) (s + 1)
  10115.   -----------------
  10116.   s (s + 2) (s + 2)
  10117.  
  10118.  
  10119. ΓòÉΓòÉΓòÉ 32. sys2zp ΓòÉΓòÉΓòÉ
  10120.  
  10121. Function File : [zer, pol, k, tsam, inname, outname] = sys2zp (sys) 
  10122. Extract zero/pole/leading coefficient information from a system data structure 
  10123.  
  10124. See zp2sys for parameter descriptions. 
  10125.  
  10126. *Example* 
  10127.  
  10128. octave:1> sys=ss2sys([1 -2; -1.1,-2.1],[0;1],[1 1]);
  10129. octave:2> [zer,pol,k] = sys2zp(sys)
  10130. zer = 3.0000
  10131. pol =
  10132.   -2.6953
  10133.    1.5953
  10134. k = 1
  10135.  
  10136.  
  10137. ΓòÉΓòÉΓòÉ 32.1. Data structure access functions ΓòÉΓòÉΓòÉ
  10138.  
  10139.  syschnames 
  10140.  syschtsam 
  10141.  sysdimensions 
  10142.  sysgetsignals 
  10143.  sysgettsam 
  10144.  sysgettype 
  10145.  syssetsignals 
  10146.  sysupdate 
  10147.  
  10148.  
  10149. ΓòÉΓòÉΓòÉ 33. syschnames ΓòÉΓòÉΓòÉ
  10150.  
  10151. Function File : retsys = syschnames (sys, opt, list, names) 
  10152. Superseded by syssetsignals 
  10153.  
  10154.  
  10155. ΓòÉΓòÉΓòÉ 34. syschtsam ΓòÉΓòÉΓòÉ
  10156.  
  10157. Function File : retsys = syschtsam ( sys,tsam ) 
  10158. This function changes the sampling time (tsam) of the system.  Exits with an 
  10159. error if sys is purely continuous time. 
  10160.  
  10161.  
  10162. ΓòÉΓòÉΓòÉ 35. sysdimensions ΓòÉΓòÉΓòÉ
  10163.  
  10164. Function File : [n, nz, m, p,yd] = sysdimensions (sys{, opt}) 
  10165.  return the number of states, inputs, and/or outputs in the system sys. 
  10166.  
  10167. *Inputs* 
  10168.  
  10169.  sys 
  10170.             system data structure 
  10171.  
  10172.  opt 
  10173.            String indicating which dimensions are desired.  Values: 
  10174.  
  10175.            "all" 
  10176.                           (default) return all parameters as specified under 
  10177.                           Outputs below. 
  10178.  
  10179.            "cst" 
  10180.                           return n= number of continuous states 
  10181.  
  10182.            "dst" 
  10183.                           return n= number of discrete states 
  10184.  
  10185.            "in" 
  10186.                           return n= number of inputs 
  10187.  
  10188.            "out" 
  10189.                           return n= number of outputs 
  10190.  
  10191.  *Outputs* 
  10192.  
  10193.  n 
  10194.             number of continuous states (or individual requested dimension as 
  10195.            specified by opt). 
  10196.  
  10197.  nz 
  10198.             number of discrete states 
  10199.  
  10200.  m 
  10201.             number of system inputs 
  10202.  
  10203.  p 
  10204.             number of system outputs 
  10205.  
  10206.  yd 
  10207.             binary vector; yd(ii) is nonzero if output ii is discrete. yd(ii) = 
  10208.            0 if output ii is continous 
  10209.  
  10210.  
  10211. ΓòÉΓòÉΓòÉ 36. sysgetsignals ΓòÉΓòÉΓòÉ
  10212.  
  10213. Function File : [stname, inname, outname, yd] = sysgetsignals (sys) 
  10214.  
  10215. Function File : siglist = sysgetsignals (sys,sigid) 
  10216.  
  10217. Function File : signame = sysgetsignals (sys,sigid,signum{, strflg}) 
  10218.  Get signal names from a system 
  10219.  
  10220. *Inputs* 
  10221.  
  10222.  sys 
  10223.             system data structure for the state space system 
  10224.  
  10225.  sigid 
  10226.            signal id.  String.  Must be one of 
  10227.  
  10228.            "in" 
  10229.                           input signals 
  10230.  
  10231.            "out" 
  10232.                           output signals 
  10233.  
  10234.            "st" 
  10235.                           stage signals 
  10236.  
  10237.            "yd" 
  10238.                           value of logical vector yd 
  10239.  
  10240.  signum 
  10241.            Index of signal (or indices of signals if signum is a vector) 
  10242.  
  10243.  strflg 
  10244.            flag to return a string instead of a list;  Values: 
  10245.  
  10246.            0 
  10247.                           (default) return a list (even if signum is a scalar) 
  10248.  
  10249.            1 
  10250.                           return a string.  Exits with an error if signum is 
  10251.                           not a scalar. 
  10252.  
  10253.  *Outputs* 
  10254.  
  10255.  ΓûáIf sigid is not specified 
  10256.  
  10257.            stname, inname, outname 
  10258.                                signal names (lists of strings);  names of 
  10259.                           states,      inputs, and outputs, respectively 
  10260.  
  10261.            yd 
  10262.                            binary vector; yd(ii) is nonzero if output ii is 
  10263.                           discrete. 
  10264.  
  10265.  ΓûáIf sigid is specified but signum is not specified, then 
  10266.  
  10267.            sigid="in" 
  10268.                           siglist is set to the list of input names 
  10269.  
  10270.            sigid="out" 
  10271.                           siglist is set to the list of output names 
  10272.  
  10273.            sigid="st" 
  10274.                           siglist is set to the list of state names 
  10275.  
  10276.                           stage signals 
  10277.  
  10278.            sigid="yd" 
  10279.                           siglist is set to logical vector indicating discrete 
  10280.                           outputs; siglist(ii) = 0 indicates that output ii is 
  10281.                           continuous (unsampled), otherwise it is discrete. 
  10282.  
  10283.  Γûáif the first three input arguments are specified, then signame is 
  10284.            a list of the specified signal names (sigid is "in", "out", or 
  10285.            "st"), or else the logical flag indicating whether output(s) signum 
  10286.            is(are) discrete (sigval=1) or continuous (sigval=0). 
  10287.  
  10288.  *Examples* (From sysrepdemo) 
  10289.  
  10290.   octave> sys=ss2sys(rand(4),rand(4,2),rand(3,4));
  10291.   octave> [Ast,Ain,Aout,Ayd] = sysgetsignals(sys) i  # get all signal names
  10292.   Ast =
  10293.   (
  10294.     [1] = x_1
  10295.     [2] = x_2
  10296.     [3] = x_3
  10297.     [4] = x_4
  10298.   )
  10299.   Ain =
  10300.   (
  10301.     [1] = u_1
  10302.     [2] = u_2
  10303.   )
  10304.   Aout =
  10305.   (
  10306.     [1] = y_1
  10307.     [2] = y_2
  10308.     [3] = y_3
  10309.   )
  10310.   Ayd =
  10311.  
  10312.     0  0  0
  10313.   octave> Ain = sysgetsignals(sys,"in")   # get only input signal names
  10314.   Ain =
  10315.   (
  10316.     [1] = u_1
  10317.     [2] = u_2
  10318.   )
  10319.   octave> Aout = sysgetsignals(sys,"out",2)   # get name of output 2 (in list)
  10320.   Aout =
  10321.   (
  10322.     [1] = y_2
  10323.   )
  10324.   octave> Aout = sysgetsignals(sys,"out",2,1)  # get name of output 2 (as string)
  10325.   Aout = y_2
  10326.  
  10327.  
  10328. ΓòÉΓòÉΓòÉ 37. sysgettsam ΓòÉΓòÉΓòÉ
  10329.  
  10330. Function File : Tsam = sysgettsam ( sys ) 
  10331.  return the sampling time of the system 
  10332.  
  10333.  
  10334. ΓòÉΓòÉΓòÉ 38. sysgettype ΓòÉΓòÉΓòÉ
  10335.  
  10336. Function File : systype = sysgettype ( sys ) 
  10337.  return the initial system type of the system 
  10338.  
  10339. *Inputs*   sys: system data structure 
  10340.  
  10341. *Outputs*   systype: string indicating how the structure was initially 
  10342. constructed:    values: "ss", "zp", or "tf" 
  10343.  
  10344. *Note* FIR initialized systems return systype="tf". 
  10345.  
  10346.  
  10347. ΓòÉΓòÉΓòÉ 39. syssetsignals ΓòÉΓòÉΓòÉ
  10348.  
  10349. Function File : retsys = syssetsignals (sys, opt, names{, sig_idx}) 
  10350.  change the names of selected inputs, outputs and states. *Inputs* 
  10351.  
  10352.  sys 
  10353.             system data structure 
  10354.  
  10355.  opt 
  10356.            change default name (output) 
  10357.  
  10358.            "out" 
  10359.                            change selected output names 
  10360.  
  10361.            "in" 
  10362.                            change selected input names 
  10363.  
  10364.            "st" 
  10365.                            change selected state names 
  10366.  
  10367.            "yd" 
  10368.                            change selected outputs from discrete to continuous 
  10369.                           or           from continuous to discrete. 
  10370.  
  10371.  names 
  10372.  
  10373.            opt = "out", "in", or "st" 
  10374.                            string or string array containing desired signal 
  10375.                           names or values. 
  10376.  
  10377.            opt = "yd" 
  10378.                           To desired output continuous/discrete flag. Set name 
  10379.                           to 0 for continuous, or 1 for discrete. 
  10380.  
  10381.  list 
  10382.             vector of indices of outputs, yd, inputs, or        states whose 
  10383.            respective names should be changed. 
  10384.  
  10385.                   Default: replace entire list of names/entire yd vector. 
  10386.  
  10387.  *Outputs*   retsys=sys with appropriate signal names changed       (or yd 
  10388.  values, where appropriate) 
  10389.  
  10390.  *Example* 
  10391.  
  10392.   octave:1> sys=ss2sys([1 2; 3 4],[5;6],[7 8]);
  10393.   octave:2> sys = syssetsignals(sys,"st",str2mat("Posx","Velx"));
  10394.   octave:3> sysout(sys)
  10395.   Input(s)
  10396.           1: u_1
  10397.   Output(s):
  10398.           1: y_1
  10399.   state-space form:
  10400.   2 continuous states, 0 discrete states
  10401.   State(s):
  10402.           1: Posx
  10403.           2: Velx
  10404.   A matrix: 2 x 2
  10405.     1  2
  10406.     3  4
  10407.   B matrix: 2 x 1
  10408.     5
  10409.     6
  10410.   C matrix: 1 x 2
  10411.     7  8
  10412.   D matrix: 1 x 1
  10413.   0
  10414.  
  10415.  
  10416. ΓòÉΓòÉΓòÉ 40. sysupdate ΓòÉΓòÉΓòÉ
  10417.  
  10418. Function File : sys = sysupdate ( sys, opt ) 
  10419.  Update the internal representation of a system. 
  10420.  
  10421. *Inputs* 
  10422.  
  10423.  sys: 
  10424.            system data structure 
  10425.  
  10426.  opt 
  10427.             string: 
  10428.  
  10429.            "tf" 
  10430.                           update transfer function form 
  10431.  
  10432.            "zp" 
  10433.                           update zero-pole form 
  10434.  
  10435.            "ss" 
  10436.                           update state space form 
  10437.  
  10438.            "all" 
  10439.                           all of the above 
  10440.  
  10441.  *Outputs* retsys: contains union of data in sys and requested data. If 
  10442.  requested data in sys is already up to date then retsys=sys. 
  10443.  
  10444.  Conversion to tf or zp exits with an error if the system is  mixed 
  10445.  continuous/digital. 
  10446.  
  10447.  
  10448. ΓòÉΓòÉΓòÉ 40.1. Data structure internal functions ΓòÉΓòÉΓòÉ
  10449.  
  10450. Function File :  syschnamesl 
  10451.  used internally in syschnames 
  10452.  
  10453. Function File : ioname = sysdefioname (n,str {,m}) 
  10454. return default input or output names given n, str, m.  n is the final value, 
  10455. str is the string prefix, and m is start value 
  10456.  
  10457.  used internally, minimal argument checking 
  10458.  
  10459. *Example* ioname = sysdefioname(5,"u",3) returns the list: 
  10460.  
  10461. ioname =
  10462. (
  10463.   [1] = u_3
  10464.   [2] = u_4
  10465.   [3] = u_5
  10466. )
  10467.  
  10468. Function File : stname = sysdefstname (n, nz) 
  10469.  return default state names given n, nz 
  10470.  
  10471.  used internally, minimal argument checking 
  10472.  
  10473. Function File : vec =  tf2sysl (vec) 
  10474.  used internally in tf2sys.  strip leading zero coefficients to get the true 
  10475. polynomial length 
  10476.  
  10477.  
  10478. ΓòÉΓòÉΓòÉ 40.2. System display functions ΓòÉΓòÉΓòÉ
  10479.  
  10480. Function File :  sysout ( sys{, opt}) 
  10481.  print out a system data structure in desired format 
  10482.  
  10483.  sys 
  10484.             system data structure 
  10485.  
  10486.  opt 
  10487.            Display option 
  10488.  
  10489.            [] 
  10490.                            primary system form (default); see sysgettype. 
  10491.  
  10492.            "ss" 
  10493.                            state space form 
  10494.  
  10495.            "tf" 
  10496.                            transfer function form 
  10497.  
  10498.            "zp" 
  10499.                            zero-pole form 
  10500.  
  10501.            "all" 
  10502.                            all of the above 
  10503.  
  10504.  Function File : y = polyout ( c{, x}) 
  10505.  write formatted polynomial 
  10506.  
  10507.      c(x) = c(1) * x^n + ... + c(n) x + c(n+1)
  10508.  
  10509.   to string y or to the screen (if y is omitted)  x defaults to the string "s" 
  10510.  
  10511.  Function File :  tfout (num, denom{, x}) 
  10512.   print formatted transfer function n(s)/d(s)  to the screen  x defaults to the 
  10513.  string "s" 
  10514.  
  10515.  Function File :  zpout (zer, pol, k{, x}) 
  10516.   print formatted zero-pole form to the screen. x defaults to the string "s" 
  10517.  
  10518.  Function File :  outlist (lmat{, tabchar, yd, ilist }) 
  10519.   Prints an enumerated list of strings.  internal use only; minimal argument 
  10520.  checking performed 
  10521.  
  10522.  *Inputs* 
  10523.  
  10524.  lmat 
  10525.             list of strings 
  10526.  
  10527.  tabchar 
  10528.             tab character (default: none) 
  10529.  
  10530.  yd 
  10531.             indices of strings to append with the string "(discrete)" 
  10532.            (used by sysout; minimal checking of this argument)       yd = [] 
  10533.            indicates all outputs are continuous 
  10534.  
  10535.  ilist 
  10536.            index numbers to print with names. 
  10537.  
  10538.            default: 1:rows(lmat) 
  10539.  
  10540.  *Outputs*   prints the list to the screen, numbering each string in order. 
  10541.  
  10542.  
  10543. ΓòÉΓòÉΓòÉ 40.3. Block Diagram Manipulations ΓòÉΓòÉΓòÉ
  10544.  
  10545. See systime 
  10546.  
  10547. Unless otherwise noted, all parameters (input,output) are system data 
  10548. structures. 
  10549.  
  10550.  buildssic 
  10551.  jet707 
  10552.  ord2 
  10553.  parallel 
  10554.  sysadd 
  10555.  sysappend 
  10556.  sysconnect 
  10557.  syscont 
  10558.  syscont_disc 
  10559.  sysdisc 
  10560.  sysdup 
  10561.  sysgroup 
  10562.  sysgroupn 
  10563.  sysmult 
  10564.  sysprune 
  10565.  sysreorder 
  10566.  sysscale 
  10567.  syssub 
  10568.  
  10569.  Function File : outputs = bddemo ( inputs ) 
  10570.   Octave Controls toolbox demo: Block Diagram Manipulations demo 
  10571.  
  10572.  
  10573. ΓòÉΓòÉΓòÉ 41. buildssic ΓòÉΓòÉΓòÉ
  10574.  
  10575. Function File : [sys] = buildssic(Clst, Ulst, Olst, Ilst, s1, s2, s3, s4, s5, 
  10576. s6, s7, s8) 
  10577.  
  10578. Contributed by Kai Mueller. 
  10579.  
  10580.  Form an arbitrary complex (open or closed loop) system in  state-space form 
  10581. from several systems. "buildssic" can  easily (despite it's cryptic syntax) 
  10582. integrate transfer functions  from a complex block diagram into a single system 
  10583. with one call.  This function is especially useful for building open loop 
  10584. interconnections for H_infinity and H2 designs or for closing  loops with these 
  10585. controllers. 
  10586.  
  10587.  Although this function is general purpose, the use of "sysgroup"  "sysmult", 
  10588. "sysconnect" and the like is recommended for standard  operations since they 
  10589. can handle mixed discrete and continuous  systems and also the names of inputs, 
  10590. outputs, and states. 
  10591.  
  10592.  The parameters consist of 4 lists that describe the connections  outputs and 
  10593. inputs and up to 8 systems s1-s8.  Format of the lists: 
  10594.  
  10595.  Clst 
  10596.            connection list, describes the input signal of each system. The 
  10597.            maximum number of rows of Clst is equal to the sum of all inputs of 
  10598.            s1-s8. 
  10599.  
  10600.            Example: [1 2 -1; 2 1 0] ==> new input 1 is old inpout 1 + output 2 
  10601.            - output 1, new input 2 is old input 2 + output 1. The order of rows 
  10602.            is arbitrary. 
  10603.  
  10604.  Ulst 
  10605.             if not empty the old inputs in vector Ulst will       be appended 
  10606.            to the outputs. You need this if you       want to "pull out" the 
  10607.            input of a system. Elements       are input numbers of s1-s8. 
  10608.  
  10609.  Olst 
  10610.             output list, specifiy the outputs of the resulting       systems. 
  10611.            Elements are output numbers of s1-s8.       The numbers are alowed 
  10612.            to be negative and may       appear in any order. An empty matrix 
  10613.            means       all outputs. 
  10614.  
  10615.  Ilst 
  10616.             input list, specifiy the inputs of the resulting       systems. 
  10617.            Elements are input numbers of s1-s8.       The numbers are alowed to 
  10618.            be negative and may       appear in any order. An empty matrix means 
  10619.            all inputs. 
  10620.  
  10621.   Example:  Very simple closed loop system. 
  10622.  
  10623.   w        e  +-----+   u  +-----+
  10624.    --->o--*-->|  K  |--*-->|  G  |--*---> y
  10625.        ^  |   +-----+  |   +-----+  |
  10626.      - |  |            |            |
  10627.        |  |            +----------------> u
  10628.        |  |                         |
  10629.        |  +-------------------------|---> e
  10630.        |                            |
  10631.        +----------------------------+
  10632.  
  10633.  The closed loop system GW can be optained by 
  10634.  
  10635.   GW = buildssic([1 2; 2 -1], [2], [1 2 3], [2], G, K);
  10636.  
  10637.  Clst 
  10638.            (1. row) connect input 1 (G) with output 2 (K). (2. row) connect 
  10639.            input 2 (K) with neg. output 1 (G). 
  10640.  
  10641.  Ulst 
  10642.            append input of (2) K to the number of outputs. 
  10643.  
  10644.  Olst 
  10645.            Outputs are output of 1 (G), 2 (K) and appended output 3 (from 
  10646.            Ulst). 
  10647.  
  10648.  Ilst 
  10649.            the only input is 2 (K). 
  10650.  
  10651.  Here is a real example: 
  10652.  
  10653.                            +----+
  10654.       -------------------->| W1 |---> v1
  10655.   z   |                    +----+
  10656.   ----|-------------+                   || GW   ||     => min.
  10657.       |             |                        vz   infty
  10658.       |    +---+    v      +----+
  10659.       *--->| G |--->O--*-->| W2 |---> v2
  10660.       |    +---+       |   +----+
  10661.       |                |
  10662.       |                v
  10663.      u                  y
  10664.  
  10665.  The closed loop system GW from [z; u]' to [v1; v2; y]' can be obtained by (all 
  10666.  SISO systems): 
  10667.  
  10668.   GW = buildssic([1 4;2 4;3 1],[3],[2 3 5],[3 4],G,W1,W2,One);
  10669.  
  10670.  where "One" is a unity gain (auxillary) function with order 0. (e.g. One = 
  10671.  ugain(1);) 
  10672.  
  10673.  
  10674. ΓòÉΓòÉΓòÉ 42. jet707 ΓòÉΓòÉΓòÉ
  10675.  
  10676. Function File : outsys  = jet707 ( ) 
  10677.  Creates linearized state space model of a Boeing 707-321 aircraft  at v=80m/s. 
  10678. (M = 0.26, Ga0 = -3 deg, alpha0 = 4 deg, kappa = 50 deg)  System inputs:  (1) 
  10679. thrust  and (2) elevator angle  System outputs:  (1) airspeed and (2) pitch 
  10680. angle  Ref: R. Brockhaus: Flugregelung (Flight Control), Springer, 1994 
  10681.  
  10682.  see also: ord2 
  10683.  
  10684. Contributed by Kai Mueller 
  10685.  
  10686.  
  10687. ΓòÉΓòÉΓòÉ 43. ord2 ΓòÉΓòÉΓòÉ
  10688.  
  10689. Function File : outsys = ord2 (nfreq, damp{[, gain}) 
  10690.  Creates a continuous 2nd order system with parameters: *Inputs* 
  10691.  
  10692.  nfreq:  natural frequency [Hz]. (not in rad/s) 
  10693.  
  10694.  damp:   damping coefficient 
  10695.  
  10696.  gain:   dc-gain 
  10697.                    This is steady state value only for damp > 0.         gain 
  10698.            is assumed to be 1.0 if ommitted. 
  10699.  
  10700.  *Outputs* outsys    system data structure has representation with w = 2 * pi * 
  10701.  nfreq: 
  10702.  
  10703.       /                                        \
  10704.       | / -2w*damp -w \  / w \                 |
  10705.   G = | |             |, |   |, [ 0  gain ], 0 |
  10706.       | \   w       0 /  \ 0 /                 |
  10707.       \                                        /
  10708.  
  10709.  *See also* jet707 (MIMO example, Boeing 707-321 aircraft model) 
  10710.  
  10711.  
  10712. ΓòÉΓòÉΓòÉ 44. parallel ΓòÉΓòÉΓòÉ
  10713.  
  10714. Function File : sysp = parallel(Asys, Bsys) 
  10715. Forms the parallel connection of two systems. 
  10716.  
  10717.          ____________________
  10718.          |      ________    |
  10719. u  ----->|----> | Asys |--->|----> y1
  10720.     |    |      --------    |
  10721.     |    |      ________    |
  10722.     |--->|----> | Bsys |--->|----> y2
  10723.          |      --------    |
  10724.          --------------------
  10725.               Ksys
  10726.  
  10727.  
  10728. ΓòÉΓòÉΓòÉ 45. sysadd ΓòÉΓòÉΓòÉ
  10729.  
  10730. Function File : sys =  sysadd ( Gsys,Hsys) 
  10731. returns sys = Gsys + Hsys. 
  10732.  
  10733.      Exits with an error if Gsys and Hsys are not compatibly dimensioned. 
  10734.  
  10735.      Prints a warning message is system states have identical names; 
  10736.       duplicate names are given a suffix to make them unique. 
  10737.  
  10738.      sys input/output names are taken from Gsys. 
  10739.  
  10740.             ________
  10741.        ----|  Gsys  |---
  10742.   u   |    ----------  +|
  10743.   -----                (_)----> y
  10744.       |     ________   +|
  10745.        ----|  Hsys  |---
  10746.             --------
  10747.  
  10748.  
  10749. ΓòÉΓòÉΓòÉ 46. sysappend ΓòÉΓòÉΓòÉ
  10750.  
  10751. Function File : retsys = sysappend (sys,b{, c, d, outname, inname, yd}) 
  10752. appends new inputs and/or outputs to a system 
  10753.  
  10754. *Inputs* 
  10755.  
  10756.  sys 
  10757.            system data structure 
  10758.  
  10759.  b 
  10760.            matrix to be appended to sys "B" matrix (empty if none) 
  10761.  
  10762.  c 
  10763.            matrix to be appended to sys "C" matrix (empty if none) 
  10764.  
  10765.  d 
  10766.            revised sys d matrix (can be passed as [] if the revised d is all 
  10767.            zeros) 
  10768.  
  10769.  outname 
  10770.            list of names for new outputs 
  10771.  
  10772.  inname 
  10773.            list of names for new inputs 
  10774.  
  10775.  yd 
  10776.            binary vector; yd(ii)=0 indicates a continuous output; yd(ii)=1 
  10777.            indicates a discrete output. 
  10778.  
  10779.  *Outputs* sys 
  10780.  
  10781.      sys.b := [sys.b , b]
  10782.      sys.c := [sys.c  ]
  10783.               [ c     ]
  10784.      sys.d := [sys.d | D12 ]
  10785.               [D21   | D22 ]
  10786.  
  10787.  where D12, D21, and D22 are the appropriate dimensioned blocks of the input 
  10788.  parameter d. 
  10789.  
  10790.      The leading block D11 of d is ignored. 
  10791.  
  10792.      If inname and outname are not given as arguments,     the new inputs and 
  10793.       outputs are be assigned default names. 
  10794.  
  10795.      yd is a binary vector of length rows(c) that indicates 
  10796.       continuous/sampled outputs.  Default value for yd is: 
  10797.  
  10798.      sys = continuous or mixed yd = zeros(1,rows(c)) 
  10799.  
  10800.      sys = discrete yd = ones(1,rows(c)) 
  10801.  
  10802.  
  10803. ΓòÉΓòÉΓòÉ 47. sysconnect ΓòÉΓòÉΓòÉ
  10804.  
  10805. Function File : retsys = sysconnect (sys, out_idx,in_idx{,order, tol}) 
  10806. Close the loop from specified outputs to respective specified inputs 
  10807.  
  10808. *Inputs* 
  10809.  
  10810.  sys 
  10811.            system data structure 
  10812.  
  10813.  out_idx, in_idx 
  10814.            list of connections indices; y(out_idx(ii)) is connected to 
  10815.            u(in_idx(ii)). 
  10816.  
  10817.  order 
  10818.            logical flag (default = 0) 
  10819.  
  10820.            0 
  10821.                           leave inputs and outputs in their original order 
  10822.  
  10823.            1 
  10824.                           permute inputs and outputs to the order shown in the 
  10825.                           diagram below 
  10826.  
  10827.  tol 
  10828.            tolerance for singularities in algebraic loops default: 200eps 
  10829.  
  10830.  *Outputs*  sys: resulting closed loop system. 
  10831.  
  10832.  *Method* sysconnect internally permutes selected inputs, outputs as shown 
  10833.  below, closes the loop, and then permutes inputs and outputs back to their 
  10834.  original order 
  10835.  
  10836.                    ____________________
  10837.    u_1       ----->|                  |----> y_1
  10838.                    |        sys       |
  10839.            old u_2 |                  |
  10840.   u_2* ---->(+)--->|                  |----->y_2
  10841.   (in_idx)   ^     -------------------|    | (out_idx)
  10842.              |                             |
  10843.              -------------------------------
  10844.  
  10845.  The input that has the summing junction added to it has an * added to the end 
  10846.  of the input name. 
  10847.  
  10848.  
  10849. ΓòÉΓòÉΓòÉ 48. syscont ΓòÉΓòÉΓòÉ
  10850.  
  10851. Function File: [csys, Acd, Ccd] =  syscont (sys) 
  10852. Extract the purely continuous subsystem of an input system. 
  10853.  
  10854. *Inputs* sys is a system data structure 
  10855.  
  10856. *Outputs* 
  10857.  
  10858.  csys 
  10859.             is the purely continuous input/output connections of sys 
  10860.  
  10861.  Acd, Ccd: 
  10862.             connections from discrete states to continuous states, 
  10863.            discrete states to continuous outputs, respectively. 
  10864.  
  10865.             returns csys empty if no continuous/continous path exists 
  10866.  
  10867.  
  10868. ΓòÉΓòÉΓòÉ 49. syscont_disc ΓòÉΓòÉΓòÉ
  10869.  
  10870. Function File : [n_tot, st_c, st_d, y_c, y_d] = syscont_disc(sys) 
  10871. Used internally in syscont and sysdisc. 
  10872.  
  10873. *Inputs* sys is a system data structure. 
  10874.  
  10875. *Outputs* 
  10876.  
  10877.  n_tot 
  10878.            total number of states 
  10879.  
  10880.  st_c 
  10881.            vector of continuous state indices (empty if none) 
  10882.  
  10883.  st_d 
  10884.            vector of discrete state indices (empty if none) 
  10885.  
  10886.  y_c 
  10887.            vector of continuous output indices 
  10888.  
  10889.  y_d 
  10890.            vector of discrete output indices 
  10891.  
  10892.  
  10893. ΓòÉΓòÉΓòÉ 50. sysdisc ΓòÉΓòÉΓòÉ
  10894.  
  10895. Function File : [dsys, Adc, Cdc] = sysdisc (sys) 
  10896.  
  10897. *Inputs* sys = system data structure 
  10898.  
  10899. *Outputs* 
  10900.  
  10901.  dsys 
  10902.             purely discrete portion of sys (returned empty if there is      no 
  10903.            purely discrete path from inputs to outputs) 
  10904.  
  10905.  Adc, Cdc 
  10906.             connections from continuous states to discrete states and discrete 
  10907.            outputs, respectively. 
  10908.  
  10909.  
  10910. ΓòÉΓòÉΓòÉ 51. sysdup ΓòÉΓòÉΓòÉ
  10911.  
  10912. Function File : retsys = sysdup (Asys, out_idx, in_idx) 
  10913.  Duplicate specified input/output connections of a system 
  10914.  
  10915. *Inputs* 
  10916.  
  10917.  Asys 
  10918.             system data structure (See ss2sys) 
  10919.  
  10920.  out_idx,in_idx 
  10921.             list of connections indices;     duplicates are made of 
  10922.            y(out_idx(ii)) and u(in_idx(ii)). 
  10923.  
  10924.  *Outputs* retsys: resulting closed loop system:   duplicated i/o names are 
  10925.  appended with a "+" suffix. 
  10926.  
  10927.  *Method* sysdup creates copies of selected inputs and outputs as  shown below. 
  10928.  u1/y1 is the set of original inputs/outputs, and  u2,y2 is the set of 
  10929.  duplicated inputs/outputs in the order specified  in in_idx, out_idx, 
  10930.  respectively 
  10931.  
  10932.             ____________________
  10933.   u1  ----->|                  |----> y1
  10934.             |       Asys       |
  10935.   u2 ------>|                  |----->y2
  10936.   (in_idx)  -------------------| (out_idx)
  10937.  
  10938.  
  10939. ΓòÉΓòÉΓòÉ 52. sysgroup ΓòÉΓòÉΓòÉ
  10940.  
  10941. Function File : sys = sysgroup ( Asys, Bsys) 
  10942. Combines two systems into a single system 
  10943.  
  10944. *Inputs* Asys, Bsys: system data structures 
  10945.  
  10946. *Outputs*  sys = block diag(Asys,Bsys) 
  10947.  
  10948.          __________________
  10949.          |    ________    |
  10950. u1 ----->|--> | Asys |--->|----> y1
  10951.          |    --------    |
  10952.          |    ________    |
  10953. u2 ----->|--> | Bsys |--->|----> y2
  10954.          |    --------    |
  10955.          ------------------
  10956.               Ksys
  10957.  
  10958. The function also rearranges the internal state-space realization of sys so 
  10959. that the  continuous states come first and the discrete states come last.  If 
  10960. there are duplicate names, the second name has a unique suffix appended  on to 
  10961. the end of the name. 
  10962.  
  10963.  
  10964. ΓòÉΓòÉΓòÉ 53. sysgroupn ΓòÉΓòÉΓòÉ
  10965.  
  10966. Function File : names = sysgroupn (names) 
  10967. Locate and mark duplicate names.  Used internally in sysgroup (and elsewhere). 
  10968.  
  10969.  
  10970. ΓòÉΓòÉΓòÉ 54. sysmult ΓòÉΓòÉΓòÉ
  10971.  
  10972. Function File : sys = sysmult( Asys, Bsys) 
  10973. Compute sys = Asys*Bsys (series connection): 
  10974.  
  10975. u   ----------     ----------
  10976. --->|  Bsys  |---->|  Asys  |--->
  10977.     ----------     ----------
  10978.  
  10979. A warning occurs if there is direct feed-through from an input of Bsys or a 
  10980. continuous state of Bsys through a discrete output of Bsys to a continuous 
  10981. state or output in Asys (system data structure does not recognize discrete 
  10982. inputs). 
  10983.  
  10984.  
  10985. ΓòÉΓòÉΓòÉ 55. sysprune ΓòÉΓòÉΓòÉ
  10986.  
  10987. Function File : retsys = sysprune ( Asys, out_idx, in_idx) 
  10988. Extract specified inputs/outputs from a system 
  10989.  
  10990. *Inputs* 
  10991.  
  10992.  Asys 
  10993.            system data structure 
  10994.  
  10995.  out_idx,in_idx 
  10996.             list of connections indices; the new     system has outputs 
  10997.            y(out_idx(ii)) and inputs u(in_idx(ii)).     May select as [] (empty 
  10998.            matrix) to specify all outputs/inputs. 
  10999.  
  11000.  *Outputs* retsys: resulting system 
  11001.  
  11002.              ____________________
  11003.   u1 ------->|                  |----> y1
  11004.    (in_idx)  |       Asys       | (out_idx)
  11005.   u2 ------->|                  |----| y2
  11006.     (deleted)-------------------- (deleted)
  11007.  
  11008.  
  11009. ΓòÉΓòÉΓòÉ 56. sysreorder ΓòÉΓòÉΓòÉ
  11010.  
  11011. Function File : pv = sysreorder( vlen, {var{list}) 
  11012.  
  11013. *Inputs* vlen=vector length, list= a subset of [1:vlen], 
  11014.  
  11015. *Outputs*  pv: a permutation vector to order elements of [1:vlen] in list to 
  11016. the end of a vector. 
  11017.  
  11018.  Used internally by sysconnect to permute vector elements to their  desired 
  11019. locations. 
  11020.  
  11021.  
  11022. ΓòÉΓòÉΓòÉ 57. sysscale ΓòÉΓòÉΓòÉ
  11023.  
  11024. Function File : sys = sysscale (sys, outscale, inscale{, outname, inname}) 
  11025. scale inputs/outputs of a system. 
  11026.  
  11027. *Inputs*   sys: structured system   outscale, inscale: constant matrices of 
  11028. appropriate dimension 
  11029.  
  11030. *Outputs* sys: resulting open loop system: 
  11031.  
  11032.       -----------    -------    -----------
  11033. u --->| inscale |--->| sys |--->| outscale |---> y
  11034.       -----------    -------    -----------
  11035.  
  11036.  If the input names and output names (each a list of strings) are not given and 
  11037. the scaling matrices  are not square, then default names will be given to the 
  11038. inputs and/or  outputs. 
  11039.  
  11040. A warning message is printed if outscale attempts to add continuous system 
  11041. outputs to discrete system outputs; otherwise yd is set appropriately in the 
  11042. returned value of sys. 
  11043.  
  11044.  
  11045. ΓòÉΓòÉΓòÉ 58. syssub ΓòÉΓòÉΓòÉ
  11046.  
  11047. Function File : sys = syssub (Gsys, Hsys) 
  11048.  returns sys = Gsys - Hsys 
  11049.  
  11050.  Method: Gsys and Hsys are connected in parallel  The input vector is connected 
  11051. to both systems; the outputs are  subtracted.  Returned system names are those 
  11052. of Gsys. 
  11053.  
  11054.           ________
  11055.      ----|  Gsys  |---
  11056. u   |    ----------  +|
  11057. -----                (_)----> y
  11058.     |     ________   -|
  11059.      ----|  Hsys  |---
  11060.           --------
  11061.  
  11062. Function File : outsys = ugain(n) 
  11063.  Creates a system with unity gain, no states.  This trivial system is sometimes 
  11064. needed to create arbitrary  complex systems from simple systems with buildssic. 
  11065. Watch out if you are forming sampled systems since "ugain"  does not contain a 
  11066. sampling period. 
  11067.  
  11068. See also: hinfdemo (MIMO H_infinty example, Boeing 707-321 aircraft model) 
  11069.  
  11070. Function File : wsys = wgt1o (vl, vh, fc) 
  11071. State space description of a first order weighting function. 
  11072.  
  11073.  Weighting function are needed by the H2/H_infinity design procedure.  These 
  11074. function are part of thye augmented plant P (see hinfdemo  for an applicattion 
  11075. example). 
  11076.  
  11077.  vl = Gain @ low frequencies 
  11078.  
  11079.  vh = Gain @ high frequencies 
  11080.  
  11081.  fc = Corner frequency (in Hz, *not* in rad/sec) 
  11082.  
  11083.  
  11084. ΓòÉΓòÉΓòÉ 58.1. Numerical Functions ΓòÉΓòÉΓòÉ
  11085.  
  11086. Function File:  are (a, b, c, opt) 
  11087. Solve the algebraic Riccati equation 
  11088.  
  11089. a' * x + x * a - x * b * x + c = 0
  11090.  
  11091. *Inputs* for identically dimensioned square matrices 
  11092.  
  11093.  a 
  11094.            nxn matrix. 
  11095.  
  11096.  b 
  11097.             nxn matrix or nxm matrix; in the latter case  b is replaced by 
  11098.            b:=b*b'. 
  11099.  
  11100.  c 
  11101.             nxn matrix or pxm matrix; in the latter case  c is replaced by 
  11102.            c:=c'*c. 
  11103.  
  11104.  opt 
  11105.            (optional argument; default = "B"): String option passed to balance 
  11106.            prior to ordered Schur decomposition. 
  11107.  
  11108.  *Outputs* x: solution of the ARE. 
  11109.  
  11110.  *Method* Laub's Schur method (IEEE Transactions on Automatic Control, 1979) is 
  11111.  applied to the appropriate Hamiltonian matrix. 
  11112.  
  11113.  Function File:  dare (a, b, c, r, opt) 
  11114.  
  11115.  Return the solution, x of the discrete-time algebraic Riccati equation 
  11116.  
  11117.   a' x a - x + a' x b (r + b' x b)^(-1) b' x a + c = 0
  11118.  
  11119.  *Inputs* 
  11120.  
  11121.  a 
  11122.            n by n. 
  11123.  
  11124.  b 
  11125.            n by m. 
  11126.  
  11127.  c 
  11128.            n by n, symmetric positive semidefinite, or p by n. In the latter 
  11129.            case c:=c'*c is used. 
  11130.  
  11131.  r 
  11132.            m by m, symmetric positive definite (invertible). 
  11133.  
  11134.  opt 
  11135.            (optional argument; default = "B"): String option passed to balance 
  11136.            prior to ordered QZ decomposition. 
  11137.  
  11138.  *Outputs* x solution of DARE. 
  11139.  
  11140.  *Method* Generalized eigenvalue approach (Van Dooren; SIAM J.  Sci. Stat. 
  11141.  Comput., Vol 2) applied  to the appropriate symplectic pencil. 
  11142.  
  11143.   See also: Ran and Rodman, "Stable Hermitian Solutions of Discrete  Algebraic 
  11144.  Riccati Equations," Mathematics of Control, Signals and  Systems, Vol 5, no 2 
  11145.  (1992)  pp 165-194. 
  11146.  
  11147.  Function File : m = dgram ( a, b) 
  11148.   Return controllability grammian of discrete time system 
  11149.  
  11150.     x(k+1) = a x(k) + b u(k)
  11151.  
  11152.  *Inputs* 
  11153.  
  11154.  a 
  11155.            n by n matrix 
  11156.  
  11157.  b 
  11158.            n by m matrix 
  11159.  
  11160.  *Outputs* m (n by n) satisfies 
  11161.  
  11162.    a m a' - m + b*b' = 0
  11163.  
  11164.  Function File: x =  dlyap (a, b) 
  11165.  Solve the discrete-time Lyapunov equation 
  11166.  
  11167.   *Inputs* 
  11168.  
  11169.  a 
  11170.              n by n matrix 
  11171.  
  11172.  b 
  11173.              Matrix: n by n, n by m, or p by n. 
  11174.  
  11175.   *Outputs*  x: matrix satisfying appropriate discrete time Lyapunov equation. 
  11176.  Options: 
  11177.  
  11178.        b is square: solve a x a' - x + b = 0 
  11179.  
  11180.        b is not square: x satisfies either 
  11181.  
  11182.                   a x a' - x + b b' = 0
  11183.  
  11184.          or 
  11185.  
  11186.              a' x a - x + b' b = 0,
  11187.  
  11188.         whichever is appropriate. 
  11189.  
  11190.  *Method*  Uses Schur decomposition method as in Kitagawa,   An Algorithm for 
  11191.  Solving the Matrix Equation X =   FXF' + S,  International Journal of Control, 
  11192.  Volume 25, Number 5, pages 745--753  (1977). 
  11193.  
  11194.  Column-by-column solution method as suggested in  Hammarling, Numerical 
  11195.  Solution of the Stable, Non-Negative  Definite Lyapunov Equation, IMA Journal 
  11196.  of Numerical Analysis, Volume  2, pages 303--323 (1982). 
  11197.  
  11198.  Function File : m = gram (a, b) 
  11199.   Return controllability grammian m of the continuous time system dx/dt = a x + 
  11200.  b u. 
  11201.  
  11202.  m satisfies a m + m a' + b b' = 0 . 
  11203.  
  11204.  Function File:  lyap (a, b, c) 
  11205.  
  11206.  Function File:  lyap (a, b) 
  11207.   Solve the Lyapunov (or Sylvester) equation via the Bartels-Stewart  algorithm 
  11208.  (Communications of the ACM, 1972). 
  11209.  
  11210.   If a, b, and c are specified, then lyap returns  the solution of the 
  11211.  Sylvester equation 
  11212.  
  11213.         a x + x b + c = 0
  11214.  
  11215.   If only (a, b) are specified, then lyap returns the  solution of the Lyapunov 
  11216.  equation 
  11217.  
  11218.         a' x + x a + b = 0
  11219.  
  11220.   If b is not square, then lyap returns the solution of either 
  11221.  
  11222.         a' x + x a + b' b = 0
  11223.  
  11224.   or 
  11225.  
  11226.         a x + x a' + b b' = 0
  11227.  
  11228.   whichever is appropriate. 
  11229.  
  11230.  Function File :  pinv ( X{,tol} ) 
  11231.  Returns the pseudoinverse of X; singular values less than tol are ignored. 
  11232.  
  11233.  Function File : x = qzval (A, B) 
  11234.  Compute generalized eigenvalues of the matrix pencil 
  11235.  
  11236.   (A - lambda B).
  11237.  
  11238.  A and B must be real matrices. 
  11239.  
  11240.  *Note* qzval is obsolete; use qz instead. 
  11241.  
  11242.  Function File :  zgfmul 
  11243.  
  11244.  Function File :  zgfslv 
  11245.  
  11246.  Function File :  zginit 
  11247.  
  11248.  Function File : retsys = zgpbal (Asys) 
  11249.  
  11250.  Function File :  zgreduce 
  11251.  
  11252.  Function File : [nonz, zer] = zgrownorm (mat, meps) 
  11253.  
  11254.  Function File : x = zgscal (f, z, n, m, p) 
  11255.  
  11256.  Function File :  zgsgiv ( ) 
  11257.  
  11258.  Function File : x = zgshsr( y) 
  11259.  Used internally by tzero. Minimal argument checking performed. 
  11260.  
  11261.  Details involving major subroutines: 
  11262.  
  11263.  zgpbal 
  11264.            Implementation of zero computation generalized eigenvalue problem 
  11265.            balancing method.  zgpbal computes a state/input/output weighting 
  11266.            that attempts to  reduced the range of the magnitudes of the nonzero 
  11267.            elements of [a,b,c,d]  The weighting uses scalar multiplication by 
  11268.            powers of 2, so no roundoff  will occur. 
  11269.  
  11270.             zgpbal should be followed by zgpred 
  11271.  
  11272.  zgreduce 
  11273.            Implementation of procedure REDUCE in (Emami-Naeini and Van Dooren, 
  11274.            Automatica, 1982). 
  11275.  
  11276.  zgrownorm 
  11277.             Returns nonz = number of rows of mat whose two norm exceeds 
  11278.            meps, zer = number of rows of mat whose two norm     is less than 
  11279.            meps 
  11280.  
  11281.  zgscal 
  11282.            Generalized conjugate gradient iteration to  solve zero-computation 
  11283.            generalized eigenvalue problem balancing equation  fx=z;  called by 
  11284.            zgepbal 
  11285.  
  11286.  zgsgiv 
  11287.            apply givens rotation c,s to column vector a,b 
  11288.  
  11289.  zgshsr 
  11290.            Apply Householder vector based on e^(m) (all ones) to (column 
  11291.            vector) y.  Called by zgfslv. 
  11292.  
  11293.  References: 
  11294.  
  11295.  *ZGEP* 
  11296.             Hodel, "Computation of Zeros with Balancing," 1992, Linear Algebra 
  11297.            and its Applications 
  11298.  
  11299.  **Generalized CG** 
  11300.             Golub and Van Loan, "Matrix Computations, 2nd ed" 1989 
  11301.  
  11302.  
  11303. ΓòÉΓòÉΓòÉ 58.2. System Analysis-Properties ΓòÉΓòÉΓòÉ
  11304.  
  11305. Function File :  analdemo ( ) 
  11306.  Octave Controls toolbox demo: State Space analysis demo 
  11307.  
  11308. Function File: [n, m, p] = abcddim (a, b, c, d) 
  11309. Check for compatibility of the dimensions of the matrices defining the linear 
  11310. system [A, B, C, D] corresponding to 
  11311.  
  11312. dx/dt = a x + b u
  11313. y = c x + d u
  11314.  
  11315. or a similar discrete-time system. 
  11316.  
  11317. If the matrices are compatibly dimensioned, then abcddim returns 
  11318.  
  11319.  n 
  11320.            The number of system states. 
  11321.  
  11322.  m 
  11323.            The number of system inputs. 
  11324.  
  11325.  p 
  11326.            The number of system outputs. 
  11327.  
  11328.  Otherwise abcddim returns n = m = p = -1. 
  11329.  
  11330.  Note: n = 0 (pure gain block) is returned without warning. 
  11331.  
  11332.  See also: is_abcd 
  11333.  
  11334.  Function File : [y, my, ny] = abcddims (x) 
  11335.  
  11336.  Used internally in abcddim.  If x is a zero-size matrix, both dimensions are 
  11337.  set to 0 in y. my and ny are the row and column dimensions of the result. 
  11338.  
  11339.  Function File : Qs = ctrb(sys {, b}) 
  11340.  
  11341.  Function File : Qs = ctrb(A, B) 
  11342.  Build controllability matrix 
  11343.  
  11344.                2       n-1
  11345.   Qs = [ B AB A B ... A   B ]
  11346.  
  11347.   of a system data structure or the pair (A, B). 
  11348.  
  11349.  *Note* ctrb forms the controllability matrix.     The numerical properties of 
  11350.  is_controllable     are much better for controllability tests. 
  11351.  
  11352.  Function File : retval = h2norm(sys) 
  11353.  Computes the H2 norm of a system data structure (continuous time only) 
  11354.  
  11355.  Reference:  Doyle, Glover, Khargonekar, Francis, ``State Space Solutions to 
  11356.  Standard  H2 and Hinf Control Problems", IEEE TAC August 1989 
  11357.  
  11358.  Function File : [g, gmin, gmax] = hinfnorm(sys{, tol, gmin, gmax, ptol}) 
  11359.   Computes the H infinity norm of a system data structure. 
  11360.  
  11361.  *Inputs* 
  11362.  
  11363.  sys 
  11364.            system data structure 
  11365.  
  11366.  tol 
  11367.            H infinity norm search tolerance (default: 0.001) 
  11368.  
  11369.  gmin 
  11370.            minimum value for norm search (default: 1e-9) 
  11371.  
  11372.  gmax 
  11373.            maximum value for norm search (default: 1e+9) 
  11374.  
  11375.  ptol 
  11376.             pole tolerance: 
  11377.  
  11378.                if sys is continuous, poles with |real(pole)| < ptol*||H|| (H 
  11379.                 is appropriate Hamiltonian) are considered to be on the 
  11380.                 imaginary axis. 
  11381.  
  11382.                if sys is discrete, poles with |abs(pole)-1| < ptol*||[s1,s2]|| 
  11383.                 (appropriate symplectic pencil) are considered to be on the 
  11384.                 unit circle 
  11385.  
  11386.                Default: 1e-9 
  11387.  
  11388.  *Outputs* 
  11389.  
  11390.  g 
  11391.            Computed gain, within tol of actual gain.  g is returned as Inf if 
  11392.            the system is unstable. 
  11393.  
  11394.  gmin, gmax 
  11395.            Actual system gain lies in the interval [gmin, gmax] 
  11396.  
  11397.   References:  Doyle, Glover, Khargonekar, Francis, "State space solutions to 
  11398.  standard   H2 and Hinf control problems", IEEE TAC August 1989  Iglesias and 
  11399.  Glover, "State-Space approach to discrete-time Hinf control,"   Int. J. 
  11400.  Control, vol 54, #5, 1991  Zhou, Doyle, Glover, "Robust and Optimal Control," 
  11401.  Prentice-Hall, 1996  $Revision: 1.9 $ 
  11402.  
  11403.  Function File : Qb = obsv (sys{, c}) 
  11404.  Build observability matrix 
  11405.  
  11406.        | C        |
  11407.        | CA       |
  11408.   Qb = | CA^2     |
  11409.        | ...      |
  11410.        | CA^(n-1) |
  11411.  
  11412.  of a system data structure or the pair (A, C). 
  11413.  
  11414.  Note: obsv() forms the observability matrix. 
  11415.  
  11416.      The numerical properties of is_observable()     are much better for 
  11417.  observability tests. 
  11418.  
  11419.  Function File : [zer, pol]= pzmap (sys) 
  11420.   Plots the zeros and poles of a system in the complex plane. *Inputs*  sys 
  11421.  system data structure 
  11422.  
  11423.  *Outputs* if omitted, the poles and zeros are plotted on the screen. 
  11424.  otherwise, pol, zer are returned as the system poles and zeros.      (see 
  11425.  sys2zp for a preferable function call) 
  11426.  
  11427.  Function File: outputs =  synKnames (inputs) 
  11428.  Return controller signal names based in plant signal names and dimensions 
  11429.  
  11430.  Function File : retval = is_abcd( a{, b, c, d}) 
  11431.   Returns retval = 1 if the dimensions of a, b, c, d  are compatible, otherwise 
  11432.  retval = 0 with an appropriate diagnostic message printed to the screen. 
  11433.  
  11434.  Function File : [retval, U] = is_controllable (sys{, tol}) 
  11435.  
  11436.  Function File : [retval, U] = is_controllable (a{, b ,tol}) 
  11437.  Logical check for system controllability. 
  11438.  
  11439.  *Inputs* 
  11440.  
  11441.  sys 
  11442.            system data structure 
  11443.  
  11444.  a, b 
  11445.            n by n, n by m matrices, respectively 
  11446.  
  11447.  tol 
  11448.            optional roundoff paramter.  default value: 10*eps 
  11449.  
  11450.  *Outputs* 
  11451.  
  11452.  retval 
  11453.            Logical flag; returns true (1) if the system sys or the pair (a,b) 
  11454.            is controllable, whichever was passed as input arguments. 
  11455.  
  11456.  U 
  11457.             U is an orthogonal basis of the controllable subspace. 
  11458.  
  11459.  *Method* Controllability is determined by applying Arnoldi iteration with 
  11460.  complete re-orthogonalization to obtain an orthogonal basis of the Krylov 
  11461.  subspace 
  11462.  
  11463.   span ([b,a*b,...,a^{n-1}*b]).
  11464.  
  11465.  The Arnoldi iteration is executed with krylov if the system has a single 
  11466.  input; otherwise a block Arnoldi iteration is performed with krylovb. 
  11467.  
  11468.  *See also* is_observable, is_stabilizable, is_detectable,     krylov, krylovb 
  11469.  
  11470.  Function File : [retval, U] = is_detectable (a, c{, tol}) 
  11471.  
  11472.  Function File : [retval, U] = is_detectable (sys{, tol}) 
  11473.  Test for detactability (observability of unstable modes) of (a,c). 
  11474.  
  11475.   Returns 1 if the system a or the pair (a,c)is  detectable, 0 if not. 
  11476.  
  11477.  *See* is_stabilizable for detailed description of arguments and computational 
  11478.  method. 
  11479.  
  11480.  Function File : [retval, dgkf_struct ] = is_dgkf (Asys, nu, ny, tol ) 
  11481.   Determine whether a continuous time state space system meets  assumptions of 
  11482.  DGKF algorithm.  Partitions system into: 
  11483.  
  11484.   [dx/dt] = [A  | Bw  Bu  ][w]
  11485.   [ z   ]   [Cz | Dzw Dzu ][u]
  11486.   [ y   ]   [Cy | Dyw Dyu ]
  11487.  
  11488.  or similar discrete-time system. If necessary, orthogonal transformations Qw, 
  11489.  Qz and nonsingular  transformations Ru, Ry are applied to respective vectors 
  11490.  w, z, u, y in order to satisfy DGKF assumptions. Loop shifting is used if Dyu 
  11491.  block is nonzero. 
  11492.  
  11493.  *Inputs* 
  11494.  
  11495.  Asys 
  11496.            system data structure 
  11497.  
  11498.  nu 
  11499.            number of controlled inputs 
  11500.  
  11501.  ny 
  11502.             number of measured outputs 
  11503.  
  11504.  tol 
  11505.             threshhold for 0.  Default: 200eps 
  11506.  
  11507.  *Outputs* 
  11508.  
  11509.  retval 
  11510.             true(1) if system passes check, false(0) otherwise 
  11511.  
  11512.  dgkf_struct 
  11513.             data structure of is_dgkf results.  Entries: 
  11514.  
  11515.            nw, nz 
  11516.                            dimensions of w, z 
  11517.  
  11518.            A 
  11519.                            system A matrix 
  11520.  
  11521.            Bw 
  11522.                            (n x nw) Qw-transformed disturbance input matrix 
  11523.  
  11524.            Bu 
  11525.                            (n x nu) Ru-transformed controlled input matrix; 
  11526.  
  11527.                                *Note* B = [Bw Bu] 
  11528.  
  11529.            Cz 
  11530.                            (nz x n) Qz-transformed error output matrix 
  11531.  
  11532.            Cy 
  11533.                            (ny x n) Ry-transformed measured output matrix 
  11534.  
  11535.                                *Note* C = [Cz; Cy] 
  11536.  
  11537.            Dzu, Dyw 
  11538.                            off-diagonal blocks of transformed D matrix that 
  11539.                           enter z, y from u, w respectively 
  11540.  
  11541.            Ru 
  11542.                            controlled input transformation matrix 
  11543.  
  11544.            Ry 
  11545.                            observed output transformation matrix 
  11546.  
  11547.            Dyu_nz 
  11548.                            nonzero if the Dyu block is nonzero. 
  11549.  
  11550.            Dyu 
  11551.                            untransformed Dyu block 
  11552.  
  11553.            dflg 
  11554.                            nonzero if the system is discrete-time 
  11555.  
  11556.  is_dgkf exits with an error if the system is mixed discrete/continuous 
  11557.  
  11558.  *References* 
  11559.  
  11560.  *[1]* 
  11561.             Doyle, Glover, Khargonekar, Francis, "State Space Solutions    to 
  11562.            Standard H2 and Hinf Control Problems," IEEE TAC August 1989 
  11563.  
  11564.  *[2]* 
  11565.             Maciejowksi, J.M.: "Multivariable feedback design," 
  11566.  
  11567.  Function File : retval = is_digital ( sys) 
  11568.  Return nonzero if system is digital; Exits with an error of sys is a mixed 
  11569.  (continuous and discrete) system 
  11570.  
  11571.  Function File : [retval,U] = is_observable (a, c{,tol}) 
  11572.  
  11573.  Function File : [retval,U] = is_observable (sys{, tol}) 
  11574.  Logical check for system observability.  Returns 1 if the system sys or the 
  11575.  pair (a,c) is  observable, 0 if not. 
  11576.  
  11577.  *See* is_controllable for detailed description of arguments and default 
  11578.  values. 
  11579.  
  11580.  Function File : retval = is_sample (Ts) 
  11581.   return true if Ts is a legal sampling time  (real,scalar, > 0) 
  11582.  
  11583.  Function File : retval = is_siso (sys) 
  11584.  return nonzero if the system data structure sys is single-input, 
  11585.  single-output. 
  11586.  
  11587.  Function File : [retval, U] = is_stabilizable (sys{, tol}) 
  11588.  
  11589.  Function File : [retval, U] = is_stabilizable (a{, b ,tol}) 
  11590.  Logical check for system stabilizability (i.e., all unstable modes are 
  11591.  controllable). 
  11592.  
  11593.  *See* is_controllable for description of inputs, outputs. Test for 
  11594.  stabilizability is performed via an ordered Schur decomposition that reveals 
  11595.  the unstable subspace of the system A matrix. 
  11596.  
  11597.  Function File : flg = is_signal_list (mylist) 
  11598.  returns true if mylist is a list of individual strings (legal for input to 
  11599.  syssetsignals). 
  11600.  
  11601.  Function File : retval = is_stable (a{,tol,dflg}) 
  11602.  
  11603.  Function File : retval = is_stable (sys{,tol}) 
  11604.   Returns retval = 1 if the matrix a or the system sys is stable, or 0 if not. 
  11605.  
  11606.  *Inputs* 
  11607.  
  11608.  tol 
  11609.            is a roundoff paramter, set to 200*eps if omitted. 
  11610.  
  11611.  dflg 
  11612.            Digital system flag (not required for system data structure): 
  11613.  
  11614.            dflg != 0 
  11615.                           stable if eig(a) in unit circle 
  11616.  
  11617.            dflg == 0 
  11618.                           stable if eig(a) in open LHP (default) 
  11619.  
  11620.  
  11621. ΓòÉΓòÉΓòÉ 58.3. System Analysis-Time Domain ΓòÉΓòÉΓòÉ
  11622.  
  11623. Function File : dsys = c2d (sys{, opt, T}) 
  11624.  
  11625. Function File : dsys = c2d (sys{, T}) 
  11626.  
  11627. *Inputs* 
  11628.  
  11629.  sys 
  11630.             system data structure (may have both continuous time and discrete 
  11631.            time subsystems) 
  11632.  
  11633.  opt 
  11634.            string argument; conversion option (optional argument; may be 
  11635.            omitted as shown above) 
  11636.  
  11637.            "ex" 
  11638.                           use the matrix exponential (default) 
  11639.  
  11640.            "bi" 
  11641.                           use the bilinear transformation 
  11642.  
  11643.                           2(z-1)
  11644.                       s = -----
  11645.                           T(z+1)
  11646.  
  11647.            FIXME: This option exits with an error if sys is not purely 
  11648.            continuous. (The ex option can handle mixed systems.) 
  11649.  
  11650.  T 
  11651.            sampling time; required if sys is purely continuous. 
  11652.  
  11653.            *Note* If the 2nd argument is not a string, c2d assumes that the 2nd 
  11654.            argument is T and performs appropriate argument checks. 
  11655.  
  11656.  *Outputs* dsys discrete time equivalent via zero-order hold, sample each T 
  11657.  sec. 
  11658.  
  11659.  converts the system data structure describing 
  11660.  
  11661.   .
  11662.   x = Ac x + Bc u
  11663.  
  11664.  into a discrete time equivalent model 
  11665.  
  11666.   x[n+1] = Ad x[n] + Bd u[n]
  11667.  
  11668.  via the matrix exponential or bilinear transform 
  11669.  
  11670.  *Note* This function adds the suffix  _d to the names of the new discrete 
  11671.  states. 
  11672.  
  11673.  Function File : csys = d2c (sys{,tol}) 
  11674.  
  11675.  Function File : csys = d2c (sys, opt) 
  11676.  Convert discrete (sub)system to a purely continuous system.  Sampling time 
  11677.  used is sysgettsam(sys) 
  11678.  
  11679.  *Inputs* 
  11680.  
  11681.  sys 
  11682.             system data structure with discrete components 
  11683.  
  11684.  tol 
  11685.            Scalar value.  tolerance for convergence of default "log" option 
  11686.            (see below) 
  11687.  
  11688.  opt 
  11689.             conversion option.  Choose from: 
  11690.  
  11691.            "log" 
  11692.                            (default) Conversion is performed via a matrix 
  11693.                           logarithm. Due to some problems with this 
  11694.                           computation, it is followed by a steepest descent 
  11695.                           algorithm to identify continuous time A, B, to get a 
  11696.                           better fit to the original data. 
  11697.  
  11698.                           If called as d2c(sys,tol), tol=positive scalar, 
  11699.                           the "log" option is used.  The default value for tol 
  11700.                           is     1e-8. 
  11701.  
  11702.            "bi" 
  11703.                            Conversion is performed via bilinear transform z = 
  11704.                           (1 + s T / 2)/(1 - s T / 2) where T is the system 
  11705.                           sampling time (see sysgettsam). 
  11706.  
  11707.                           FIXME: bilinear option exits with an error if sys is 
  11708.                           not purely discrete 
  11709.  
  11710.  *Outputs* csys continuous time system (same dimensions and signal names as in 
  11711.  sys). 
  11712.  
  11713.  Function File : [dsys, fidx] = dmr2d (sys, idx, sprefix, Ts2 {,cuflg}) 
  11714.   convert a multirate digital system to a single rate digital system  states 
  11715.  specified by idx, sprefix are sampled at Ts2, all  others are assumed sampled 
  11716.  at Ts1 = sysgettsam(sys). 
  11717.  
  11718.  *Inputs* 
  11719.  
  11720.  sys 
  11721.            discrete time system; dmr2d exits with an error if sys is not 
  11722.            discrete 
  11723.  
  11724.  idx 
  11725.            list of states with sampling time sysgettsam(sys) (may be empty) 
  11726.  
  11727.  sprefix 
  11728.            list of string prefixes of states with sampling time sysgettsam(sys) 
  11729.            (may be empty) 
  11730.  
  11731.  Ts2 
  11732.            sampling time of states not specified by idx, sprefix must be an 
  11733.            integer multiple of sysgettsam(sys) 
  11734.  
  11735.  cuflg 
  11736.            "constant u flag" if cuflg is nonzero then the system inputs are 
  11737.            assumed to be constant over the revised sampling interval Ts2. 
  11738.            Otherwise, since the inputs can change during the interval     t in 
  11739.            [k Ts2, (k+1) Ts2], an additional set of inputs is     included in 
  11740.            the revised B matrix so that these intersample inputs     may be 
  11741.            included in the single-rate system.     default  cuflg = 1. 
  11742.  
  11743.  *Outputs* 
  11744.  
  11745.  dsys 
  11746.             equivalent discrete time system with sampling time Ts2. 
  11747.  
  11748.                 The sampling time of sys is updated to Ts2. 
  11749.  
  11750.                 if cuflg=0 then a set of additional inputs is added to      the 
  11751.            system with suffixes _d1, ..., _dn to indicate their      delay from 
  11752.            the starting time k Ts2, i.e.      u = [u_1; u_1_d1; ..., u_1_dn] 
  11753.            where u_1_dk is the input        k*Ts1 units of time after u_1 is 
  11754.            sampled. (Ts1 is        the original sampling time of discrete time 
  11755.            sys and        Ts2 = (n+1)*Ts1) 
  11756.  
  11757.  fidx 
  11758.            indices of "formerly fast" states specified by idx and sprefix; 
  11759.            these states are updated to the new (slower) sampling interval Ts2. 
  11760.  
  11761.  *WARNING* Not thoroughly tested yet; especially when cuflg == 0. 
  11762.  
  11763.  Function File :  damp(p{, tsam}) 
  11764.     Displays eigenvalues, natural frequencies and damping ratios    of the 
  11765.  eigenvalues of a matrix p or the A-matrix of a    system p, respectively. 
  11766.  If p is a system, tsam must not be specified.    If p is a matrix and tsam is 
  11767.  specified, eigenvalues    of p are assumed to be in z-domain. 
  11768.  
  11769.  See also: eig 
  11770.  
  11771.  Function File : gm = dcgain(sys{, tol}) 
  11772.     Returns dc-gain matrix. If dc-gain is infinite    an empty matrix is 
  11773.  returned.    The argument tol is an optional tolerance for the condition 
  11774.  number of A-Matrix in sys (default tol = 1.0e-10) 
  11775.  
  11776.  Function File : [y, t] = impulse (sys{, inp,tstop, n}) 
  11777.  Impulse response for a linear system.     The system can be discrete or 
  11778.  multivariable (or both). If no output arguments are specified, impulse 
  11779.  produces a plot or the step response data for system sys. 
  11780.  
  11781.  *Inputs* 
  11782.  
  11783.  sys 
  11784.            System data structure. 
  11785.  
  11786.  inp 
  11787.            Index of input being excited 
  11788.  
  11789.  tstop 
  11790.             The argument tstop (scalar value) denotes the time when the 
  11791.            simulation should end. 
  11792.  
  11793.  n 
  11794.            the number of data values. 
  11795.  
  11796.             Both parameters tstop and n can be omitted and will be  computed 
  11797.            from the eigenvalues of the A-Matrix. 
  11798.  
  11799.  *Outputs* y, t: impulse response 
  11800.  
  11801.  Function File : [y, t] = step (sys{, inp,tstop, n}) 
  11802.  Step response of a linear system; calling protocol is identical to impulse. 
  11803.  
  11804.  Function File :  stepimp ( ) 
  11805.  Used internally in impulse, step. 
  11806.  
  11807.  
  11808. ΓòÉΓòÉΓòÉ 58.4. System Analysis-Frequency Domain ΓòÉΓòÉΓòÉ
  11809.  
  11810. *Demonstration/tutorial script* 
  11811.  
  11812. Function File :  frdemo ( ) 
  11813.  
  11814. Function File : [mag, phase, w] = bode(sys{,w, out_idx, in_idx}) 
  11815. If no output arguments are given: produce Bode plots of a system; otherwise, 
  11816. compute the frequency response of a system data structure 
  11817.  
  11818. *Inputs* 
  11819.  
  11820.  sys 
  11821.             a system data structure (must be either purely continuous or 
  11822.            discrete;      see is_digital) 
  11823.  
  11824.  w 
  11825.             frequency values for evaluation. 
  11826.  
  11827.            if sys is continuous, then bode evaluates G(jw) where G(s) is the 
  11828.            system transfer function. 
  11829.  
  11830.            if sys is discrete, then bode evaluates G(exp(jwT)), where 
  11831.  
  11832.                T=sysgettsam(sys) (the system sampling time) and 
  11833.  
  11834.                G(z) is the system transfer function. 
  11835.  
  11836.            *Default* the default frequency range is selected as follows: (These 
  11837.            steps are NOT performed if w is specified) 
  11838.  
  11839.              1. via routine bodquist, isolate all poles and zeros away from w=0 
  11840.                 (jw=0 or exp(jwT)=1) and select the frequency range based on 
  11841.                 the breakpoint locations of the frequencies. 
  11842.  
  11843.              2. if sys is discrete time, the frequency range is limited 
  11844.                 to jwT in [0,2 pi /T] 
  11845.  
  11846.              3. A "smoothing" routine is used to ensure that the plot phase 
  11847.                 does        not change excessively from point to point and that 
  11848.                 singular        points (e.g., crossovers from +/- 180) are 
  11849.                 accurately shown. 
  11850.  
  11851.  out_idx, in_idx 
  11852.             the indices of the output(s) and input(s) to be used in    the 
  11853.            frequency response; see sysprune. 
  11854.  
  11855.  *Outputs* 
  11856.  
  11857.  mag, phase 
  11858.             the magnitude and phase of the frequency response     G(jw) or 
  11859.            G(exp(jwT)) at the selected frequency values. 
  11860.  
  11861.  w 
  11862.            the vector of frequency values used 
  11863.  
  11864.  *Notes* 
  11865.  
  11866.    1. If no output arguments are given, e.g., 
  11867.  
  11868.             bode(sys);
  11869.  
  11870.       bode plots the results to the screen.  Descriptive labels are 
  11871.       automatically placed. 
  11872.  
  11873.       Failure to include a concluding semicolon will yield some garbage being 
  11874.       printed to the screen (ans = []). 
  11875.  
  11876.    2. If the requested plot is for an MIMO system, mag is set to  ||G(jw)|| or 
  11877.       ||G(exp(jwT))|| and phase information is not computed. 
  11878.  
  11879.  Function File : [wmin, wmax] = bode_bounds (zer, pol, dflg{, tsam }) 
  11880.  Get default range of frequencies based on cutoff frequencies of system poles 
  11881.  and zeros. Frequency range is the interval [10^wmin,10^wmax] 
  11882.  
  11883.  Used internally in freqresp (bode, nyquist) 
  11884.  
  11885.  Function File : [f, w] = bodquist (sys, w, out_idx, in_idx) 
  11886.   used internally by bode, nyquist; compute system frequency response. 
  11887.  
  11888.  *Inputs* 
  11889.  
  11890.  sys 
  11891.            input system structure 
  11892.  
  11893.  w 
  11894.            range of frequencies; empty if user wants default 
  11895.  
  11896.  out_idx 
  11897.            list of outputs; empty if user wants all 
  11898.  
  11899.  in_idx 
  11900.            list of inputs; empty if user wants all 
  11901.  
  11902.  rname 
  11903.            name of routine that called bodquist ("bode" or "nyquist") 
  11904.  
  11905.  *Outputs* 
  11906.  
  11907.  w 
  11908.             list of frequencies 
  11909.  
  11910.  f 
  11911.             frequency response of sys; f(ii) = f(omega(ii)) 
  11912.  
  11913.  *Note* bodquist could easily be incorporated into a Nichols plot function; 
  11914.  this is in a "to do" list. 
  11915.  
  11916.  Function File : retval = freqchkw ( w ) 
  11917.  Used by freqresp to check that input frequency vector w is legal. Returns 
  11918.  boolean value. 
  11919.  
  11920.  Function File : out = freqresp (sys,USEW{,w}); 
  11921.   Frequency response function - used internally by bode, nyquist.  minimal 
  11922.  argument checking; "do not attempt to do this at home" 
  11923.  
  11924.  *Inputs* 
  11925.  
  11926.  sys 
  11927.            system data structure 
  11928.  
  11929.  USEW 
  11930.            returned by freqchkw 
  11931.  
  11932.  optional 
  11933.             must be present if USEW is true (nonzero) 
  11934.  
  11935.  *Outputs* 
  11936.  
  11937.  out 
  11938.            vector of finite G(j*w) entries (or ||G(j*w)|| for MIMO) 
  11939.  
  11940.  w 
  11941.            vector of corresponding frequencies 
  11942.  
  11943.  Function File : out = ltifr (A, B, w) 
  11944.  
  11945.  Function File : out = ltifr (sys, w) 
  11946.  Linear time invariant frequency response of single input systems *Inputs* 
  11947.  
  11948.  A, B 
  11949.            coefficient matrices of dx/dt = A x + B u 
  11950.  
  11951.  sys 
  11952.             system data structure 
  11953.  
  11954.  w 
  11955.             vector of frequencies 
  11956.  
  11957.  *Outputs* out 
  11958.  
  11959.                              -1
  11960.               G(s) = (jw I-A) B
  11961.  
  11962.  for complex frequencies s = jw. 
  11963.  
  11964.  Function File : [realp, imagp, w] = nyquist (sys{, w, out_idx, in_idx, atol}) 
  11965.  
  11966.  Function File :  nyquist (sys{, w, out_idx, in_idx, atol}) 
  11967.  Produce Nyquist plots of a system; if no output arguments are given, Nyquist 
  11968.  plot is printed to the screen. 
  11969.  
  11970.  Arguments are identical to bode with exceptions as noted below: 
  11971.  
  11972.  *Inputs* (pass as empty to get default values) 
  11973.  
  11974.  atol 
  11975.            for interactive nyquist plots: atol is a change-in-slope tolerance 
  11976.            for the of asymptotes (default = 0; 1e-2 is a good choice).  This 
  11977.            allows the user to ``zoom in'' on portions of the Nyquist plot too 
  11978.            small to be seen with large asymptotes. 
  11979.  
  11980.  *Outputs* 
  11981.  
  11982.  realp, imagp 
  11983.            the real and imaginary parts of the frequency response     G(jw) or 
  11984.            G(exp(jwT)) at the selected frequency values. 
  11985.  
  11986.  w 
  11987.             the vector of frequency values used 
  11988.  
  11989.   If no output arguments are given, nyquist plots the results to the screen. 
  11990.  If atol != 0 and asymptotes are detected then the user is asked 
  11991.  interactively if they wish to zoom in (remove asymptotes)  Descriptive labels 
  11992.  are automatically placed. 
  11993.  
  11994.   Note: if the requested plot is for an MIMO system, a warning message is 
  11995.  presented; the returned information is of the magnitude  ||G(jw)|| or 
  11996.  ||G(exp(jwT))|| only; phase information is not computed. 
  11997.  
  11998.  Function File:  tzero (a, b, c, d{, opt}) 
  11999.  
  12000.  Function File:  tzero (sys{,opt}) 
  12001.   Compute transmission zeros of a continuous 
  12002.  
  12003.   .
  12004.   x = Ax + Bu
  12005.   y = Cx + Du
  12006.  
  12007.  or discrete 
  12008.  
  12009.   x(k+1) = A x(k) + B u(k)
  12010.   y(k)   = C x(k) + D u(k)
  12011.  
  12012.  system. *Outputs* 
  12013.  
  12014.  zer 
  12015.             transmission zeros of the system 
  12016.  
  12017.  gain 
  12018.            leading coefficient (pole-zero form) of SISO transfer function 
  12019.            returns gain=0 if system is multivariable 
  12020.  
  12021.  *References* 
  12022.  
  12023.    1. Emami-Naeini and Van Dooren, Automatica, 1982. 
  12024.  
  12025.    2. Hodel, "Computation of Zeros with Balancing," 1992 Lin. Alg. Appl. 
  12026.  
  12027.  Function File : zr = tzero2 (a, b, c, d, bal) 
  12028.  Compute the transmission zeros of a, b, c, d. 
  12029.  
  12030.  bal = balancing option (see balance); default is "B". 
  12031.  
  12032.  Needs to incorporate mvzero algorithm to isolate finite zeros; use tzero 
  12033.  instead. 
  12034.  
  12035.  
  12036. ΓòÉΓòÉΓòÉ 58.5. Controller Design ΓòÉΓòÉΓòÉ
  12037.  
  12038. Function File :  dgkfdemo ( ) 
  12039.  Octave Controls toolbox demo: H2/Hinfinity options demos 
  12040.  
  12041. Function File :  hinfdemo ( ) 
  12042. Non-trivial H_infinity design demo. 
  12043.  
  12044. H_infinity optimal controller for the jet707 plant; Linearized state space 
  12045. model of a Boeing 707-321 aircraft at v=80m/s. (M = 0.26, Ga0 = -3 deg, alpha0 
  12046. = 4 deg, kappa = 50 deg) inputs:  (1) thrust  and (2) elevator angle outputs: 
  12047. (1) airspeed and (2) pitch angle 
  12048.  
  12049. The optimal controller minimizes the H_infinity norm of the augmented plant P 
  12050. (mixed-sensitivity problem): 
  12051.  
  12052.  w
  12053.   1 -----------+
  12054.                |                   +----+
  12055.            +---------------------->| W1 |----> z1
  12056.  w         |   |                   +----+
  12057.   2 ------------------------+
  12058.            |   |            |
  12059.            |   v   +----+   v      +----+
  12060.         +--*-->o-->| G  |-->o--*-->| W2 |---> z2
  12061.         |          +----+      |   +----+
  12062.         |                      |
  12063.         ^                      v
  12064.          u (from                 y (to K)
  12065.            controller
  12066.            K)
  12067.  
  12068. +    +           +    +
  12069. | z  |           | w  |
  12070. |  1 |           |  1 |
  12071. | z  | = [ P ] * | w  |
  12072. |  2 |           |  2 |
  12073. | y  |           | u  |
  12074. +    +           +    +
  12075.  
  12076. Function File: [l, m, p, e] = dlqe (a, g, c, sigw, sigv, z) 
  12077. Construct the linear quadratic estimator (Kalman filter) for the discrete time 
  12078. system 
  12079.  
  12080. x[k+1] = A x[k] + B u[k] + G w[k]
  12081.   y[k] = C x[k] + D u[k] + w[k]
  12082.  
  12083. where w, v are zero-mean gaussian noise processes with respective intensities 
  12084. sigw = cov (w, w) and sigv = cov (v, v). 
  12085.  
  12086. If specified, z is cov (w, v).  Otherwise cov (w, v) = 0. 
  12087.  
  12088. The observer structure is 
  12089.  
  12090. z[k+1] = A z[k] + B u[k] + k (y[k] - C z[k] - D u[k])
  12091.  
  12092. The following values are returned: 
  12093.  
  12094.  l 
  12095.            The observer gain, (a - alc). is stable. 
  12096.  
  12097.  m 
  12098.            The Riccati equation solution. 
  12099.  
  12100.  p 
  12101.            The estimate error covariance after the measurement update. 
  12102.  
  12103.  e 
  12104.            The closed loop poles of (a - alc). 
  12105.  
  12106.  Function File: [k, p, e] = dlqr (a, b, q, r, z) 
  12107.  Construct the linear quadratic regulator for the discrete time system 
  12108.  
  12109.   x[k+1] = A x[k] + B u[k]
  12110.  
  12111.  to minimize the cost functional 
  12112.  
  12113.   J = Sum (x' Q x + u' R u)
  12114.  
  12115.  z omitted or 
  12116.  
  12117.   J = Sum (x' Q x + u' R u + 2 x' Z u)
  12118.  
  12119.  z included. 
  12120.  
  12121.  The following values are returned: 
  12122.  
  12123.  k 
  12124.            The state feedback gain, (a - bk) is stable. 
  12125.  
  12126.  p 
  12127.            The solution of algebraic Riccati equation. 
  12128.  
  12129.  e 
  12130.            The closed loop poles of (a - bk). 
  12131.  
  12132.  *References* 
  12133.  
  12134.    1. Anderson and Moore, Optimal Control: Linear Quadratic Methods, 
  12135.       Prentice-Hall, 1990, pp. 56-58 
  12136.  
  12137.    2. Kuo, Digital Control Systems, Harcourt Brace Jovanovich, 1992,    section 
  12138.       11-5-2. 
  12139.  
  12140.  Function File : [K, gain, Kc, Kf, Pc, Pf] = h2syn(Asys, nu, ny, tol) 
  12141.   Design H2 optimal controller per procedure in  Doyle, Glover, Khargonekar, 
  12142.  Francis, "State Space Solutions to Standard  H2 and Hinf Control Problems", 
  12143.  IEEE TAC August 1989 
  12144.  
  12145.  *Inputs* input system is passed as either 
  12146.  
  12147.  Asys 
  12148.            system data structure (see ss2sys, sys2ss) 
  12149.  
  12150.                controller is implemented for continuous time systems 
  12151.  
  12152.                controller is NOT implemented for discrete time systems 
  12153.  
  12154.  nu 
  12155.            number of controlled inputs 
  12156.  
  12157.  ny 
  12158.            number of measured outputs 
  12159.  
  12160.  tol 
  12161.            threshhold for 0.  Default: 200*eps 
  12162.  
  12163.  *Outputs* 
  12164.  
  12165.  K 
  12166.            system controller 
  12167.  
  12168.  gain 
  12169.            optimal closed loop gain 
  12170.  
  12171.  Kc 
  12172.            full information control (packed) 
  12173.  
  12174.  Kf 
  12175.            state estimator (packed) 
  12176.  
  12177.  Pc 
  12178.            ARE solution matrix for regulator subproblem 
  12179.  
  12180.  Pf 
  12181.            ARE solution matrix for filter subproblem 
  12182.  
  12183.  Function File : K = hinf_ctr(dgs, F, H, Z, g) 
  12184.  Called by hinfsyn to compute the H_inf optimal controller. 
  12185.  
  12186.  *Inputs* 
  12187.  
  12188.  dgs 
  12189.            data structure returned by is_dgkf 
  12190.  
  12191.  F, H 
  12192.            feedback and filter gain (not partitioned) 
  12193.  
  12194.  g 
  12195.            final gamma value 
  12196.  
  12197.  *Outputs* controller K (system data structure) 
  12198.  
  12199.  Do not attempt to use this at home; no argument checking performed. 
  12200.  
  12201.  Function File : [K, g, GW, Xinf, Yinf] = hinfsyn(Asys, nu, ny, gmin, gmax, 
  12202.  gtol{, ptol, tol}) 
  12203.  
  12204.  *Inputs* input system is passed as either 
  12205.  
  12206.  Asys 
  12207.            system data structure (see ss2sys, sys2ss) 
  12208.  
  12209.                controller is implemented for continuous time systems 
  12210.  
  12211.                controller is NOT implemented for discrete time systems  (see 
  12212.                 bilinear transforms in c2d, d2c) 
  12213.  
  12214.  nu 
  12215.            number of controlled inputs 
  12216.  
  12217.  ny 
  12218.            number of measured outputs 
  12219.  
  12220.  gmin 
  12221.            initial lower bound on H-infinity optimal gain 
  12222.  
  12223.  gmax 
  12224.            initial upper bound on H-infinity optimal gain 
  12225.  
  12226.  gtol 
  12227.            gain threshhold.  Routine quits when gmax/gmin < 1+tol 
  12228.  
  12229.  ptol 
  12230.            poles with abs(real(pole)) < ptol*||H|| (H is appropriate 
  12231.            Hamiltonian) are considered to be on the imaginary axis. Default: 
  12232.            1e-9 
  12233.  
  12234.  tol 
  12235.            threshhold for 0.  Default: 200*eps 
  12236.  
  12237.            gmax, min, tol, and tol must all be postive scalars. 
  12238.  
  12239.  *Outputs* 
  12240.  
  12241.  K 
  12242.            system controller 
  12243.  
  12244.  g 
  12245.            designed gain value 
  12246.  
  12247.  GW 
  12248.            closed loop system 
  12249.  
  12250.  Xinf 
  12251.            ARE solution matrix for regulator subproblem 
  12252.  
  12253.  Yinf 
  12254.            ARE solution matrix for filter subproblem 
  12255.  
  12256.    1. Doyle, Glover, Khargonekar, Francis, "State Space Solutions    to 
  12257.       Standard H2 and Hinf Control Problems," IEEE TAC August 1989 
  12258.  
  12259.    2. Maciejowksi, J.M., "Multivariable feedback design,"    Addison-Wesley, 
  12260.       1989, ISBN 0-201-18243-2 
  12261.  
  12262.    3. Keith Glover and John C. Doyle, "State-space formulae for all 
  12263.       stabilizing controllers that satisfy and h-infinity-norm bound    and 
  12264.       relations to risk sensitivity,"    Systems & Control Letters 11, Oct. 
  12265.       1988, pp 167-172. 
  12266.  
  12267.  Function File : [xx, err] = hinfsyn_c (nn, ptol, s1{, s2}) 
  12268.  used internally in hinfsyn to evaluate hamiltonian/symplectic  eigenvalue 
  12269.  problems. 
  12270.  
  12271.  *WARNING* Argument checking not performed. 
  12272.  
  12273.  *Inputs* 
  12274.  
  12275.  s1 (alone) 
  12276.            hamiltonian matrix 
  12277.  
  12278.  (s1,s2)  as a pair 
  12279.            symplectic matrix pencil 
  12280.  
  12281.  *Outputs* 
  12282.  
  12283.  xx: positive (semi-)definite solution of DARE (set to 0 if err <=2) 
  12284.  
  12285.  code:  error: 
  12286.  
  12287.            *0* 
  12288.                           no error 
  12289.  
  12290.            *1* 
  12291.                             (s1): eigenvalues on imaginary axis 
  12292.  
  12293.                                (s1,s2): gen. eigenvalues on unit circle 
  12294.  
  12295.            *2* 
  12296.                             unequal number of stable/antistable (generalized) 
  12297.                           eigenvalues 
  12298.  
  12299.            *3* 
  12300.                           (s1): infinite entries in solution x 
  12301.  
  12302.                           (s1,s2): infinite entires in solution x or ( I + R X) 
  12303.                           singular 
  12304.  
  12305.            *4* 
  12306.                           x is not symmetric 
  12307.  
  12308.            *5* 
  12309.                           x has negative eigenvalues 
  12310.  
  12311.  Solution method: Either Laub's schur method or Symplectic GEP approach; uses 
  12312.  Van Dooren's code to re-order qz decompostion (www.netlib.com - toms/590) 
  12313.  
  12314.  See also: Ran and Rodman, "Stable Hermitian Solutions of Discrete  Algebraic 
  12315.  Riccati Equations," Mathematics of Control, Signals and  Systems, Vol 5, no 2 
  12316.  (1992)  pp 165-194. 
  12317.  
  12318.  Function File: [retval, Pc, Pf] = hinfsyn_chk(A, B1, B2, C1, C2, D12, D21, g, 
  12319.  ptol) 
  12320.   Called by hinfsyn to see if gain g satisfies conditions in Theorem 3 of 
  12321.  Doyle, Glover, Khargonekar, Francis, "State Space Solutions to Standard  H2 
  12322.  and Hinf Control Problems", IEEE TAC August 1989 
  12323.  
  12324.  *Warning* Do not attempt to use this at home; no argument checking performed. 
  12325.  
  12326.  *Inputs* as returned by is_dgkf, except for: 
  12327.  
  12328.  g 
  12329.            candidate gain level 
  12330.  
  12331.  ptol 
  12332.             as in hinfsyn 
  12333.  
  12334.   Outputs:   retval: = 1 if g exceeds optimal Hinf closed loop gain, else 0 
  12335.  Pc: solution of "regulator" H-inf ARE   Pf: solution of "filter" H-inf ARE 
  12336.  
  12337.  Function File: [k, p, e] = lqe (a, g, c, sigw, sigv, z) 
  12338.  Construct the linear quadratic estimator (Kalman filter) for the continuous 
  12339.  time system 
  12340.  
  12341.   dx
  12342.   -- = a x + b u
  12343.   dt
  12344.  
  12345.   y = c x + d u
  12346.  
  12347.  where w and v are zero-mean gaussian noise processes with respective 
  12348.  intensities 
  12349.  
  12350.   sigw = cov (w, w)
  12351.   sigv = cov (v, v)
  12352.  
  12353.  The optional argument z is the cross-covariance cov (w, v).  If it is omitted, 
  12354.  cov (w, v) = 0 is assumed. 
  12355.  
  12356.  Observer structure is dz/dt = A z + B u + k (y - C z - D u) 
  12357.  
  12358.  The following values are returned: 
  12359.  
  12360.  k 
  12361.            The observer gain, (a - kc) is stable. 
  12362.  
  12363.  p 
  12364.            The solution of algebraic Riccati equation. 
  12365.  
  12366.  e 
  12367.            The vector of closed loop poles of (a - kc). 
  12368.  
  12369.  Function File : [K, Q, P, Ee, Er] = lqg(sys, Sigw, Sigv, Q, R, in_idx) 
  12370.  Design a linear-quadratic-gaussian optimal controller for the system 
  12371.  
  12372.   dx/dt = A x + B u + G w       [w]=N(0,[Sigw 0    ])
  12373.       y = C x + v               [v]  (    0   Sigv ])
  12374.  
  12375.  or 
  12376.  
  12377.   x(k+1) = A x(k) + B u(k) + G w(k)       [w]=N(0,[Sigw 0    ])
  12378.     y(k) = C x(k) + v(k)                  [v]  (    0   Sigv ])
  12379.  
  12380.  *Inputs* 
  12381.  
  12382.  sys 
  12383.            system data structure 
  12384.  
  12385.  Sigw, Sigv 
  12386.            intensities of independent Gaussian noise processes (as above) 
  12387.  
  12388.  Q, R 
  12389.            state, control weighting respectively.  Control ARE is 
  12390.  
  12391.  in_idx 
  12392.            indices of controlled inputs 
  12393.  
  12394.               default: last dim(R) inputs are assumed to be controlled inputs, 
  12395.            all        others are assumed to be noise inputs. 
  12396.  
  12397.  *Outputs* 
  12398.  
  12399.  K 
  12400.            system data structure format LQG optimal controller (Obtain A,B,C 
  12401.            matrices with sys2ss, sys2tf, or sys2zp as appropriate) 
  12402.  
  12403.  P 
  12404.            Solution of control (state feedback) algebraic Riccati equation 
  12405.  
  12406.  Q 
  12407.            Solution of estimation algebraic Riccati equation 
  12408.  
  12409.  Ee 
  12410.            estimator poles 
  12411.  
  12412.  Es 
  12413.            controller poles 
  12414.  
  12415.  Function File: [k, p, e] = lqr (a, b, q, r, z) 
  12416.  construct the linear quadratic regulator for the continuous time system 
  12417.  
  12418.   dx
  12419.   -- = A x + B u
  12420.   dt
  12421.  
  12422.  to minimize the cost functional 
  12423.  
  12424.         infinity
  12425.         /
  12426.     J = |  x' Q x + u' R u
  12427.        /
  12428.       t=0
  12429.  
  12430.  z omitted or 
  12431.  
  12432.         infinity
  12433.         /
  12434.     J = |  x' Q x + u' R u + 2 x' Z u
  12435.        /
  12436.       t=0
  12437.  
  12438.  z included. 
  12439.  
  12440.  The following values are returned: 
  12441.  
  12442.  k 
  12443.            The state feedback gain, (a - bk) is stable. 
  12444.  
  12445.  p 
  12446.            The stabilizing solution of appropriate algebraic Riccati equation. 
  12447.  
  12448.  e 
  12449.            The vector of the closed loop poles of (a - bk). 
  12450.  
  12451.  Function File :  lsim (sys, u, t{,x0}) 
  12452.  Produce output for a linear simulation of a system 
  12453.  
  12454.  Produces a plot for the output of the system, sys. 
  12455.  
  12456.  U is an array that contains the system's inputs.  Each column in u corresponds 
  12457.  to a different time step.  Each row in u corresponds to a different input.  T 
  12458.  is an array that contains the time index of the system.  T should be regularly 
  12459.  spaced.  If initial conditions are required on the system, the x0 vector 
  12460.  should be added to the argument list. 
  12461.  
  12462.  When the lsim function is invoked with output parameters: [y,x] = 
  12463.  lsim(sys,u,t,[x0]) a plot is not displayed, however, the data is returned in y 
  12464.  = system output and x = system states. 
  12465.  
  12466.  Function File : K = place (sys, P) 
  12467.  Computes the matrix  K such that if the state is feedback with gain K, then 
  12468.  the eigenvalues  of the closed loop system (i.e. A-BK) are those specified in 
  12469.  the vector P. 
  12470.  
  12471.  Version: Beta (May-1997): If you have any comments, please let me know. 
  12472.  (see the file place.m for my address) 
  12473.  
  12474.  Written by: Jose Daniel Munoz Frias. 
  12475.  
  12476.  
  12477. ΓòÉΓòÉΓòÉ 58.6. Miscellaneous Functions (Not yet properly filed/documented) ΓòÉΓòÉΓòÉ
  12478.  
  12479. Function File : axvec = axis2dlim (axdata) 
  12480.  determine axis limits for 2-d data(column vectors); leaves a 10% margin 
  12481. around the plots.  puts in margins of +/- 0.1 if data is one dimensional (or a 
  12482. single point) 
  12483.  
  12484. *Inputs*   axdata nx2 matrix of data [x,y] 
  12485.  
  12486. *Outputs*   axvec vector of axis limits appropriate for call to axis() function 
  12487.  
  12488. Function File : outputs = mb ( inputs ) 
  12489.  $Revision: 1.9 $ 
  12490.  
  12491. Function File : outputs = moddemo ( inputs ) 
  12492.  Octave Controls toolbox demo: Model Manipulations demo  Written by David Clem 
  12493. August 15, 1994 
  12494.  
  12495. Function File : outputs = prompt ( inputs ) 
  12496.  function prompt([str])  Prompt user to continue  str: input string. Default 
  12497. value: "\n ---- Press a key to continue ---"  Written by David Clem August 15, 
  12498. 1994  Modified A. S. Hodel June 1995 
  12499.  
  12500. Function File : outputs = rldemo ( inputs ) 
  12501.  
  12502. Function File : outputs = rlocus ( inputs ) 
  12503.  [rldata, k] = rlocus(sys[,increment,min_k,max_k])  Displays root locus plot of 
  12504. the specified SISO system. 
  12505.  
  12506.     -----  ---   --------   --->| + |---|k|---->| SISO |----------->     ----- 
  12507. ---   --------     |     - ^               | 
  12508. |_____________________________| 
  12509.  
  12510. inputs: sys = system data structure     min_k, max_k,increment: minimum, 
  12511. maximum values of k and         the increment used in computing gain values 
  12512. Outputs: plots the root locus to the screen.   rldata: Data points plotted 
  12513. column 1: real values, column 2: imaginary       values)   k: gains for real 
  12514. axis break points. 
  12515.  
  12516. Function File : outputs = sortcom ( inputs ) 
  12517.  [yy,idx] = sortcom(xx[,opt]): sort a complex vector  xx: complex vector  opt: 
  12518. sorting option:     "re": real part (default)     "mag": by magnitude     "im": 
  12519. by imaginary part 
  12520.  
  12521.  if opt != "im" then complex conjugate pairs are grouped together,    a - jb 
  12522. followed by a + jb.  yy: sorted values  idx: permutation vector: yy = xx(idx) 
  12523.  
  12524. Function File : outputs = ss2tf ( inputs ) 
  12525.  [num,den] = ss2tf(a,b,c,d)  Conversion from tranfer function to state-space. 
  12526. The state space system    .    x = Ax + Bu    y = Cx + Du 
  12527.  
  12528.  is converted to a transfer function 
  12529.  
  12530.         num(s)      G(s)=-------         den(s) 
  12531.  
  12532.  used internally in system data structure format manipulations 
  12533.  
  12534. Function File : outputs = ss2zp ( inputs ) 
  12535.  Converts a state space representation to a set of poles and zeros. 
  12536.  
  12537.  [pol,zer,k] = ss2zp(a,b,c,d) returns the poles and zeros of the state space 
  12538. system (a,b,c,d).  K is a gain associated with the zeros. 
  12539.  
  12540.  used internally in system data structure format manipulations 
  12541.  
  12542. Function File : outputs = starp ( inputs ) 
  12543.  
  12544.  [sys] = starp(P, K, ny, nu) 
  12545.  
  12546.  Redheffer star product or upper/lower LFT, respectively. 
  12547.  
  12548.         +-------+    --------->|    |--------->         |  P  |      +--->| 
  12549. |---+  ny      |   +-------+  |      +-------------------+               |  | 
  12550. +----------------+  |      |          |      |   +-------+    |      +--->| 
  12551. |------+ nu         |  K  |    --------->|    |--------->         +-------+ 
  12552.  
  12553.  If ny and nu "consume" all inputs and outputs of K then the result  is a lower 
  12554. fractional transformation. If ny and nu "consume" all  inputs and outputs of P 
  12555. then the result is an upper fractional  transformation. 
  12556.  
  12557.  ny and/or nu may be negative (= negative feedback) 
  12558.  
  12559. Function File : outputs = susball ( inputs ) 
  12560.  
  12561. Function File : outputs = swap ( inputs ) 
  12562.  [a1,b1] = swap(a,b)  interchange a and b 
  12563.  
  12564. Function File : outputs = swapcols ( inputs ) 
  12565.  function B = swapcols(A)  permute columns of A into reverse order 
  12566.  
  12567. Function File : outputs = swaprows ( inputs ) 
  12568.  function B = swaprows(A)  permute rows of A into reverse order 
  12569.  
  12570. Function File : outputs = tf2ss ( inputs ) 
  12571.  Conversion from tranfer function to state-space.  The state space system    . 
  12572. x = Ax + Bu    y = Cx + Du 
  12573.  
  12574.  is obtained from a transfer function 
  12575.  
  12576.         num(s)      G(s)=-------         den(s) 
  12577.  
  12578.  via the function call [a,b,c,d] = tf2ss(num,den).  The vector 'den' must 
  12579. contain only one row, whereas the vector 'num'  may contain as many rows as 
  12580. there are outputs of the system 'y'.  The state space system matrices obtained 
  12581. from this function will be  in controllable canonical form as described in 
  12582. "Modern Control Theory",  [Brogan, 1991]. 
  12583.  
  12584. Function File : outputs = tf2zp ( inputs ) 
  12585.  Converts transfer functions to poles / zeros. 
  12586.  
  12587.  [zer,pol,k] = tf2zp(num,den) returns the zeros and poles of the SISO system 
  12588. defined by num/den.  K is a gain associated with the system zeros. 
  12589.  
  12590. Function File :  zp2ss 
  12591. Conversion from zero / pole to state space. The state space system 
  12592.  
  12593. .
  12594. x = Ax + Bu
  12595. y = Cx + Du
  12596.  
  12597. is obtained from a vector of zeros and a vector of poles via the function call 
  12598. [a,b,c,d] = zp2ss(zer,pol,k). The vectors `zer' and `pol' may either be row or 
  12599. column vectors.  Each zero and pole that has an imaginary part must have a 
  12600. conjugate in the list. The number of zeros must not exceed the number of poles. 
  12601. `k' is zp-form leading coefficient. 
  12602.  
  12603. Function File : [poly, rvals] = zp2ssg2 (rvals) 
  12604. Used internally in zp2ss Extract 2 values from rvals (if possible) and 
  12605. construct  a polynomial with those roots. 
  12606.  
  12607. Function File :  zp2tf 
  12608.  Converts zeros / poles to a transfer function. 
  12609.  
  12610. [num,den] = zp2tf(zer,pol,k) forms the transfer function num/den from the 
  12611. vectors of poles and zeros. 
  12612.  
  12613.  
  12614. ΓòÉΓòÉΓòÉ 59. Signal Processing ΓòÉΓòÉΓòÉ
  12615.  
  12616. I hope that someday Octave will include more signal processing functions.  If 
  12617. you would like to help improve Octave in this area, please contact 
  12618. bug-octave@bevo.che.wisc.edu. 
  12619.  
  12620. Function File:  detrend (x, p) 
  12621. If x is a vector, detrend (x, p) removes the best fit of a polynomial of order 
  12622. p from the data x. 
  12623.  
  12624. If x is a matrix, detrend (x, p) does the same for each column in x. 
  12625.  
  12626. The second argument is optional.  If it is not specified, a value of 1 is 
  12627. assumed.  This corresponds to removing a linear trend. 
  12628.  
  12629. Function:  fft (a, n) 
  12630. Compute the FFT of a using subroutines from Fftpack.  If a is a matrix, fft 
  12631. computes the FFT for each column of a. 
  12632.  
  12633. If called with two arguments, n is expected to be an integer specifying the 
  12634. number of elements of a to use.  If a is a matrix, n specifies the number of 
  12635. rows of a to use.  If n is larger than the size of a, a is resized and padded 
  12636. with zeros. 
  12637.  
  12638. Loadable Function:  ifft (a, n) 
  12639. Compute the inverse FFT of a using subroutines from Fftpack.  If a is a matrix, 
  12640. fft computes the inverse FFT for each column of a. 
  12641.  
  12642. If called with two arguments, n is expected to be an integer specifying the 
  12643. number of elements of a to use.  If a is a matrix, n specifies the number of 
  12644. rows of a to use.  If n is larger than the size of a, a is resized and padded 
  12645. with zeros. 
  12646.  
  12647. Loadable Function:  fft2 (a, n, m) 
  12648. Compute the two dimensional FFT of a. 
  12649.  
  12650. The optional arguments n and m may be used specify the number of rows and 
  12651. columns of a to use.  If either of these is larger than the size of a, a is 
  12652. resized and padded with zeros. 
  12653.  
  12654. Loadable Function:  ifft2 (a, n, m) 
  12655. Compute the two dimensional inverse FFT of a. 
  12656.  
  12657. The optional arguments n and m may be used specify the number of rows and 
  12658. columns of a to use.  If either of these is larger than the size of a, a is 
  12659. resized and padded with zeros. 
  12660.  
  12661. Built-in Function:  fftconv (a, b, n) 
  12662. Return the convolution of the vectors a and b, as a vector with length equal to 
  12663. the length (a) + length (b) - 1.  If a and b are the coefficient vectors of two 
  12664. polynomials, the returned value is the coefficient vector of the product 
  12665. polynomial. 
  12666.  
  12667. The computation uses the FFT by calling the function fftfilt.  If the optional 
  12668. argument n is specified, an N-point FFT is used. 
  12669.  
  12670. Function File:  fftfilt (b, x, n) 
  12671.  
  12672. With two arguments, fftfilt filters x with the FIR filter b using the FFT. 
  12673.  
  12674. Given the optional third argument, n, fftfilt uses the overlap-add method to 
  12675. filter x with b using an N-point FFT. 
  12676.  
  12677. Loadable Function: y = filter (b, a, x) 
  12678. Return the solution to the following linear, time-invariant difference 
  12679. equation: 
  12680.  
  12681.    N                   M
  12682.   SUM a(k+1) y(n-k) = SUM b(k+1) x(n-k)      for 1<=n<=length(x)
  12683.   k=0                 k=0
  12684.  
  12685. where  N=length(a)-1 and M=length(b)-1. An equivalent form of this equation is: 
  12686.  
  12687.             N                   M
  12688.   y(n) = - SUM c(k+1) y(n-k) + SUM d(k+1) x(n-k)  for 1<=n<=length(x)
  12689.            k=1                 k=0
  12690.  
  12691. where  c = a/a(1) and d = b/a(1). 
  12692.  
  12693. In terms of the z-transform, y is the result of passing the discrete- time 
  12694. signal x through a system characterized by the following rational system 
  12695. function: 
  12696.  
  12697.              M
  12698.             SUM d(k+1) z^(-k)
  12699.             k=0
  12700.   H(z) = ----------------------
  12701.                N
  12702.           1 + SUM c(k+1) z(-k)
  12703.               k=1
  12704.  
  12705. Loadable Function: [y, sf] = filter (b, a, x, si) 
  12706. This is the same as the filter function described above, except that si is 
  12707. taken as the initial state of the system and the final state is returned as sf. 
  12708. The state vector is a column vector whose length is equal to the length of the 
  12709. longest coefficient vector minus one.  If si is not set, the initial state 
  12710. vector is set to all zeros. 
  12711.  
  12712. Function File: [h, w] = freqz (b, a, n, "whole") 
  12713. Return the complex frequency response h of the rational IIR filter whose 
  12714. numerator and denominator coefficients are b and a, respectively.  The response 
  12715. is evaluated at n angular frequencies between 0 and  2*pi. 
  12716.  
  12717. The output value w is a vector of the frequencies. 
  12718.  
  12719. If the fourth argument is omitted, the response is evaluated at frequencies 
  12720. between 0 and  pi. 
  12721.  
  12722. If n is omitted, a value of 512 is assumed. 
  12723.  
  12724. If a is omitted, the denominator is assumed to be 1 (this corresponds to a 
  12725. simple FIR filter). 
  12726.  
  12727. For fastest computation, n should factor into a small number of small primes. 
  12728.  
  12729. Function File:  sinc (x) 
  12730. Return  sin(pi*x)/(pi*x). 
  12731.  
  12732.  
  12733. ΓòÉΓòÉΓòÉ 60. Image Processing ΓòÉΓòÉΓòÉ
  12734.  
  12735. Octave can display images with the X Window System using the xloadimage 
  12736. program.  You do not need to be running X in order to manipulate images, 
  12737. however, so some of these functions may be useful even if you are not able to 
  12738. view the results. 
  12739.  
  12740. Loading images only works with Octave's image format (a file with a matrix 
  12741. containing the image data, and a matrix containing the colormap). 
  12742. Contributions of robust, well-written functions to read other image formats are 
  12743. welcome.  If you can provide them, or would like to improve Octave's image 
  12744. processing capabilities in other ways, please contact 
  12745. bug-octave@bevo.che.wisc.edu. 
  12746.  
  12747. Function File:  colormap (map) 
  12748.  
  12749. Function File:  colormap ("default") 
  12750. Set the current colormap. 
  12751.  
  12752. colormap (map) sets the current colormap to map.  The color map should be an n 
  12753. row by 3 column matrix.  The columns contain red, green, and blue intensities 
  12754. respectively.  All entries should be between 0 and 1 inclusive.  The new 
  12755. colormap is returned. 
  12756.  
  12757. colormap ("default") restores the default colormap (a gray scale colormap with 
  12758. 64 entries).  The default colormap is returned. 
  12759.  
  12760. With no arguments, colormap returns the current color map. 
  12761.  
  12762. Function File:  gray (n) 
  12763. Return a gray colormap with n entries corresponding to values from 0 to n.  The 
  12764. argument n should be a scalar.  If it is omitted, 64 is assumed. 
  12765.  
  12766. Function File: [img, map] = gray2ind () 
  12767. Convert a gray scale intensity image to an Octave indexed image. 
  12768.  
  12769. Function File:  image (x, zoom) 
  12770. Display a matrix as a color image.  The elements of x are indices into the 
  12771. current colormap and should have values between 1 and the length of the 
  12772. colormap.  If zoom is omitted, a value of 4 is assumed. 
  12773.  
  12774. Function File:  imagesc (x, zoom) 
  12775. Display a scaled version of the matrix x as a color image.  The matrix is 
  12776. scaled so that its entries are indices into the current colormap.  The scaled 
  12777. matrix is returned.  If zoom is omitted, a value of 4 is assumed. 
  12778.  
  12779. Function File:  imshow (x, map) 
  12780.  
  12781. Function File:  imshow (x, n) 
  12782.  
  12783. Function File:  imshow (i, n) 
  12784.  
  12785. Function File:  imshow (r, g, b) 
  12786. Display images. 
  12787.  
  12788. imshow (x) displays an indexed image using the current colormap. 
  12789.  
  12790. imshow (x, map) displays an indexed image using the specified colormap. 
  12791.  
  12792. imshow (i, n) displays a gray scale intensity image. 
  12793.  
  12794. imshow (r, g, b) displays an RGB image. 
  12795.  
  12796. Function File:  ind2gray (x, map) 
  12797. Convert an Octave indexed image to a gray scale intensity image. If map is 
  12798. omitted, the current colormap is used to determine the intensities. 
  12799.  
  12800. Function File: [r, g, b] = ind2rgb (x, map) 
  12801. Convert an indexed image to red, green, and blue color components. If map is 
  12802. omitted, the current colormap is used for the conversion. 
  12803.  
  12804. Function File: [x, map] = loadimage (file) 
  12805. Load an image file and it's associated color map from the specified file.  The 
  12806. image must be stored in Octave's image format. 
  12807.  
  12808. Function File:  rgb2ntsc (rgb) 
  12809. Image format conversion. 
  12810.  
  12811. Function File:  ntsc2rgb (yiq) 
  12812. Image format conversion. 
  12813.  
  12814. Function File:  ocean (n) 
  12815. Create color colormap.  The argument n should be a scalar.  If it is omitted, 
  12816. 64 is assumed. 
  12817.  
  12818. Function File: [x, map] = rgb2ind (r, g, b) 
  12819. Convert and RGB image to an Octave indexed image. 
  12820.  
  12821. Function File:  saveimage (file, x, fmt, map) 
  12822. Save the matrix x to file in image format fmt.  Valid values for fmt are 
  12823.  
  12824.  "img" 
  12825.            Octave's image format.  The current colormap is also saved in the 
  12826.            file. 
  12827.  
  12828.  "ppm" 
  12829.            Portable pixmap format. 
  12830.  
  12831.  "ps" 
  12832.            PostScript format.  Note that images saved in PostScript format can 
  12833.            not be read back into Octave with loadimage. 
  12834.  
  12835.  If the fourth argument is supplied, the specified colormap will also be saved 
  12836.  along with the image. 
  12837.  
  12838.  Note: if the colormap contains only two entries and these entries are black 
  12839.  and white, the bitmap ppm and PostScript formats are used.  If the image is a 
  12840.  gray scale image (the entries within each row of the colormap are equal) the 
  12841.  gray scale ppm and PostScript image formats are used, otherwise the full color 
  12842.  formats are used. 
  12843.  
  12844.  Built-in Variable: IMAGEPATH 
  12845.  A colon separated list of directories in which to search for image files. 
  12846.  
  12847.  
  12848. ΓòÉΓòÉΓòÉ 61. Audio Processing ΓòÉΓòÉΓòÉ
  12849.  
  12850. Octave provides a few functions for dealing with audio data.  An audio `sample' 
  12851. is a single output value from an A/D converter, i.e., a small integer number 
  12852. (usually 8 or 16 bits), and audio data is just a series of such samples.  It 
  12853. can be characterized by three parameters:  the sampling rate (measured in 
  12854. samples per second or Hz, e.g. 8000 or 44100), the number of bits per sample 
  12855. (e.g. 8 or 16), and the number of channels (1 for mono, 2 for stereo, etc.). 
  12856.  
  12857. There are many different formats for representing such data.  Currently, only 
  12858. the two most popular, linear encoding and mu-law encoding, are supported by 
  12859. Octave.  There is an excellent FAQ on audio formats by Guido van Rossum 
  12860. <guido@cwi.nl> which can be found at any FAQ ftp site, in particular in the 
  12861. directory `/pub/usenet/news.answers/audio-fmts' of the archive site 
  12862. rtfm.mit.edu. 
  12863.  
  12864. Octave simply treats audio data as vectors of samples (non-mono data are not 
  12865. supported yet).  It is assumed that audio files using linear encoding have one 
  12866. of the extensions `lin' or `raw', and that files holding data in mu-law 
  12867. encoding end in `au', `mu', or `snd'. 
  12868.  
  12869. Function File:  lin2mu (x) 
  12870. If the vector x represents mono audio data in 8- or 16-bit linear encoding, 
  12871. lin2mu (x) is the corresponding mu-law encoding. 
  12872.  
  12873. Function File:  mu2lin (x, bps) 
  12874. If the vector x represents mono audio data in mu-law encoding, mu2lin converts 
  12875. it to linear encoding.  The optional argument bps specifies whether the input 
  12876. data uses 8 bit per sample (default) or 16 bit. 
  12877.  
  12878. Function File:  loadaudio (name, ext, bps) 
  12879. Loads audio data from the file `name.ext' into the vector x. 
  12880.  
  12881. The extension ext determines how the data in the audio file is interpreted; 
  12882. the extensions `lin' (default) and `raw' correspond to linear, the extensions 
  12883. `au', `mu', or `snd' to mu-law encoding. 
  12884.  
  12885. The argument bps can be either 8 (default) or 16, and specifies the number of 
  12886. bits per sample used in the audio file. 
  12887.  
  12888. Function File:  saveaudio (name, x, ext, bps) 
  12889. Saves a vector x of audio data to the file `name.ext'.  The optional parameters 
  12890. ext and bps determine the encoding and the number of bits per sample used in 
  12891. the audio file (see loadaudio);  defaults are `lin' and 8, respectively. 
  12892.  
  12893. The following functions for audio I/O require special A/D hardware and 
  12894. operating system support.  It is assumed that audio data in linear encoding can 
  12895. be played and recorded by reading from and writing to `/dev/dsp', and that 
  12896. similarly `/dev/audio' is used for mu-law encoding.  These file names are 
  12897. system-dependent.  Improvements so that these functions will work without 
  12898. modification on a wide variety of hardware are welcome. 
  12899.  
  12900. Function File:  playaudio (name, ext) 
  12901.  
  12902. Function File:  playaudio (x) 
  12903. Plays the audio file `name.ext' or the audio data stored in the vector x. 
  12904.  
  12905. Function File:  record (sec, sampling_rate) 
  12906. Records sec seconds of audio input into the vector x.  The default value for 
  12907. sampling_rate is 8000 samples per second, or 8kHz.  The program waits until the 
  12908. user types RET and then immediately starts to record. 
  12909.  
  12910. Function File:  setaudio (type) 
  12911.  
  12912. Function File:  setaudio (type, value) 
  12913. Set or display various properties of your mixer hardware. 
  12914.  
  12915. For example, if vol corresponds to the volume property, you can set it to 50 
  12916. (percent) by setaudio ("vol", 50). 
  12917.  
  12918. This is an simple experimental program to control the audio hardware settings. 
  12919. It assumes that there is a mixer program which can be used as mixer type value, 
  12920. and simply executes system ("mixer type value").  Future releases might get rid 
  12921. of this assumption by using the fcntl interface. 
  12922.  
  12923.  
  12924. ΓòÉΓòÉΓòÉ 62. System Utilities ΓòÉΓòÉΓòÉ
  12925.  
  12926. This chapter describes the functions that are available to allow you to get 
  12927. information about what is happening outside of Octave, while it is still 
  12928. running, and use this information in your program.  For example, you can get 
  12929. information about environment variables, the current time, and even start other 
  12930. programs from the Octave prompt. 
  12931.  
  12932.  Timing Utilities 
  12933.  Filesystem Utilities 
  12934.  Controlling Subprocesses 
  12935.  Process ID Information 
  12936.  Environment Variables 
  12937.  Current Working Directory 
  12938.  Password Database Functions 
  12939.  Group Database Functions 
  12940.  System Information 
  12941.  
  12942.  
  12943. ΓòÉΓòÉΓòÉ 62.1. Timing Utilities ΓòÉΓòÉΓòÉ
  12944.  
  12945. Octave's core set of functions for manipulating time values are patterned after 
  12946. the corresponding functions from the standard C library. Several of these 
  12947. functions use a data structure for time that includes the following elements: 
  12948.  
  12949.  usec 
  12950.            Microseconds after the second (0-999999). 
  12951.  
  12952.  sec 
  12953.            Seconds after the minute (0-61).  This number can be 61 to account 
  12954.            for leap seconds. 
  12955.  
  12956.  min 
  12957.            Minutes after the hour (0-59). 
  12958.  
  12959.  hour 
  12960.            Hours since midnight (0-23). 
  12961.  
  12962.  mday 
  12963.            Day of the month (1-31). 
  12964.  
  12965.  mon 
  12966.            Months since January (0-11). 
  12967.  
  12968.  year 
  12969.            Years since 1900. 
  12970.  
  12971.  wday 
  12972.            Days since Sunday (0-6). 
  12973.  
  12974.  yday 
  12975.            Days since January 1 (0-365). 
  12976.  
  12977.  isdst 
  12978.            Daylight Savings Time flag. 
  12979.  
  12980.  zone 
  12981.            Time zone. 
  12982.  
  12983.  In the descriptions of the following functions, this structure is referred to 
  12984.  as a tm_struct. 
  12985.  
  12986.  Loadable Function:  time () 
  12987.  Return the current time as the number of seconds since the epoch.  The epoch 
  12988.  is referenced to 00:00:00 CUT (Coordinated Universal Time) 1 Jan 1970.  For 
  12989.  example, on Monday February 17, 1997 at 07:15:06 CUT, the value returned by 
  12990.  time was 856163706. 
  12991.  
  12992.  Function File:  ctime (t) 
  12993.  Convert a value returned from time (or any other nonnegative integer), to the 
  12994.  local time and return a string of the same form as asctime.  The function 
  12995.  ctime (time) is equivalent to asctime (localtime (time)).  For example, 
  12996.  
  12997.   ctime (time ())
  12998.        => "Mon Feb 17 01:15:06 1997"
  12999.  
  13000.  Loadable Function:  gmtime (t) 
  13001.  Given a value returned from time (or any nonnegative integer), return a time 
  13002.  structure corresponding to CUT.  For example, 
  13003.  
  13004.   gmtime (time ())
  13005.        => {
  13006.              usec = 0
  13007.              year = 97
  13008.              mon = 1
  13009.              mday = 17
  13010.              sec = 6
  13011.              zone = CST
  13012.              min = 15
  13013.              wday = 1
  13014.              hour = 7
  13015.              isdst = 0
  13016.              yday = 47
  13017.            }
  13018.  
  13019.  Loadable Function:  localtime (t) 
  13020.  Given a value returned from time (or any nonnegative integer), return a time 
  13021.  structure corresponding to the local time zone. 
  13022.  
  13023.   localtime (time ())
  13024.        => {
  13025.              usec = 0
  13026.              year = 97
  13027.              mon = 1
  13028.              mday = 17
  13029.              sec = 6
  13030.              zone = CST
  13031.              min = 15
  13032.              wday = 1
  13033.              hour = 1
  13034.              isdst = 0
  13035.              yday = 47
  13036.            }
  13037.  
  13038.  Loadable Function:  mktime (tm_struct) 
  13039.  Convert a time structure corresponding to the local time to the number of 
  13040.  seconds since the epoch.  For example, 
  13041.  
  13042.   mktime (localtime (time ())
  13043.        => 856163706
  13044.  
  13045.  Function File:  asctime (tm_struct) 
  13046.  Convert a time structure to a string using the following five-field format: 
  13047.  Thu Mar 28 08:40:14 1996.  For example, 
  13048.  
  13049.   asctime (localtime (time ())
  13050.        => "Mon Feb 17 01:15:06 1997\n"
  13051.  
  13052.  This is equivalent to ctime (time ()). 
  13053.  
  13054.  Loadable Function:  strftime (tm_struct) 
  13055.  Format a time structure in a flexible way using `%' substitutions similar to 
  13056.  those in printf.  Except where noted, substituted fields have a fixed size; 
  13057.  numeric fields are padded if necessary. Padding is with zeros by default; for 
  13058.  fields that display a single number, padding can be changed or inhibited by 
  13059.  following the `%' with one of the modifiers described below.  Unknown field 
  13060.  specifiers are copied as normal characters.  All other characters are copied 
  13061.  to the output without change.  For example, 
  13062.  
  13063.   strftime ("%r (%Z) %A %e %B %Y", localtime (time ())
  13064.        => "01:15:06 AM (CST) Monday 17 February 1997"
  13065.  
  13066.  Octave's strftime function supports a superset of the ANSI C field specifiers. 
  13067.  
  13068.  Literal character fields: 
  13069.  
  13070.  % 
  13071.            % character. 
  13072.  
  13073.  n 
  13074.            Newline character. 
  13075.  
  13076.  t 
  13077.            Tab character. 
  13078.  
  13079.  Numeric modifiers (a nonstandard extension): 
  13080.  
  13081.  - (dash) 
  13082.            Do not pad the field. 
  13083.  
  13084.  _ (underscore) 
  13085.            Pad the field with spaces. 
  13086.  
  13087.  Time fields: 
  13088.  
  13089.  %H 
  13090.            Hour (00-23). 
  13091.  
  13092.  %I 
  13093.            Hour (01-12). 
  13094.  
  13095.  %k 
  13096.            Hour (0-23). 
  13097.  
  13098.  %l 
  13099.            Hour (1-12). 
  13100.  
  13101.  %M 
  13102.            Minute (00-59). 
  13103.  
  13104.  %p 
  13105.            Locale's AM or PM. 
  13106.  
  13107.  %r 
  13108.            Time, 12-hour (hh:mm:ss [AP]M). 
  13109.  
  13110.  %R 
  13111.            Time, 24-hour (hh:mm). 
  13112.  
  13113.  %s 
  13114.            Time in seconds since 00:00:00, Jan 1, 1970 (a nonstandard 
  13115.            extension). 
  13116.  
  13117.  %S 
  13118.            Second (00-61). 
  13119.  
  13120.  %T 
  13121.            Time, 24-hour (hh:mm:ss). 
  13122.  
  13123.  %X 
  13124.            Locale's time representation (%H:%M:%S). 
  13125.  
  13126.  %Z 
  13127.            Time zone (EDT), or nothing if no time zone is determinable. 
  13128.  
  13129.  Date fields: 
  13130.  
  13131.  %a 
  13132.            Locale's abbreviated weekday name (Sun-Sat). 
  13133.  
  13134.  %A 
  13135.            Locale's full weekday name, variable length (Sunday-Saturday). 
  13136.  
  13137.  %b 
  13138.            Locale's abbreviated month name (Jan-Dec). 
  13139.  
  13140.  %B 
  13141.            Locale's full month name, variable length (January-December). 
  13142.  
  13143.  %c 
  13144.            Locale's date and time (Sat Nov 04 12:02:33 EST 1989). 
  13145.  
  13146.  %C 
  13147.            Century (00-99). 
  13148.  
  13149.  %d 
  13150.            Day of month (01-31). 
  13151.  
  13152.  %e 
  13153.            Day of month ( 1-31). 
  13154.  
  13155.  %D 
  13156.            Date (mm/dd/yy). 
  13157.  
  13158.  %h 
  13159.            Same as %b. 
  13160.  
  13161.  %j 
  13162.            Day of year (001-366). 
  13163.  
  13164.  %m 
  13165.            Month (01-12). 
  13166.  
  13167.  %U 
  13168.            Week number of year with Sunday as first day of week (00-53). 
  13169.  
  13170.  %w 
  13171.            Day of week (0-6). 
  13172.  
  13173.  %W 
  13174.            Week number of year with Monday as first day of week (00-53). 
  13175.  
  13176.  %x 
  13177.            Locale's date representation (mm/dd/yy). 
  13178.  
  13179.  %y 
  13180.            Last two digits of year (00-99). 
  13181.  
  13182.  %Y 
  13183.            Year (1970-). 
  13184.  
  13185.  Most of the remaining functions described in this section are not patterned 
  13186.  after the standard C library.  Some are available for compatiblity with Matlab 
  13187.  and others are provided because they are useful. 
  13188.  
  13189.  Function File:  clock () 
  13190.  Return a vector containing the current year, month (1-12), day (1-31), hour 
  13191.  (0-23), minute (0-59) and second (0-61).  For example, 
  13192.  
  13193.   clock ()
  13194.        => [ 1993, 8, 20, 4, 56, 1 ]
  13195.  
  13196.  The function clock is more accurate on systems that have the gettimeofday 
  13197.  function. 
  13198.  
  13199.  Function File:  date () 
  13200.  Return the date as a character string in the form DD-MMM-YY.  For example, 
  13201.  
  13202.   date ()
  13203.        => "20-Aug-93"
  13204.  
  13205.  Function File:  etime (t1, t2) 
  13206.  Return the difference (in seconds) between two time values returned from 
  13207.  clock.  For example: 
  13208.  
  13209.   t0 = clock ();
  13210.   # many computations later...
  13211.   elapsed_time = etime (clock (), t0);
  13212.  
  13213.  will set the variable elapsed_time to the number of seconds since the variable 
  13214.  t0 was set. 
  13215.  
  13216.  Built-in Function: [total, user, system] = cputime (); 
  13217.  Return the CPU time used by your Octave session.  The first output is the 
  13218.  total time spent executing your process and is equal to the sum of second and 
  13219.  third outputs, which are the number of CPU seconds spent executing in user 
  13220.  mode and the number of CPU seconds spent executing in system mode, 
  13221.  respectively.  If your system does not have a way to report CPU time usage, 
  13222.  cputime returns 0 for each of its output values. Note that because Octave used 
  13223.  some CPU time to start, it is reasonable to check to see if cputime works by 
  13224.  checking to see if the total CPU time used is nonzero. 
  13225.  
  13226.  Function File:  is_leap_year (year) 
  13227.  Return 1 if the given year is a leap year and 0 otherwise.  If no arguments 
  13228.  are provided, is_leap_year will use the current year. For example, 
  13229.  
  13230.   is_leap_year (2000)
  13231.        => 1
  13232.  
  13233.  Function File:  tic () 
  13234.  
  13235.  Function File:  toc () 
  13236.  These functions set and check a wall-clock timer.  For example, 
  13237.  
  13238.   tic ();
  13239.   # many computations later...
  13240.   elapsed_time = toc ();
  13241.  
  13242.  will set the variable elapsed_time to the number of seconds since the most 
  13243.  recent call to the function tic. 
  13244.  
  13245.  If you are more interested in the CPU time that your process used, you should 
  13246.  use the cputime function instead.  The tic and toc functions report the actual 
  13247.  wall clock time that elapsed between the calls.  This may include time spent 
  13248.  processing other jobs or doing nothing at all.  For example, 
  13249.  
  13250.   tic (); sleep (5); toc ()
  13251.        => 5
  13252.   t = cputime (); sleep (5); cputime () - t
  13253.        => 0
  13254.  
  13255.  (This example also illustrates that the CPU timer may have a fairly coarse 
  13256.  resolution.) 
  13257.  
  13258.  Built-in Function:  pause (seconds) 
  13259.  Suspend the execution of the program.  If invoked without any arguments, 
  13260.  Octave waits until you type a character.  With a numeric argument, it pauses 
  13261.  for the given number of seconds.  For example, the following statement prints 
  13262.  a message and then waits 5 seconds before clearing the screen. 
  13263.  
  13264.   fprintf (stderr, "wait please...\n");
  13265.   pause (5);
  13266.   clc;
  13267.  
  13268.  Built-in Function:  sleep (seconds) 
  13269.  Suspend the execution of the program for the given number of seconds. 
  13270.  
  13271.  Built-in Function:  usleep (microseconds) 
  13272.  Suspend the execution of the program for the given number of microseconds.  On 
  13273.  systems where it is not possible to sleep for periods of time less than one 
  13274.  second, usleep will pause the execution for round (microseconds / 1e6) 
  13275.  seconds. 
  13276.  
  13277.  
  13278. ΓòÉΓòÉΓòÉ 62.2. Filesystem Utilities ΓòÉΓòÉΓòÉ
  13279.  
  13280. Octave includes the following functions for renaming and deleting files, 
  13281. creating, deleting, and reading directories, and for getting information about 
  13282. the status of files. 
  13283.  
  13284. Built-in Function: [err, msg] = rename (old, new) 
  13285. Change the name of file old to new. 
  13286.  
  13287. If successful, err is 0 and msg is an empty string. Otherwise, err is nonzero 
  13288. and msg contains a system-dependent error message. 
  13289.  
  13290. Built-in Function: [err, msg] = unlink (file) 
  13291. Delete file. 
  13292.  
  13293. If successful, err is 0 and msg is an empty string. Otherwise, err is nonzero 
  13294. and msg contains a system-dependent error message. 
  13295.  
  13296. Built-in Function: [files, err, msg] = readdir (dir) 
  13297. Return names of the files in the directory dir as an array of strings.  If an 
  13298. error occurs, return an empty matrix in files. 
  13299.  
  13300. If successful, err is 0 and msg is an empty string. Otherwise, err is nonzero 
  13301. and msg contains a system-dependent error message. 
  13302.  
  13303. Built-in Function: [err, msg] = mkdir (dir) 
  13304. Create a directory named dir. 
  13305.  
  13306. If successful, err is 0 and msg is an empty string. Otherwise, err is nonzero 
  13307. and msg contains a system-dependent error message. 
  13308.  
  13309. Built-in Function: [err, msg] = rmdir (dir) 
  13310. Remove the directory named dir. 
  13311.  
  13312. If successful, err is 0 and msg is an empty string. Otherwise, err is nonzero 
  13313. and msg contains a system-dependent error message. 
  13314.  
  13315. Built-in Function: [err, msg] = mkfifo (name) 
  13316. Create a FIFO special file. 
  13317.  
  13318. If successful, err is 0 and msg is an empty string. Otherwise, err is nonzero 
  13319. and msg contains a system-dependent error message. 
  13320.  
  13321. Built-in Function:  umask (mask) 
  13322. Set the permission mask for file creation.  The parameter mask is interpreted 
  13323. as an octal number. 
  13324.  
  13325. Built-in Function: [info, err, msg] = stat (file) 
  13326.  
  13327. Built-in Function: [info, err, msg] = lstat (file) 
  13328. Return a structure s containing the following information about file. 
  13329.  
  13330.  dev 
  13331.            ID of device containing a directory entry for this file. 
  13332.  
  13333.  ino 
  13334.            File number of the file. 
  13335.  
  13336.  modestr 
  13337.            File mode, as a string of ten letters or dashes as would be returned 
  13338.            by ls -l. 
  13339.  
  13340.  nlink 
  13341.            Number of links. 
  13342.  
  13343.  uid 
  13344.            User ID of file's owner. 
  13345.  
  13346.  gid 
  13347.            Group ID of file's group. 
  13348.  
  13349.  rdev 
  13350.            ID of device for block or character special files. 
  13351.  
  13352.  size 
  13353.            Size in bytes. 
  13354.  
  13355.  atime 
  13356.            Time of last access in the same form as time values returned from 
  13357.            time.  See Timing Utilities. 
  13358.  
  13359.  mtime 
  13360.            Time of last modification in the same form as time values returned 
  13361.            from time.  See Timing Utilities. 
  13362.  
  13363.  ctime 
  13364.            Time of last file status change in the same form as time values 
  13365.            returned from time.  See Timing Utilities. 
  13366.  
  13367.  blksize 
  13368.            Size of blocks in the file. 
  13369.  
  13370.  blocks 
  13371.            Number of blocks allocated for file. 
  13372.  
  13373.  If the call is successful err is 0 and msg is an empty string.  If the file 
  13374.  does not exist, or some other error occurs, s is an empty matrix, err is -1, 
  13375.  and msg contains the corresponding system error message. 
  13376.  
  13377.  If file is a symbolic link, stat will return information about the actual file 
  13378.  the is referenced by the link.  Use lstat if you want information about the 
  13379.  symbolic link itself. 
  13380.  
  13381.  For example, 
  13382.  
  13383.   [s, err, msg] = stat ("/vmlinuz")
  13384.        => s =
  13385.           {
  13386.             atime = 855399756
  13387.             rdev = 0
  13388.             ctime = 847219094
  13389.             uid = 0
  13390.             size = 389218
  13391.             blksize = 4096
  13392.             mtime = 847219094
  13393.             gid = 6
  13394.             nlink = 1
  13395.             blocks = 768
  13396.             modestr = -rw-r--r--
  13397.             ino = 9316
  13398.             dev = 2049
  13399.           }
  13400.        => err = 0
  13401.        => msg =
  13402.  
  13403.  Built-in Function:  glob (pattern) 
  13404.  Given an array of strings in pattern, return the list of file names that any 
  13405.  of them, or an empty string if no patterns match.  Tilde expansion is 
  13406.  performed on each of the patterns before looking for matching file names.  For 
  13407.  example, 
  13408.  
  13409.   glob ("/vm*")
  13410.        => "/vmlinuz"
  13411.  
  13412.  Note that multiple values are returned in a string matrix with the fill 
  13413.  character set to ASCII NUL. 
  13414.  
  13415.  Built-in Function:  fnmatch (pattern, string) 
  13416.  Return 1 or zero for each element of string that matches any of the elements 
  13417.  of the string array pattern, using the rules of filename pattern matching. 
  13418.  For example, 
  13419.  
  13420.   fnmatch ("a*b", ["ab"; "axyzb"; "xyzab"])
  13421.        => [ 1; 1; 0 ]
  13422.  
  13423.  Built-in Function:  file_in_path (path, file) 
  13424.  Return the absolute name name of file if it can be found in path.  The value 
  13425.  of path should be a colon-separated list of directories in the format 
  13426.  described for the built-in variable LOADPATH. 
  13427.  
  13428.  If the file cannot be found in the path, an empty matrix is returned. For 
  13429.  example, 
  13430.  
  13431.   file_in_path (LOADPATH, "nargchk.m")
  13432.        => "*/share/octave/2.0/m/general/nargchk.m"
  13433.  
  13434.  Built-in Function:  tilde_expand (string) 
  13435.  Performs tilde expansion on string.  If string begins with a tilde character, 
  13436.  (`~'), all of the characters preceding the first slash (or all characters, if 
  13437.  there is no slash) are treated as a possible user name, and the tilde and the 
  13438.  following characters up to the slash are replaced by the home directory of the 
  13439.  named user.  If the tilde is followed immediately by a slash, the tilde is 
  13440.  replaced by the home directory of the user running Octave.  For example, 
  13441.  
  13442.   tilde_expand ("~joeuser/bin")
  13443.        => "/home/joeuser/bin"
  13444.   tilde_expand ("~/bin")
  13445.        => "/home/jwe/bin"
  13446.  
  13447.  
  13448. ΓòÉΓòÉΓòÉ 62.3. Controlling Subprocesses ΓòÉΓòÉΓòÉ
  13449.  
  13450. Octave includes some high-level commands like system and popen for starting 
  13451. subprocesses.  If you want to run another program to perform some task and then 
  13452. look at its output, you will probably want to use these functions. 
  13453.  
  13454. Octave also provides several very low-level Unix-like functions which can also 
  13455. be used for starting subprocesses, but you should probably only use them if you 
  13456. can't find any way to do what you need with the higher-level functions. 
  13457.  
  13458. Built-in Function:  system (string, return_output, type) 
  13459. Execute a shell command specified by string.  The second argument is optional. 
  13460. If type is "async", the process is started in the background and the process id 
  13461. of the child process is returned immediately.  Otherwise, the process is 
  13462. started, and Octave waits until it exits.  If type argument is omitted, a value 
  13463. of "sync" is assumed. 
  13464.  
  13465. If two input arguments are given (the actual value of return_output is 
  13466. irrelevant) and the subprocess is started synchronously, or if system is called 
  13467. with one input argument and one or more output arguments, the output from the 
  13468. command is returned. Otherwise, if the subprocess is executed synchronously, 
  13469. it's output is sent to the standard output.  To send the output of a command 
  13470. executed with system through the pager, use a command like 
  13471.  
  13472. disp (system (cmd, 1));
  13473.  
  13474. or 
  13475.  
  13476. printf ("%s\n", system (cmd, 1));
  13477.  
  13478. The system function can return two values.  The first is any output from the 
  13479. command that was written to the standard output stream, and the second is the 
  13480. output status of the command.  For example, 
  13481.  
  13482. [output, status] = system ("echo foo; exit 2");
  13483.  
  13484. will set the variable output to the string `foo', and the variable status to 
  13485. the integer `2'. 
  13486.  
  13487. Built-in Function: fid = popen (command, mode) 
  13488. Start a process and create a pipe.  The name of the command to run is given by 
  13489. command.  The file identifier corresponding to the input or output stream of 
  13490. the process is returned in fid.  The argument mode may be 
  13491.  
  13492.  "r" 
  13493.            The pipe will be connected to the standard output of the process, 
  13494.            and open for reading. 
  13495.  
  13496.  "w" 
  13497.            The pipe will be connected to the standard input of the process, and 
  13498.            open for writing. 
  13499.  
  13500.  For example, 
  13501.  
  13502.   fid = popen ("ls -ltr / | tail -3", "r");
  13503.   while (isstr (s = fgets (fid)))
  13504.     fputs (stdout, s);
  13505.   endwhile
  13506.        -| drwxr-xr-x  33 root  root  3072 Feb 15 13:28 etc
  13507.        -| drwxr-xr-x   3 root  root  1024 Feb 15 13:28 lib
  13508.        -| drwxrwxrwt  15 root  root  2048 Feb 17 14:53 tmp
  13509.  
  13510.  Built-in Function:  pclose (fid) 
  13511.  Close a file identifier that was opened by popen.  You may also use fclose for 
  13512.  the same purpose. 
  13513.  
  13514.  Built-in Function: [in, out, pid] = popen2 (command, args) 
  13515.  Start a subprocess with two-way communication.  The name of the process is 
  13516.  given by command, and args is an array of strings containing options for the 
  13517.  command.  The file identifiers for the input and output streams of the 
  13518.  subprocess are returned in in and out.  If execution of the command is 
  13519.  successful, pid contains the process ID of the subprocess.  Otherwise, pid is 
  13520.  -1. 
  13521.  
  13522.  For example, 
  13523.  
  13524.   [in, out, pid] = popen2 ("sort", "-nr");
  13525.   fputs (in, "these\nare\nsome\nstrings\n");
  13526.   fclose (in);
  13527.   while (isstr (s = fgets (out)))
  13528.     fputs (stdout, s);
  13529.   endwhile
  13530.   fclose (out);
  13531.        -| are
  13532.        -| some
  13533.        -| strings
  13534.        -| these
  13535.  
  13536.  Built-in Variable: EXEC_PATH 
  13537.  The variable EXEC_PATH is a colon separated list of directories to search when 
  13538.  executing subprograms.  Its initial value is taken from the environment 
  13539.  variable OCTAVE_EXEC_PATH (if it exists) or PATH, but that value can be 
  13540.  overridden by the command line argument --exec-path PATH, or by setting the 
  13541.  value of EXEC_PATH in a startup script.  If the value of EXEC_PATH begins 
  13542.  (ends) with a colon, the directories 
  13543.  
  13544.   octave-home/libexec/octave/site/exec/arch
  13545.   octave-home/libexec/octave/version/exec/arch
  13546.  
  13547.  are prepended (appended) to EXEC_PATH, where octave-home is the top-level 
  13548.  directory where all of Octave is installed (the default value is `*').  If you 
  13549.  don't specify a value for EXEC_PATH explicitly, these special directories are 
  13550.  prepended to your shell path. 
  13551.  
  13552.  In most cases, the following functions simply decode their arguments and make 
  13553.  the corresponding Unix system calls.  For a complete example of how they can 
  13554.  be used, look at the definition of the function popen2. 
  13555.  
  13556.  Built-in Function: [pid, msg] = fork () 
  13557.  Create a copy of the current process. 
  13558.  
  13559.  Fork can return one of the following values: 
  13560.  
  13561.  > 0 
  13562.            You are in the parent process.  The value returned from fork is the 
  13563.            process id of the child process.  You should probably arrange to 
  13564.            wait for any child processes to exit. 
  13565.  
  13566.  0 
  13567.            You are in the child process.  You can call exec to start another 
  13568.            process.  If that fails, you should probably call exit. 
  13569.  
  13570.  < 0 
  13571.            The call to fork failed for some reason.  You must take evasive 
  13572.            action.  A system dependent error message will be waiting in msg. 
  13573.  
  13574.  Built-in Function: [err, msg] = exec (file, args) 
  13575.  Replace current process with a new process.  Calling exec without first 
  13576.  calling fork will terminate your current Octave process and replace it with 
  13577.  the program named by file.  For example, 
  13578.  
  13579.   exec ("ls" "-l")
  13580.  
  13581.  will run ls and return you to your shell prompt. 
  13582.  
  13583.  If successful, exec does not return.  If exec does return, err will be 
  13584.  nonzero, and msg will contain a system-dependent error message. 
  13585.  
  13586.  Built-in Function: [file_ids, err, msg] = pipe () 
  13587.  Create a pipe and return the vector file_ids, which corresponding to the 
  13588.  reading and writing ends of the pipe. 
  13589.  
  13590.  If successful, err is 0 and msg is an empty string. Otherwise, err is nonzero 
  13591.  and msg contains a system-dependent error message. 
  13592.  
  13593.  Built-in Function: [fid, msg] = dup2 (old, new) 
  13594.  Duplicate a file descriptor. 
  13595.  
  13596.  If successful, fid is greater than zero and contains the new file ID. 
  13597.  Otherwise, fid is negative and msg contains a system-dependent error message. 
  13598.  
  13599.  Built-in Function: [pid, msg] = waitpid (pid, options) 
  13600.  Wait for process pid to terminate.  The pid argument can be: 
  13601.  
  13602.  -1 
  13603.            Wait for any child process. 
  13604.  
  13605.  0 
  13606.            Wait for any child process whose process group ID is equal to that 
  13607.            of the Octave interpreter process. 
  13608.  
  13609.  > 0 
  13610.            Wait for termination of the child process with ID pid. 
  13611.  
  13612.  The options argument can be: 
  13613.  
  13614.  0 
  13615.            Wait until signal is received or a child process exits (this is the 
  13616.            default if the options argument is missing). 
  13617.  
  13618.  1 
  13619.            Do not hang if status is not immediately available. 
  13620.  
  13621.  2 
  13622.            Report the status of any child processes that are stopped, and whose 
  13623.            status has not yet been reported since they stopped. 
  13624.  
  13625.  3 
  13626.            Implies both 1 and 2. 
  13627.  
  13628.  If the returned value of pid is greater than 0, it is the process ID of the 
  13629.  child process that exited.  If an error occurs, pid will be less than zero and 
  13630.  msg will contain a system-dependent error message. 
  13631.  
  13632.  Built-in Function: [err, msg] = fcntl (fid, request, arg) 
  13633.  Change the properties of the open file fid.  The following values may be 
  13634.  passed as request: 
  13635.  
  13636.  F_DUPFD 
  13637.            Return a duplicate file descriptor. 
  13638.  
  13639.  F_GETFD 
  13640.            Return the file descriptor flags for fid. 
  13641.  
  13642.  F_SETFD 
  13643.            Set the file descriptor flags for fid. 
  13644.  
  13645.  F_GETFL 
  13646.            Return the file status flags for fid.  The following codes may be 
  13647.            returned (some of the flags may be undefined on some systems). 
  13648.  
  13649.            *O_RDONLY* 
  13650.                           Open for reading only. 
  13651.  
  13652.            *O_WRONLY* 
  13653.                           Open for writing only. 
  13654.  
  13655.            *O_RDWR* 
  13656.                           Open for reading and writing. 
  13657.  
  13658.            *O_APPEND* 
  13659.                           Append on each write. 
  13660.  
  13661.            *O_NONBLOCK* 
  13662.                           Nonblocking mode. 
  13663.  
  13664.            *O_SYNC* 
  13665.                           Wait for writes to complete. 
  13666.  
  13667.            *O_ASYNC* 
  13668.                           Asynchronous I/O. 
  13669.  
  13670.  F_SETFL 
  13671.            Set the file status flags for fid to the value specified by arg. 
  13672.            The only flags that can be changed are O_APPEND and O_NONBLOCK. 
  13673.  
  13674.  If successful, err is 0 and msg is an empty string. Otherwise, err is nonzero 
  13675.  and msg contains a system-dependent error message. 
  13676.  
  13677.  
  13678. ΓòÉΓòÉΓòÉ 62.4. Process, Group, and User IDs ΓòÉΓòÉΓòÉ
  13679.  
  13680. Built-in Function:  getpgrp () 
  13681. Return the process group id of the current process. 
  13682.  
  13683. Built-in Function:  getpid () 
  13684. Return the process id of the current process. 
  13685.  
  13686. Built-in Function:  getppid () 
  13687. Return the process id of the parent process. 
  13688.  
  13689. Built-in Function:  geteuid () 
  13690. Return the effective user id of the current process. 
  13691.  
  13692. Built-in Function:  getuid () 
  13693. Return the real user id of the current process. 
  13694.  
  13695. Built-in Function:  getegid () 
  13696. Return the effective group id of the current process. 
  13697.  
  13698. Built-in Function:  getgid () 
  13699. Return the real group id of the current process. 
  13700.  
  13701.  
  13702. ΓòÉΓòÉΓòÉ 62.5. Environment Variables ΓòÉΓòÉΓòÉ
  13703.  
  13704. Built-in Function:  getenv (var) 
  13705. Return the value of the environment variable var.  For example, 
  13706.  
  13707. getenv ("PATH")
  13708.  
  13709. returns a string containing the value of your path. 
  13710.  
  13711. Built-in Function:  putenv (var, value) 
  13712. Set the value of the environment variable var to value. 
  13713.  
  13714.  
  13715. ΓòÉΓòÉΓòÉ 62.6. Current Working Directory ΓòÉΓòÉΓòÉ
  13716.  
  13717. Command: cd dir 
  13718.  
  13719. Command: chdir dir 
  13720. Change the current working directory to dir.  For example, 
  13721.  
  13722. cd ~/octave
  13723.  
  13724. Changes the current working directory to `~/octave'.  If the directory does not 
  13725. exist, an error message is printed and the working directory is not changed. 
  13726.  
  13727. Built-in Function:  pwd () 
  13728. Return the current working directory. 
  13729.  
  13730. Command: ls options 
  13731.  
  13732. Command: dir options 
  13733. List directory contents.  For example, 
  13734.  
  13735. ls -l
  13736.      -| total 12
  13737.      -| -rw-r--r--   1 jwe  users  4488 Aug 19 04:02 foo.m
  13738.      -| -rw-r--r--   1 jwe  users  1315 Aug 17 23:14 bar.m
  13739.  
  13740. The dir and ls commands are implemented by calling your system's directory 
  13741. listing command, so the available options may vary from system to system. 
  13742.  
  13743.  
  13744. ΓòÉΓòÉΓòÉ 62.7. Password Database Functions ΓòÉΓòÉΓòÉ
  13745.  
  13746. Octave's password database functions return information in a structure with the 
  13747. following fields. 
  13748.  
  13749.  name 
  13750.            The user name. 
  13751.  
  13752.  passwd 
  13753.            The encrypted password, if available. 
  13754.  
  13755.  uid 
  13756.            The numeric user id. 
  13757.  
  13758.  gid 
  13759.            The numeric group id. 
  13760.  
  13761.  gecos 
  13762.            The GECOS field. 
  13763.  
  13764.  dir 
  13765.            The home directory. 
  13766.  
  13767.  shell 
  13768.            The initial shell. 
  13769.  
  13770.  In the descriptions of the following functions, this data structure is 
  13771.  referred to as a pw_struct. 
  13772.  
  13773.  Loadable Function: pw_struct =  getpwent () 
  13774.  Return a structure containing an entry from the password database, opening it 
  13775.  if necessary. Once the end of the data has been reached, getpwent returns 0. 
  13776.  
  13777.  Loadable Function: pw_struct =  getpwuid (uid). 
  13778.  Return a structure containing the first entry from the password database with 
  13779.  the user ID uid.  If the user ID does not exist in the database, getpwuid 
  13780.  returns 0. 
  13781.  
  13782.  Loadable Function: pw_struct =  getpwnam (name) 
  13783.  Return a structure containing the first entry from the password database with 
  13784.  the user name name.  If the user name does not exist in the database, 
  13785.  getpwname returns 0. 
  13786.  
  13787.  Loadable Function:  setpwent () 
  13788.  Return the internal pointer to the beginning of the password database. 
  13789.  
  13790.  Loadable Function:  endpwent () 
  13791.  Close the password database. 
  13792.  
  13793.  
  13794. ΓòÉΓòÉΓòÉ 62.8. Group Database Functions ΓòÉΓòÉΓòÉ
  13795.  
  13796. Octave's group database functions return information in a structure with the 
  13797. following fields. 
  13798.  
  13799.  name 
  13800.            The user name. 
  13801.  
  13802.  passwd 
  13803.            The encrypted password, if available. 
  13804.  
  13805.  gid 
  13806.            The numeric group id. 
  13807.  
  13808.  mem 
  13809.            The members of the group. 
  13810.  
  13811.  In the descriptions of the following functions, this data structure is 
  13812.  referred to as a grp_struct. 
  13813.  
  13814.  Loadable Function: grp_struct = getgrent () 
  13815.  Return an entry from the group database, opening it if necessary. Once the end 
  13816.  of the data has been reached, getgrent returns 0. 
  13817.  
  13818.  Loadable Function: grp_struct = getgrgid (gid). 
  13819.  Return the first entry from the group database with the group ID gid.  If the 
  13820.  group ID does not exist in the database, getgrgid returns 0. 
  13821.  
  13822.  Loadable Function: grp_struct = getgrnam (name) 
  13823.  Return the first entry from the group database with the group name name.  If 
  13824.  the group name does not exist in the database, getgrname returns 0. 
  13825.  
  13826.  Loadable Function:  setgrent () 
  13827.  Return the internal pointer to the beginning of the group database. 
  13828.  
  13829.  Loadable Function:  endgrent () 
  13830.  Close the group database. 
  13831.  
  13832.  
  13833. ΓòÉΓòÉΓòÉ 62.9. System Information ΓòÉΓòÉΓòÉ
  13834.  
  13835. Built-in Function:  computer () 
  13836. Print or return a string of the form cpu-vendor-os that identifies the kind of 
  13837. computer Octave is running on.  If invoked with an output argument, the value 
  13838. is returned instead of printed.  For example, 
  13839.  
  13840. computer ()
  13841.      -| i586-pc-linux-gnu
  13842.  
  13843. x = computer ()
  13844.      => x = "i586-pc-linux-gnu"
  13845.  
  13846. Built-in Function:  isieee () 
  13847. Return 1 if your computer claims to conform to the IEEE standard for floating 
  13848. point calculations. 
  13849.  
  13850. Built-in Function:  version () 
  13851. Return Octave's version number as a string.  This is also the value of the 
  13852. built-in variable OCTAVE_VERSION. 
  13853.  
  13854. Built-in Variable: OCTAVE_VERSION 
  13855. The version number of Octave, as a string. 
  13856.  
  13857. Built-in Function:  octave_config_info () 
  13858. Return a structure containing configuration and installation information. 
  13859.  
  13860. Loadable Function:  getrusage () 
  13861. Return a structure containing a number of statistics about the current Octave 
  13862. process.  Not all fields are available on all systems.  If it is not possible 
  13863. to get CPU time statistics, the CPU time slots are set to zero.  Other missing 
  13864. data are replaced by NaN.  Here is a list of all the possible fields that can 
  13865. be present in the structure returned by getrusage: 
  13866.  
  13867.  idrss 
  13868.            Unshared data size. 
  13869.  
  13870.  inblock 
  13871.            Number of block input operations. 
  13872.  
  13873.  isrss 
  13874.            Unshared stack size. 
  13875.  
  13876.  ixrss 
  13877.            Shared memory size. 
  13878.  
  13879.  majflt 
  13880.            Number of major page faults. 
  13881.  
  13882.  maxrss 
  13883.            Maximum data size. 
  13884.  
  13885.  minflt 
  13886.            Number of minor page faults. 
  13887.  
  13888.  msgrcv 
  13889.            Number of messages received. 
  13890.  
  13891.  msgsnd 
  13892.            Number of messages sent. 
  13893.  
  13894.  nivcsw 
  13895.            Number of involuntary context switches. 
  13896.  
  13897.  nsignals 
  13898.            Number of signals received. 
  13899.  
  13900.  nswap 
  13901.            Number of swaps. 
  13902.  
  13903.  nvcsw 
  13904.            Number of voluntary context switches. 
  13905.  
  13906.  oublock 
  13907.            Number of block output operations. 
  13908.  
  13909.  stime 
  13910.            A structure containing the system CPU time used.  The structure has 
  13911.            the elements sec (seconds) usec (microseconds). 
  13912.  
  13913.  utime 
  13914.            A structure containing the user CPU time used.  The structure has 
  13915.            the elements sec (seconds) usec (microseconds). 
  13916.  
  13917.  
  13918. ΓòÉΓòÉΓòÉ 63. Tips and Standards ΓòÉΓòÉΓòÉ
  13919.  
  13920. This chapter describes no additional features of Octave.  Instead it gives 
  13921. advice on making effective use of the features described in the previous 
  13922. chapters. 
  13923.  
  13924.  Style Tips                              Writing clean and robust programs. 
  13925.  Coding Tips                             Making code run faster. 
  13926.  Documentation Tips                      Writing readable documentation 
  13927.                                          strings. 
  13928.  Comment Tips                            Conventions for writing comments. 
  13929.  Function Headers                        Standard headers for functions. 
  13930.  
  13931.  
  13932. ΓòÉΓòÉΓòÉ 63.1. Writing Clean Octave Programs ΓòÉΓòÉΓòÉ
  13933.  
  13934. Here are some tips for avoiding common errors in writing Octave code intended 
  13935. for widespread use: 
  13936.  
  13937.      Since all global variables share the same name space, and all functions 
  13938.       share another name space, you should choose a short word to distinguish 
  13939.       your program from other Octave programs.  Then take care to begin the 
  13940.       names of all global variables, constants, and functions with the chosen 
  13941.       prefix.  This helps avoid name conflicts. 
  13942.  
  13943.       If you write a function that you think ought to be added to Octave under 
  13944.       a certain name, such as fiddle_matrix, don't call it by that name in your 
  13945.       program.  Call it mylib_fiddle_matrix in your program, and send mail to 
  13946.       bug-octave@bevo.che.wisc.edu suggesting that it be added to Octave.  If 
  13947.       and when it is, the name can be changed easily enough. 
  13948.  
  13949.       If one prefix is insufficient, your package may use two or three 
  13950.       alternative common prefixes, so long as they make sense. 
  13951.  
  13952.       Separate the prefix from the rest of the symbol name with an underscore 
  13953.       `_'.  This will be consistent with Octave itself and with most Octave 
  13954.       programs. 
  13955.  
  13956.      When you encounter an error condition, call the function error (or 
  13957.       usage).  The error and usage functions do not return. See Errors. 
  13958.  
  13959.      Please put a copyright notice on the file if you give copies to anyone. 
  13960.       Use the same lines that appear at the top of the function files 
  13961.       distributed with Octave.  If you have not signed papers to assign the 
  13962.       copyright to anyone else, then place your name in the copyright notice. 
  13963.  
  13964.  
  13965. ΓòÉΓòÉΓòÉ 63.2. Tips for Making Code Run Faster. ΓòÉΓòÉΓòÉ
  13966.  
  13967. Here are some ways of improving the execution speed of Octave programs. 
  13968.  
  13969.      Avoid looping wherever possible. 
  13970.  
  13971.      Use iteration rather than recursion whenever possible. Function calls are 
  13972.       slow in Octave. 
  13973.  
  13974.      Avoid resizing matrices unnecessarily.  When building a single result 
  13975.       matrix from a series of calculations, set the size of the result matrix 
  13976.       first, then insert values into it.  Write 
  13977.  
  13978.             result = zeros (big_n, big_m)
  13979.             for i = over:and_over
  13980.               r1 = ...
  13981.               r2 = ...
  13982.               result (r1, r2) = new_value ();
  13983.             endfor
  13984.  
  13985.       instead of 
  13986.  
  13987.             result = [];
  13988.             for i = ever:and_ever
  13989.               result = [ result, new_value() ];
  13990.             endfor
  13991.  
  13992.      Avoid calling eval or feval whenever possible, because they require 
  13993.       Octave to parse input or look up the name of a function in the symbol 
  13994.       table. 
  13995.  
  13996.       If you are using eval as an exception handling mechanism and not because 
  13997.       you need to execute some arbitrary text, use the try statement instead. 
  13998.       See The try Statement. 
  13999.  
  14000.      If you are calling lots of functions but none of them will need to change 
  14001.       during your run, set the variable ignore_function_time_stamp to "all" so 
  14002.       that Octave doesn't waste a lot of time checking to see if you have 
  14003.       updated your function files. 
  14004.  
  14005.  
  14006. ΓòÉΓòÉΓòÉ 63.3. Tips for Documentation Strings ΓòÉΓòÉΓòÉ
  14007.  
  14008. Here are some tips for the writing of documentation strings. 
  14009.  
  14010.      Every command, function, or variable intended for users to know about 
  14011.       should have a documentation string. 
  14012.  
  14013.      An internal variable or subroutine of an Octave program might as well 
  14014.       have a documentation string. 
  14015.  
  14016.      The first line of the documentation string should consist of one or two 
  14017.       complete sentences that stand on their own as a summary. 
  14018.  
  14019.       The documentation string can have additional lines that expand on the 
  14020.       details of how to use the function or variable.  The additional lines 
  14021.       should also be made up of complete sentences. 
  14022.  
  14023.      For consistency, phrase the verb in the first sentence of a documentation 
  14024.       string as an infinitive with ``to'' omitted.  For instance, use ``Return 
  14025.       the frob of A and B.'' in preference to ``Returns the frob of A and B.'' 
  14026.       Usually it looks good to do likewise for the rest of the first paragraph. 
  14027.       Subsequent paragraphs usually look better if they have proper subjects. 
  14028.  
  14029.      Write documentation strings in the active voice, not the passive, and in 
  14030.       the present tense, not the future.  For instance, use ``Return a list 
  14031.       containing A and B.'' instead of ``A list containing A and B will be 
  14032.       returned.'' 
  14033.  
  14034.      Avoid using the word ``cause'' (or its equivalents) unnecessarily. 
  14035.       Instead of, ``Cause Octave to display text in boldface,'' write just 
  14036.       ``Display text in boldface.'' 
  14037.  
  14038.      Do not start or end a documentation string with whitespace. 
  14039.  
  14040.      Format the documentation string so that it fits in an Emacs window on an 
  14041.       80-column screen.  It is a good idea for most lines to be no wider than 
  14042.       60 characters. 
  14043.  
  14044.       However, rather than simply filling the entire documentation string, you 
  14045.       can make it much more readable by choosing line breaks with care. Use 
  14046.       blank lines between topics if the documentation string is long. 
  14047.  
  14048.      *Do not* indent subsequent lines of a documentation string so that the 
  14049.       text is lined up in the source code with the text of the first line. 
  14050.       This looks nice in the source code, but looks bizarre when users view the 
  14051.       documentation.  Remember that the indentation before the starting 
  14052.       double-quote is not part of the string! 
  14053.  
  14054.      The documentation string for a variable that is a yes-or-no flag should 
  14055.       start with words such as ``Nonzero means...'', to make it clear that all 
  14056.       nonzero values are equivalent and indicate explicitly what zero and 
  14057.       nonzero mean. 
  14058.  
  14059.      When a function's documentation string mentions the value of an argument 
  14060.       of the function, use the argument name in capital letters as if it were a 
  14061.       name for that value.  Thus, the documentation string of the operator / 
  14062.       refers to its second argument as `DIVISOR', because the actual argument 
  14063.       name is divisor. 
  14064.  
  14065.       Also use all caps for meta-syntactic variables, such as when you show the 
  14066.       decomposition of a list or vector into subunits, some of which may vary. 
  14067.  
  14068.  
  14069. ΓòÉΓòÉΓòÉ 63.4. Tips on Writing Comments ΓòÉΓòÉΓòÉ
  14070.  
  14071. Here are the conventions to follow when writing comments. 
  14072.  
  14073.  `#' 
  14074.            Comments that start with a single sharp-sign, `#', should all be 
  14075.            aligned to the same column on the right of the source code.  Such 
  14076.            comments usually explain how the code on the same line does its job. 
  14077.            In the Emacs mode for Octave, the M-; (indent-for-comment) command 
  14078.            automatically inserts such a `#' in the right place, or aligns such 
  14079.            a comment if it is already present. 
  14080.  
  14081.  `##' 
  14082.            Comments that start with two semicolons, `##', should be aligned to 
  14083.            the same level of indentation as the code.  Such comments usually 
  14084.            describe the purpose of the following lines or the state of the 
  14085.            program at that point. 
  14086.  
  14087.  The indentation commands of the Octave mode in Emacs, such as M-; 
  14088.  (indent-for-comment) and TAB (octave-indent-line) automatically indent 
  14089.  comments according to these conventions, depending on the number of 
  14090.  semicolons. See Manipulating Comments. 
  14091.  
  14092.  
  14093. ΓòÉΓòÉΓòÉ 63.5. Conventional Headers for Octave Functions ΓòÉΓòÉΓòÉ
  14094.  
  14095. Octave has conventions for using special comments in function files to give 
  14096. information such as who wrote them.  This section explains these conventions. 
  14097.  
  14098. The top of the file should contain a copyright notice, followed by a block of 
  14099. comments that can be used as the help text for the function. Here is an 
  14100. example: 
  14101.  
  14102. ## Copyright (C) 1996, 1997 John W. Eaton
  14103. ##
  14104. ## This file is part of Octave.
  14105. ##
  14106. ## Octave is free software; you can redistribute it and/or
  14107. ## modify it under the terms of the GNU General Public
  14108. ## License as published by the Free Software Foundation;
  14109. ## either version 2, or (at your option) any later version.
  14110. ##
  14111. ## Octave is distributed in the hope that it will be useful,
  14112. ## but WITHOUT ANY WARRANTY; without even the implied
  14113. ## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  14114. ## PURPOSE.  See the GNU General Public License for more
  14115. ## details.
  14116. ##
  14117. ## You should have received a copy of the GNU General Public
  14118. ## License along with Octave; see the file COPYING.  If not,
  14119. ## write to the Free Software Foundation, 59 Temple Place -
  14120. ## Suite 330, Boston, MA 02111-1307, USA.
  14121.  
  14122. ## usage: [IN, OUT, PID] = popen2 (COMMAND, ARGS)
  14123. ##
  14124. ## Start a subprocess with two-way communication.  COMMAND
  14125. ## specifies the name of the command to start.  ARGS is an
  14126. ## array of strings containing options for COMMAND.  IN and
  14127. ## OUT are the file ids of the input and streams for the
  14128. ## subprocess, and PID is the process id of the subprocess,
  14129. ## or -1 if COMMAND could not be executed.
  14130. ##
  14131. ## Example:
  14132. ##
  14133. ##  [in, out, pid] = popen2 ("sort", "-nr");
  14134. ##  fputs (in, "these\nare\nsome\nstrings\n");
  14135. ##  fclose (in);
  14136. ##  while (isstr (s = fgets (out)))
  14137. ##    fputs (stdout, s);
  14138. ##  endwhile
  14139. ##  fclose (out);
  14140.  
  14141. Octave uses the first block of comments in a function file that do not appear 
  14142. to be a copyright notice as the help text for the file.  For Octave to 
  14143. recognize the first comment block as a copyright notice, it must match the 
  14144. regular expression 
  14145.  
  14146. ^ Copyright (C).*\n\n This file is part of Octave.
  14147.  
  14148. or 
  14149.  
  14150. ^ Copyright (C).*\n\n This program is free softwar
  14151.  
  14152. (after stripping the leading comment characters).  This is a fairly strict 
  14153. requirement, and may be relaxed somewhat in the future. 
  14154.  
  14155. After the copyright notice and help text come several header comment lines, 
  14156. each beginning with `## header-name:'.  For example, 
  14157.  
  14158. ## Author: jwe
  14159. ## Keywords: subprocesses input-output
  14160. ## Maintainer: jwe
  14161.  
  14162. Here is a table of the conventional possibilities for header-name: 
  14163.  
  14164.  `Author' 
  14165.            This line states the name and net address of at least the principal 
  14166.            author of the library. 
  14167.  
  14168.                       ## Author: John W. Eaton <jwe@bevo.che.wisc.edu>
  14169.  
  14170.  `Maintainer' 
  14171.            This line should contain a single name/address as in the Author 
  14172.            line, or an address only, or the string `jwe'.  If there is no 
  14173.            maintainer line, the person(s) in the Author field are presumed to 
  14174.            be the maintainers.  The example above is mildly bogus because the 
  14175.            maintainer line is redundant. 
  14176.  
  14177.            The idea behind the `Author' and `Maintainer' lines is to make 
  14178.            possible a function to ``send mail to the maintainer'' without 
  14179.            having to mine the name out by hand. 
  14180.  
  14181.            Be sure to surround the network address with `<...>' if you include 
  14182.            the person's full name as well as the network address. 
  14183.  
  14184.  `Created' 
  14185.            This optional line gives the original creation date of the file. 
  14186.            For historical interest only. 
  14187.  
  14188.  `Version' 
  14189.            If you wish to record version numbers for the individual Octave 
  14190.            program, put them in this line. 
  14191.  
  14192.  `Adapted-By' 
  14193.            In this header line, place the name of the person who adapted the 
  14194.            library for installation (to make it fit the style conventions, for 
  14195.            example). 
  14196.  
  14197.  `Keywords' 
  14198.            This line lists keywords.  Eventually, it will be used by an apropos 
  14199.            command to allow people will find your package when they're looking 
  14200.            for things by topic area.  To separate the keywords, you can use 
  14201.            spaces, commas, or both. 
  14202.  
  14203.  Just about every Octave function ought to have the `Author' and `Keywords' 
  14204.  header comment lines.  Use the others if they are appropriate.  You can also 
  14205.  put in header lines with other header names---they have no standard meanings, 
  14206.  so they can't do any harm. 
  14207.  
  14208.  
  14209. ΓòÉΓòÉΓòÉ 64. Known Causes of Trouble ΓòÉΓòÉΓòÉ
  14210.  
  14211. This section describes known problems that affect users of Octave.  Most of 
  14212. these are not Octave bugs per se---if they were, we would fix them. But the 
  14213. result for a user may be like the result of a bug. 
  14214.  
  14215. Some of these problems are due to bugs in other software, some are missing 
  14216. features that are too much work to add, and some are places where people's 
  14217. opinions differ as to what is best. 
  14218.  
  14219.  Actual Bugs                             Bugs we will fix later. 
  14220.  Reporting Bugs 
  14221.  Bug Criteria 
  14222.  Bug Lists 
  14223.  Bug Reporting 
  14224.  Sending Patches 
  14225.  Service 
  14226.  
  14227.  
  14228. ΓòÉΓòÉΓòÉ 64.1. Actual Bugs We Haven't Fixed Yet ΓòÉΓòÉΓòÉ
  14229.  
  14230.      Output that comes directly from Fortran functions is not sent through the 
  14231.       pager and may appear out of sequence with other output that is sent 
  14232.       through the pager.  One way to avoid this is to force pending output to 
  14233.       be flushed before calling a function that will produce output from within 
  14234.       Fortran functions.  To do this, use the command 
  14235.  
  14236.             fflush (stdout)
  14237.  
  14238.       Another possible workaround is to use the command 
  14239.  
  14240.             page_screen_output = "false"
  14241.  
  14242.       to turn the pager off. 
  14243.  
  14244.      If you get messages like 
  14245.  
  14246.             Input line too long
  14247.  
  14248.       when trying to plot many lines on one graph, you have probably generated 
  14249.       a plot command that is too larger for gnuplot's fixed-length buffer for 
  14250.       commands.  Splitting up the plot command doesn't help because replot is 
  14251.       implemented in gnuplot by simply appending the new plotting commands to 
  14252.       the old command line and then evaluating it again. 
  14253.  
  14254.       You can demonstrate this `feature' by running gnuplot and doing something 
  14255.       like 
  14256.  
  14257.               plot sin (x), sin (x), sin (x), ... lots more ..., sin (x)
  14258.  
  14259.       and then 
  14260.  
  14261.               replot sin (x), sin (x), sin (x), ... lots more ..., sin (x)
  14262.  
  14263.       after repeating the replot command a few times, gnuplot will give you an 
  14264.       error. 
  14265.  
  14266.       Also, it doesn't help to use backslashes to enter a plot command over 
  14267.       several lines, because the limit is on the overall command line length, 
  14268.       once the backslashed lines are all pasted together. 
  14269.  
  14270.       Because of this, Octave tries to use as little of the command-line length 
  14271.       as possible by using the shortest possible abbreviations for all the plot 
  14272.       commands and options.  Unfortunately, the length of the temporary file 
  14273.       names is probably what is taking up the most space on the command line. 
  14274.  
  14275.       You can buy a little bit of command line space by setting the environment 
  14276.       variable TMPDIR to be "." before starting Octave, or you can increase the 
  14277.       maximum command line length in gnuplot by changing the following limits 
  14278.       in the file plot.h in the gnuplot distribution and recompiling gnuplot. 
  14279.  
  14280.             #define MAX_LINE_LEN 32768  /* originally 1024 */
  14281.             #define MAX_TOKENS 8192     /* originally 400 */
  14282.  
  14283.       Of course, this doesn't really fix the problem, but it does make it much 
  14284.       less likely that you will run into trouble unless you are putting a very 
  14285.       large number of lines on a given plot. 
  14286.  
  14287.  A list of ideas for future enhancements is distributed with Octave.  See the 
  14288.  file `PROJECTS' in the top level directory in the source distribution. 
  14289.  
  14290.  
  14291. ΓòÉΓòÉΓòÉ 64.2. Reporting Bugs ΓòÉΓòÉΓòÉ
  14292.  
  14293. Your bug reports play an essential role in making Octave reliable. 
  14294.  
  14295. When you encounter a problem, the first thing to do is to see if it is already 
  14296. known.  See Trouble.  If it isn't known, then you should report the problem. 
  14297.  
  14298. Reporting a bug may help you by bringing a solution to your problem, or it may 
  14299. not.  In any case, the principal function of a bug report is to help the entire 
  14300. community by making the next version of Octave work better.  Bug reports are 
  14301. your contribution to the maintenance of Octave. 
  14302.  
  14303. In order for a bug report to serve its purpose, you must include the 
  14304. information that makes it possible to fix the bug. 
  14305.  
  14306. If you have Octave working at all, the easiest way to prepare a complete bug 
  14307. report is to use the Octave function bug_report.  When you execute this 
  14308. function, Octave will prompt you for a subject and then invoke the editor on a 
  14309. file that already contains all the configuration information.  When you exit 
  14310. the editor, Octave will mail the bug report for you. 
  14311.  
  14312.  Bug Criteria 
  14313.  * Where: Bug Lists.       Where to send your bug report. * Reporting: Bug 
  14314.  Reporting.   How to report a bug effectively. * Patches: Sending Patches. 
  14315.  How to send a patch for Octave. 
  14316.  
  14317.  
  14318. ΓòÉΓòÉΓòÉ 64.3. Have You Found a Bug? ΓòÉΓòÉΓòÉ
  14319.  
  14320. If you are not sure whether you have found a bug, here are some guidelines: 
  14321.  
  14322.      If Octave gets a fatal signal, for any input whatever, that is a bug. 
  14323.       Reliable interpreters never crash. 
  14324.  
  14325.      If Octave produces incorrect results, for any input whatever, that is a 
  14326.       bug. 
  14327.  
  14328.      Some output may appear to be incorrect when it is in fact due to a 
  14329.       program whose behavior is undefined, which happened by chance to give the 
  14330.       desired results on another system.  For example, the range operator may 
  14331.       produce different results because of differences in the way floating 
  14332.       point arithmetic is handled on various systems. 
  14333.  
  14334.      If Octave produces an error message for valid input, that is a bug. 
  14335.  
  14336.      If Octave does not produce an error message for invalid input, that is a 
  14337.       bug.  However, you should note that your idea of ``invalid input'' might 
  14338.       be my idea of ``an extension'' or ``support for traditional practice''. 
  14339.  
  14340.      If you are an experienced user of programs like Octave, your suggestions 
  14341.       for improvement are welcome in any case. 
  14342.  
  14343.  
  14344. ΓòÉΓòÉΓòÉ 64.4. Where to Report Bugs ΓòÉΓòÉΓòÉ
  14345.  
  14346. If you have Octave working at all, the easiest way to prepare a complete bug 
  14347. report is to use the Octave function bug_report.  When you execute this 
  14348. function, Octave will prompt you for a subject and then invoke the editor on a 
  14349. file that already contains all the configuration information.  When you exit 
  14350. the editor, Octave will mail the bug report for you. 
  14351.  
  14352. If for some reason you cannot use Octave's bug_report function, send bug 
  14353. reports for Octave to bug-octave@bevo.che.wisc.edu. 
  14354.  
  14355. *Do not send bug reports to `help-octave'*.  Most users of Octave do not want 
  14356. to receive bug reports.  Those that do have asked to be on the mailing list. 
  14357.  
  14358. As a last resort, send bug reports on paper to: 
  14359.  
  14360. Octave Bugs c/o John W. Eaton
  14361. University of Wisconsin-Madison
  14362. Department of Chemical Engineering
  14363. 1415 Engineering Drive
  14364. Madison, Wisconsin 53706  USA
  14365.  
  14366.  
  14367. ΓòÉΓòÉΓòÉ 64.5. How to Report Bugs ΓòÉΓòÉΓòÉ
  14368.  
  14369. Send bug reports for Octave to one of the addresses listed in Bug Lists. 
  14370.  
  14371. The fundamental principle of reporting bugs usefully is this: *report all the 
  14372. facts*.  If you are not sure whether to state a fact or leave it out, state it! 
  14373.  
  14374. Often people omit facts because they think they know what causes the problem 
  14375. and they conclude that some details don't matter.  Thus, you might assume that 
  14376. the name of the variable you use in an example does not matter. Well, probably 
  14377. it doesn't, but one cannot be sure.  Perhaps the bug is a stray memory 
  14378. reference which happens to fetch from the location where that name is stored in 
  14379. memory; perhaps, if the name were different, the contents of that location 
  14380. would fool the interpreter into doing the right thing despite the bug.  Play it 
  14381. safe and give a specific, complete example. 
  14382.  
  14383. Keep in mind that the purpose of a bug report is to enable someone to fix the 
  14384. bug if it is not known. Always write your bug reports on the assumption that 
  14385. the bug is not known. 
  14386.  
  14387. Sometimes people give a few sketchy facts and ask, ``Does this ring a bell?'' 
  14388. This cannot help us fix a bug.  It is better to send a complete bug report to 
  14389. begin with. 
  14390.  
  14391. Try to make your bug report self-contained.  If we have to ask you for more 
  14392. information, it is best if you include all the previous information in your 
  14393. response, as well as the information that was missing. 
  14394.  
  14395. To enable someone to investigate the bug, you should include all these things: 
  14396.  
  14397.      The version of Octave.  You can get this by noting the version number 
  14398.       that is printed when Octave starts, or running it with the `-v' option. 
  14399.  
  14400.      A complete input file that will reproduce the bug. 
  14401.  
  14402.       A single statement may not be enough of an example---the bug might depend 
  14403.       on other details that are missing from the single statement where the 
  14404.       error finally occurs. 
  14405.  
  14406.      The command arguments you gave Octave to execute that example and observe 
  14407.       the bug.  To guarantee you won't omit something important, list all the 
  14408.       options. 
  14409.  
  14410.       If we were to try to guess the arguments, we would probably guess wrong 
  14411.       and then we would not encounter the bug. 
  14412.  
  14413.      The type of machine you are using, and the operating system name and 
  14414.       version number. 
  14415.  
  14416.      The command-line arguments you gave to the configure command when you 
  14417.       installed the interpreter. 
  14418.  
  14419.      A complete list of any modifications you have made to the interpreter 
  14420.       source. 
  14421.  
  14422.       Be precise about these changes---show a context diff for them. 
  14423.  
  14424.      Details of any other deviations from the standard procedure for 
  14425.       installing Octave. 
  14426.  
  14427.      A description of what behavior you observe that you believe is incorrect. 
  14428.       For example, "The interpreter gets a fatal signal," or, "The output 
  14429.       produced at line 208 is incorrect." 
  14430.  
  14431.       Of course, if the bug is that the interpreter gets a fatal signal, then 
  14432.       one can't miss it.  But if the bug is incorrect output, we might not 
  14433.       notice unless it is glaringly wrong. 
  14434.  
  14435.       Even if the problem you experience is a fatal signal, you should still 
  14436.       say so explicitly.  Suppose something strange is going on, such as, your 
  14437.       copy of the interpreter is out of synch, or you have encountered a bug in 
  14438.       the C library on your system.  Your copy might crash and the copy here 
  14439.       would not.  If you said to expect a crash, then when the interpreter here 
  14440.       fails to crash, we would know that the bug was not happening.  If you 
  14441.       don't say to expect a crash, then we would not know whether the bug was 
  14442.       happening.  We would not be able to draw any conclusion from our 
  14443.       observations. 
  14444.  
  14445.       Often the observed symptom is incorrect output when your program is run. 
  14446.       Unfortunately, this is not enough information unless the program is short 
  14447.       and simple.  It is very helpful if you can include an explanation of the 
  14448.       expected output, and why the actual output is incorrect. 
  14449.  
  14450.      If you wish to suggest changes to the Octave source, send them as context 
  14451.       diffs.  If you even discuss something in the Octave source, refer to it 
  14452.       by context, not by line number, because the line numbers in the 
  14453.       development sources probably won't match those in your sources. 
  14454.  
  14455.  Here are some things that are not necessary: 
  14456.  
  14457.      A description of the envelope of the bug. 
  14458.  
  14459.       Often people who encounter a bug spend a lot of time investigating which 
  14460.       changes to the input file will make the bug go away and which changes 
  14461.       will not affect it.  Such information is usually not necessary to enable 
  14462.       us to fix bugs in Octave, but if you can find a simpler example to report 
  14463.       instead of the original one, that is a convenience. Errors in the output 
  14464.       will be easier to spot, running under the debugger will take less time, 
  14465.       etc. Most Octave bugs involve just one function, so the most 
  14466.       straightforward way to simplify an example is to delete all the function 
  14467.       definitions except the one in which the bug occurs. 
  14468.  
  14469.       However, simplification is not vital; if you don't want to do this, 
  14470.       report the bug anyway and send the entire test case you used. 
  14471.  
  14472.      A patch for the bug.  Patches can be helpful, but if you find a bug, you 
  14473.       should report it, even if you cannot send a fix for the problem. 
  14474.  
  14475.  
  14476. ΓòÉΓòÉΓòÉ 64.6. Sending Patches for Octave ΓòÉΓòÉΓòÉ
  14477.  
  14478. If you would like to write bug fixes or improvements for Octave, that is very 
  14479. helpful.  When you send your changes, please follow these guidelines to avoid 
  14480. causing extra work for us in studying the patches. 
  14481.  
  14482. If you don't follow these guidelines, your information might still be useful, 
  14483. but using it will take extra work.  Maintaining Octave is a lot of work in the 
  14484. best of circumstances, and we can't keep up unless you do your best to help. 
  14485.  
  14486.      Send an explanation with your changes of what problem they fix or what 
  14487.       improvement they bring about.  For a bug fix, just include a copy of the 
  14488.       bug report, and explain why the change fixes the bug. 
  14489.  
  14490.      Always include a proper bug report for the problem you think you have 
  14491.       fixed.  We need to convince ourselves that the change is right before 
  14492.       installing it.  Even if it is right, we might have trouble judging it if 
  14493.       we don't have a way to reproduce the problem. 
  14494.  
  14495.      Include all the comments that are appropriate to help people reading the 
  14496.       source in the future understand why this change was needed. 
  14497.  
  14498.      Don't mix together changes made for different reasons. Send them 
  14499.       individually. 
  14500.  
  14501.       If you make two changes for separate reasons, then we might not want to 
  14502.       install them both.  We might want to install just one. 
  14503.  
  14504.      Use `diff -c' to make your diffs.  Diffs without context are hard for us 
  14505.       to install reliably.  More than that, they make it hard for us to study 
  14506.       the diffs to decide whether we want to install them.  Unidiff format is 
  14507.       better than contextless diffs, but not as easy to read as `-c' format. 
  14508.  
  14509.       If you have GNU diff, use `diff -cp', which shows the name of the 
  14510.       function that each change occurs in. 
  14511.  
  14512.      Write the change log entries for your changes. 
  14513.  
  14514.       Read the `ChangeLog' file to see what sorts of information to put in, and 
  14515.       to learn the style that we use.  The purpose of the change log is to show 
  14516.       people where to find what was changed.  So you need to be specific about 
  14517.       what functions you changed; in large functions, it's often helpful to 
  14518.       indicate where within the function the change was made. 
  14519.  
  14520.       On the other hand, once you have shown people where to find the change, 
  14521.       you need not explain its purpose. Thus, if you add a new function, all 
  14522.       you need to say about it is that it is new.  If you feel that the purpose 
  14523.       needs explaining, it probably does---but the explanation will be much 
  14524.       more useful if you put it in comments in the code. 
  14525.  
  14526.       If you would like your name to appear in the header line for who made the 
  14527.       change, send us the header line. 
  14528.  
  14529.  
  14530. ΓòÉΓòÉΓòÉ 64.7. How To Get Help with Octave ΓòÉΓòÉΓòÉ
  14531.  
  14532. The mailing list help-octave@bevo.che.wisc.edu exists for the discussion of 
  14533. matters related to using and installing Octave.  If would like to join the 
  14534. discussion, please send a short note to 
  14535. help-octave*-request*@bevo.che.wisc.edu. 
  14536.  
  14537. *Please do not* send requests to be added or removed from the mailing list, or 
  14538. other administrative trivia to the list itself. 
  14539.  
  14540. If you think you have found a bug in the installation procedure, however, you 
  14541. should send a complete bug report for the problem to 
  14542. bug-octave@bevo.che.wisc.edu.  See Bug Reporting for information that will help 
  14543. you to submit a useful report. 
  14544.  
  14545.  
  14546. ΓòÉΓòÉΓòÉ 65. Installing Octave ΓòÉΓòÉΓòÉ
  14547.  
  14548. Here is the procedure for installing Octave from scratch on a Unix system.  For 
  14549. instructions on how to install the binary distributions of Octave, see Binary 
  14550. Distributions. 
  14551.  
  14552.      Run the shell script `configure'.  This will determine the features your 
  14553.       system has (or doesn't have) and create a file named `Makefile' from each 
  14554.       of the files named `Makefile.in'. 
  14555.  
  14556.       Here is a summary of the configure options that are most frequently used 
  14557.       when building Octave: 
  14558.  
  14559.       --prefix=prefix 
  14560.                      Install Octave in subdirectories below prefix.  The 
  14561.                      default value of prefix is `/usr/local'. 
  14562.  
  14563.       --srcdir=dir 
  14564.                      Look for Octave sources in the directory dir. 
  14565.  
  14566.       --with-f2c 
  14567.                      Use f2c even if a Fortran compiler is available. 
  14568.  
  14569.       --with-g77 
  14570.                      Use g77 to compile Fortran code. 
  14571.  
  14572.       --enable-shared 
  14573.                      Create shared libraries.  If you are planning to use 
  14574.                      --enable-lite-kernelel or the dynamic loading features, 
  14575.                      you will probably want to use this option.  It will make 
  14576.                      your `.oct' files much smaller and on some systems it may 
  14577.                      be necessary to build shared libraries in order to use 
  14578.                      dynamically linked functions. 
  14579.  
  14580.                      You may also want to build a shared version of libstdc++, 
  14581.                      if your system doesn't already have one.  Note that a 
  14582.                      patch is needed to build shared versions of version 2.7.2 
  14583.                      of libstdc++ on the HP-PA architecture.  You can find the 
  14584.                      patch at 
  14585.                      ftp://ftp.cygnus.com/pub/g++/libg++-2.7.2-hppa-gcc-fix. 
  14586.  
  14587.       --enable-dl 
  14588.                      Use dlopen and friends to make Octave capable of 
  14589.                      dynamically linking externally compiled functions.  This 
  14590.                      only works on systems that actually have these functions. 
  14591.                      If you plan on using this feature, you should probably 
  14592.                      also use --enable-shared to reduce the size of your `.oct' 
  14593.                      files. 
  14594.  
  14595.       --enable-shl 
  14596.                      Use shl_load and friends to make Octave capable of 
  14597.                      dynamically linking externally compiled functions.  This 
  14598.                      only works on systems that actually have these functions 
  14599.                      (only HP-UX systems).  If you plan on using this feature, 
  14600.                      you should probably also use --enable-shared to reduce the 
  14601.                      size of your `.oct' files. 
  14602.  
  14603.       --enable-lite-kernel 
  14604.                      Compile smaller kernel.  This currently requires the 
  14605.                      dynamic linking functions dlopen or shl_load and friends 
  14606.                      so that Octave can load functions at run time that are not 
  14607.                      loaded at compile time. 
  14608.  
  14609.       --help 
  14610.                      Print a summary of the options recognized by the configure 
  14611.                      script. 
  14612.  
  14613.       See the file `INSTALL' for more information about the command line 
  14614.       options used by configure.  That file also contains instructions for 
  14615.       compiling in a directory other than where the source is located. 
  14616.  
  14617.      Run make. 
  14618.  
  14619.       You will need a recent version of GNU Make.  Modifying Octave's makefiles 
  14620.       to work with other make programs is probably not worth your time.  We 
  14621.       recommend you get and compile GNU Make instead. 
  14622.  
  14623.       For plotting, you will need to have gnuplot installed on your system. 
  14624.       Gnuplot is a command-driven interactive function plotting program. 
  14625.       Gnuplot is copyrighted, but freely distributable.  The `gnu' in gnuplot 
  14626.       is a coincidence---it is not related to the GNU project or the FSF in any 
  14627.       but the most peripheral sense. 
  14628.  
  14629.       To compile Octave, you will need a recent version of GNU Make.  You will 
  14630.       also need g++ 2.7.2 or later.  Version 2.8.0 or egcs 1.0.x should work. 
  14631.       Later versions may work, but C++ is still evolving, so don't be too 
  14632.       surprised if you run into some trouble. 
  14633.  
  14634.       It is no longer necessary to have libg++, but you do need to have the GNU 
  14635.       implementation of libstdc++.  If you are using g++ 2.7.2, libstdc++ is 
  14636.       distributed along with libg++, but for later versions, libstdc++ is 
  14637.       distributed separately.  For egcs, libstdc++ is included with the 
  14638.       compiler distribution. 
  14639.  
  14640.       If you plan to modify the parser you will also need GNU bison and flex. 
  14641.       If you modify the documentation, you will need GNU Texinfo, along with 
  14642.       the patch for the makeinfo program that is distributed with Octave. 
  14643.  
  14644.       GNU Make, gcc, and libstdc++, gnuplot, bison, flex, and Texinfo are all 
  14645.       available from many anonymous ftp archives.  The primary site is 
  14646.       ftp.gnu.org, but it is often very busy.  A list of sites that mirror the 
  14647.       software on ftp.gnu.org is available by anonymous ftp from 
  14648.       ftp://ftp.gnu.org/pub/gnu/GNUinfo/FTP. 
  14649.  
  14650.       If you don't have a Fortran compiler, or if your Fortran compiler doesn't 
  14651.       work like the traditional Unix f77, you will need to have the Fortran to 
  14652.       C translator f2c.  You can get f2c from any number of anonymous ftp 
  14653.       archives.  The most recent version of f2c is always available from 
  14654.       netlib.att.com. 
  14655.  
  14656.       On an otherwise idle Pentium 133 running Linux, it will take somewhere 
  14657.       between 1-1/2 to 3 hours to compile everything, depending on whether you 
  14658.       are building shared libraries.  You will need about 100 megabytes of disk 
  14659.       storage to work with (considerably less if you don't compile with 
  14660.       debugging symbols).  To do that, use the command 
  14661.  
  14662.             make CFLAGS=-O CXXFLAGS=-O LDFLAGS=
  14663.  
  14664.       instead of just `make'. 
  14665.  
  14666.      If you encounter errors while compiling Octave, first check the list of 
  14667.       known problems below to see if there is a workaround or solution for your 
  14668.       problem.  If not, see Trouble, for information about how to report bugs. 
  14669.  
  14670.      Once you have successfully compiled Octave, run `make install'. 
  14671.  
  14672.       This will install a copy of octave, its libraries, and its documentation 
  14673.       in the destination directory.  As distributed, Octave is installed in the 
  14674.       following directories.  In the table below, prefix defaults to 
  14675.       `/usr/local', version stands for the current version number of the 
  14676.       interpreter, and arch is the type of computer on which Octave is 
  14677.       installed (for example, `i586-unknown-gnu'). 
  14678.  
  14679.       `prefix/bin' 
  14680.                      Octave and other binaries that people will want to run 
  14681.                      directly. 
  14682.  
  14683.       `prefix/lib' 
  14684.                      Libraries like libcruft.a and liboctave.a. 
  14685.  
  14686.       `prefix/share' 
  14687.                      Architecture-independent data files. 
  14688.  
  14689.       `prefix/include/octave' 
  14690.                      Include files distributed with Octave. 
  14691.  
  14692.       `prefix/man/man1' 
  14693.                      Unix-style man pages describing Octave. 
  14694.  
  14695.       `prefix/info' 
  14696.                      Info files describing Octave. 
  14697.  
  14698.       `prefix/share/octave/version/m' 
  14699.                      Function files distributed with Octave.  This includes the 
  14700.                      Octave version, so that multiple versions of Octave may be 
  14701.                      installed at the same time. 
  14702.  
  14703.       `prefix/lib/octave/version/exec/arch' 
  14704.                      Executables to be run by Octave rather than the user. 
  14705.  
  14706.       `prefix/lib/octave/version/oct/arch' 
  14707.                      Object files that will be dynamically loaded. 
  14708.  
  14709.       `prefix/share/octave/version/imagelib' 
  14710.                      Image files that are distributed with Octave. 
  14711.  
  14712.  Installation Problems 
  14713.  Binary Distributions 
  14714.  
  14715.  
  14716. ΓòÉΓòÉΓòÉ 65.1. Installation Problems ΓòÉΓòÉΓòÉ
  14717.  
  14718. This section contains a list of problems (and some apparent problems that don't 
  14719. really mean anything is wrong) that may show up during installation of Octave. 
  14720.  
  14721.      On some SCO systems, info fails to compile if HAVE_TERMIOS_H is defined 
  14722.       int `config.h'.  Simply removing the definition from `info/config.h' 
  14723.       should allow it to compile. 
  14724.  
  14725.      If configure finds dlopen, dlsym, dlclose, and dlerror, but not the 
  14726.       header file `dlfcn.h', you need to find the source for the header file 
  14727.       and install it in the directory `usr/include'.  This is reportedly a 
  14728.       problem with Slackware 3.1. For Linux/GNU systems, the source for 
  14729.       `dlfcn.h' is in the ldso package. 
  14730.  
  14731.      Building `.oct' files doesn't work. 
  14732.  
  14733.       You should probably have a shared version of libstdc++.  A patch is 
  14734.       needed to build shared versions of version 2.7.2 of libstdc++ on the 
  14735.       HP-PA architecture.  You can find the patch at 
  14736.       ftp://ftp.cygnus.com/pub/g++/libg++-2.7.2-hppa-gcc-fix. 
  14737.  
  14738.      On FreeBSD systems Octave may hang while initializing some internal 
  14739.       constants.  The fix appears to be to use 
  14740.  
  14741.             options      GPL_MATH_EMULATE
  14742.  
  14743.       rather than 
  14744.  
  14745.             options      MATH_EMULATE
  14746.  
  14747.       in the kernel configuration files (typically found in the directory 
  14748.       `/sys/i386/conf'.  After making this change, you'll need to rebuild the 
  14749.       kernel, install it, and reboot. 
  14750.  
  14751.      If you encounter errors like 
  14752.  
  14753.             passing `void (*)()' as argument 2 of
  14754.               `octave_set_signal_handler(int, void (*)(int))'
  14755.  
  14756.       or 
  14757.  
  14758.             warning: ANSI C++ prohibits conversion from `(int)' to `(...)'
  14759.  
  14760.       while compiling `sighandlers.cc', you may need to edit some files in the 
  14761.       gcc include subdirectory to add proper prototypes for functions there. 
  14762.       For example, Ultrix 4.2 needs proper declarations for the signal function 
  14763.       and the SIG_IGN macro in the file `signal.h'. 
  14764.  
  14765.       On some systems the SIG_IGN macro is defined to be something like this: 
  14766.  
  14767.             #define  SIG_IGN  (void (*)())1
  14768.  
  14769.       when it should really be something like: 
  14770.  
  14771.             #define  SIG_IGN  (void (*)(int))1
  14772.  
  14773.       to match the prototype declaration for the signal function.  This change 
  14774.       should also be made for the SIG_DFL and SIG_ERR symbols. It may be 
  14775.       necessary to change the definitions in `sys/signal.h' as well. 
  14776.  
  14777.       The gcc fixincludes and fixproto scripts should probably fix these 
  14778.       problems when gcc installs its modified set of header files, but I don't 
  14779.       think that's been done yet. 
  14780.  
  14781.       *You should not change the files in `/usr/include'*.  You can find the 
  14782.       gcc include directory tree by running the command 
  14783.  
  14784.             gcc -print-libgcc-file-name
  14785.  
  14786.       The directory of gcc include files normally begins in the same directory 
  14787.       that contains the file `libgcc.a'. 
  14788.  
  14789.      Some of the Fortran subroutines may fail to compile with older versions 
  14790.       of the Sun Fortran compiler.  If you get errors like 
  14791.  
  14792.             zgemm.f:
  14793.                     zgemm:
  14794.             warning: unexpected parent of complex expression subtree
  14795.             zgemm.f, line 245: warning: unexpected parent of complex
  14796.               expression subtree
  14797.             warning: unexpected parent of complex expression subtree
  14798.             zgemm.f, line 304: warning: unexpected parent of complex
  14799.               expression subtree
  14800.             warning: unexpected parent of complex expression subtree
  14801.             zgemm.f, line 327: warning: unexpected parent of complex
  14802.               expression subtree
  14803.             pcc_binval: missing IR_CONV in complex op
  14804.             make[2]: *** [zgemm.o] Error 1
  14805.  
  14806.       when compiling the Fortran subroutines in the `libcruft' subdirectory, 
  14807.       you should either upgrade your compiler or try compiling with 
  14808.       optimization turned off. 
  14809.  
  14810.      On NeXT systems, if you get errors like this: 
  14811.  
  14812.             /usr/tmp/cc007458.s:unknown:Undefined local symbol LBB7656
  14813.             /usr/tmp/cc007458.s:unknown:Undefined local symbol LBE7656
  14814.  
  14815.       when compiling `Array.cc' and `Matrix.cc', try recompiling these files 
  14816.       without -g. 
  14817.  
  14818.      Some people have reported that calls to shell_cmd and the pager do not 
  14819.       work on SunOS systems.  This is apparently due to having G_HAVE_SYS_WAIT 
  14820.       defined to be 0 instead of 1 when compiling libg++. 
  14821.  
  14822.      On NeXT systems, linking to `libsys_s.a' may fail to resolve the 
  14823.       following functions 
  14824.  
  14825.             _tcgetattr
  14826.             _tcsetattr
  14827.             _tcflow
  14828.  
  14829.       which are part of `libposix.a'.  Unfortunately, linking Octave with 
  14830.       -posix results in the following undefined symbols. 
  14831.  
  14832.             .destructors_used
  14833.             .constructors_used
  14834.             _objc_msgSend
  14835.             _NXGetDefaultValue
  14836.             _NXRegisterDefaults
  14837.             .objc_class_name_NXStringTable
  14838.             .objc_class_name_NXBundle
  14839.  
  14840.       One kluge around this problem is to extract `termios.o' from 
  14841.       `libposix.a', put it in Octave's `src' directory, and add it to the list 
  14842.       of files to link together in the makefile.  Suggestions for better ways 
  14843.       to solve this problem are welcome! 
  14844.  
  14845.      If Octave crashes immediately with a floating point exception, it is 
  14846.       likely that it is failing to initialize the IEEE floating point values 
  14847.       for infinity and NaN. 
  14848.  
  14849.       If your system actually does support IEEE arithmetic, you should be able 
  14850.       to fix this problem by modifying the function octave_ieee_init in the 
  14851.       file `lo-ieee.cc' to correctly initialize Octave's internal infinity and 
  14852.       NaN variables. 
  14853.  
  14854.       If your system does not support IEEE arithmetic but Octave's configure 
  14855.       script incorrectly determined that it does, you can work around the 
  14856.       problem by editing the file `config.h' to not define HAVE_ISINF, 
  14857.       HAVE_FINITE, and HAVE_ISNAN. 
  14858.  
  14859.       In any case, please report this as a bug since it might be possible to 
  14860.       modify Octave's configuration script to automatically determine the 
  14861.       proper thing to do. 
  14862.  
  14863.      After installing the binary distribution of Octave in an alternate 
  14864.       directory, the Emacs command run-octave doesn't work.  Emacs hangs in 
  14865.       accept-process-output in inferior-octave-startup. 
  14866.  
  14867.       This seems to be a problem with executing a shell script using the comint 
  14868.       package.  You can avoid the problem by changing the way Octave is 
  14869.       installed to eliminate the need for the shell script.  You can either 
  14870.       compile and install Octave using the source distribution, reinstall the 
  14871.       binary distribution in the default directory, or copy the commands in the 
  14872.       octave shell script wrapper to your shell startup files (and the shell 
  14873.       startup files for anyone else who is using Octave) and then rename the 
  14874.       file `octave.bin' to be `octave'. 
  14875.  
  14876.  
  14877. ΓòÉΓòÉΓòÉ 65.2. Binary Distributions ΓòÉΓòÉΓòÉ
  14878.  
  14879. Although Octave is not very difficult to build from its sources, it is a 
  14880. relatively large program that does require a significant amount of time and 
  14881. disk space to compile and install.  Because of this, many people want to be 
  14882. able to obtain binary distributions so they can start using Octave immediately, 
  14883. without having to bother with the details of compiling it first.  This is 
  14884. understandable, so I try to maintain a current collection of binary 
  14885. distributions at ftp://ftp.che.wisc.edu/pub/octave/BINARIES. 
  14886.  
  14887. Please understand, however, that there is only a limited amount of time 
  14888. available to devote to making binaries, so binaries may not be immediately 
  14889. available for some platforms.  (Please contact bug-octave@bevo.che.wisc.edu if 
  14890. you are interested in helping make a binary distribution available for your 
  14891. system.) 
  14892.  
  14893. Also, binary distributions are limited to static binaries that do not support 
  14894. dynamic linking.  For earlier versions of Octave, I tried distributing 
  14895. dynamically linked binaries but that proved to be too much trouble to support. 
  14896. If you want to have a copy of Octave that includes all the features described 
  14897. in this manual, you will have to build it from the sources yourself, or find 
  14898. someone else who is willing to do it for you. 
  14899.  
  14900.  Installing Octave from a Binary Distribution 
  14901.  Creating a Binary Distribution 
  14902.  
  14903.  
  14904. ΓòÉΓòÉΓòÉ 65.2.1. Installing Octave from a Binary Distribution ΓòÉΓòÉΓòÉ
  14905.  
  14906. To install Octave from a binary distribution, execute the command 
  14907.  
  14908. sh ./install-octave
  14909.  
  14910. in the top level directory of the distribution. 
  14911.  
  14912. Binary distributions are normally compiled assuming that Octave will be 
  14913. installed in the following subdirectories of `/usr/local'. 
  14914.  
  14915.  `bin' 
  14916.            Octave and other binaries that people will want to run directly. 
  14917.  
  14918.  `lib' 
  14919.            Shared libraries that Octave needs in order to run.  These files are 
  14920.            not included if you are installing a statically linked version of 
  14921.            Octave. 
  14922.  
  14923.  `man/man1' 
  14924.            Unix-style man pages describing Octave. 
  14925.  
  14926.  `info' 
  14927.            Info files describing Octave. 
  14928.  
  14929.  `share/octave/version/m' 
  14930.            Function files distributed with Octave.  This includes the Octave 
  14931.            version, so that multiple versions of Octave may be installed at the 
  14932.            same time. 
  14933.  
  14934.  `libexec/octave/version/exec/arch' 
  14935.            Executables to be run by Octave rather than the user. 
  14936.  
  14937.  `libexec/octave/version/oct/arch' 
  14938.            Object files that will be dynamically loaded. 
  14939.  
  14940.  `share/octave/version/imagelib' 
  14941.            Image files that are distributed with Octave. 
  14942.  
  14943.  where version stands for the current version number of the interpreter, and 
  14944.  arch is the type of computer on which Octave is installed (for example, 
  14945.  `i486-pc-os/2'). 
  14946.  
  14947.  If these directories don't exist, the script install-octave will create them 
  14948.  for you.  The installation script also creates the following subdirectories of 
  14949.  `/usr/local' that are intended for locally installed functions: 
  14950.  
  14951.  `share/octave/site/m' 
  14952.            Locally installed M-files. 
  14953.  
  14954.  `libexec/octave/site/exec/arch' 
  14955.            Locally installed binaries intended to be run by Octave rather than 
  14956.            by the user. 
  14957.  
  14958.  `libexec/octave/site/octave/arch' 
  14959.            Local object files that will be dynamically linked. 
  14960.  
  14961.  If it is not possible for you to install Octave in `/usr/local', or if you 
  14962.  would prefer to install it in a different directory, you can specify the name 
  14963.  of the top level directory as an argument to the `install-octave' script.  For 
  14964.  example: 
  14965.  
  14966.   sh ./install-octave /some/other/directory
  14967.  
  14968.  will install Octave in subdirectories of the directory 
  14969.  `/some/other/directory'. 
  14970.  
  14971.  
  14972. ΓòÉΓòÉΓòÉ 65.2.2. Creating a Binary Distribution ΓòÉΓòÉΓòÉ
  14973.  
  14974. Here is how to build a binary distribution for others to use.  If you want to 
  14975. make a binary distribution for your system available along with the Octave 
  14976. sources and binaries on ftp.che.wisc.edu, please follow this procedure.  For 
  14977. directions explaining how to make the binary available on the ftp site, please 
  14978. contact bug-octave@bevo.che.wisc.edu. 
  14979.  
  14980.      Unpack the source distribution: 
  14981.  
  14982.             gunzip -c octave-2.1.14.tar.gz | tar xf -
  14983.  
  14984.      Change your current directory to the top-level directory of the source 
  14985.       distribution: 
  14986.  
  14987.             cd octave-2.1.14
  14988.  
  14989.      Make the binary distribution: 
  14990.  
  14991.             make binary-dist
  14992.  
  14993.       This will create a compressed tar file ready for distribution. It will 
  14994.       contain statically linked binaries and have a name like 
  14995.       `octave-2.1.14-i486-pc-os/2.tar.gz' 
  14996.  
  14997.  
  14998. ΓòÉΓòÉΓòÉ 66. Emacs Octave Support ΓòÉΓòÉΓòÉ
  14999.  
  15000. The development of Octave code can greatly be facilitated using Emacs with 
  15001. Octave mode, a major mode for editing Octave files which can e.g. automatically 
  15002. indent the code, do some of the typing (with Abbrev mode) and show keywords, 
  15003. comments, strings, etc. in different faces (with Font-lock mode on devices that 
  15004. support it). 
  15005.  
  15006. It is also possible to run Octave from within Emacs, either by directly 
  15007. entering commands at the prompt in a buffer in Inferior Octave mode, or by 
  15008. interacting with Octave from within a file with Octave code.  This is useful in 
  15009. particular for debugging Octave code. 
  15010.  
  15011. Finally, you can convince Octave to use the Emacs info reader for help -i. 
  15012.  
  15013. All functionality is provided by the Emacs Lisp package EOS (for ``Emacs Octave 
  15014. Support'').  This chapter describes how to set up and use this package. 
  15015.  
  15016. Please contact <Kurt.Hornik@ci.tuwien.ac.at> if you have any questions or 
  15017. suggestions on using EOS. 
  15018.  
  15019.  Installing EOS 
  15020.  Using Octave Mode 
  15021.  Running Octave From Within Emacs 
  15022.  Using the Emacs Info Reader for Octave 
  15023.  
  15024.  
  15025. ΓòÉΓòÉΓòÉ 66.1. Installing EOS ΓòÉΓòÉΓòÉ
  15026.  
  15027. The Emacs package EOS consists of the three files `octave-mod.el', 
  15028. `octave-inf.el', and `octave-hlp.el'.  These files, or better yet their 
  15029. byte-compiled versions, should be somewhere in your Emacs load-path. 
  15030.  
  15031. If you have GNU Emacs with a version number at least as high as 19.35, you are 
  15032. all set up, because EOS is respectively will be part of GNU Emacs as of version 
  15033. 19.35. 
  15034.  
  15035. Otherwise, copy the three files from the `emacs' subdirectory of the Octave 
  15036. distribution to a place where Emacs can find them (this depends on how your 
  15037. Emacs was installed).  Byte-compile them for speed if you want. 
  15038.  
  15039.  
  15040. ΓòÉΓòÉΓòÉ 66.2. Using Octave Mode ΓòÉΓòÉΓòÉ
  15041.  
  15042. If you are lucky, your sysadmins have already arranged everything so that Emacs 
  15043. automatically goes into Octave mode whenever you visit an Octave code file as 
  15044. characterized by its extension `.m'.  If not, proceed as follows. 
  15045.  
  15046.    1. To begin using Octave mode for all `.m' files you visit, add the 
  15047.       following lines to a file loaded by Emacs at startup time, typically your 
  15048.       `~/.emacs' file: 
  15049.  
  15050.             (autoload 'octave-mode "octave-mod" nil t)
  15051.             (setq auto-mode-alist
  15052.                   (cons '("\\.m$" . octave-mode) auto-mode-alist))
  15053.  
  15054.    2. Finally, to turn on the abbrevs, auto-fill and font-lock features 
  15055.       automatically, also add the following lines to one of the Emacs startup 
  15056.       files: 
  15057.  
  15058.             (add-hook 'octave-mode-hook
  15059.                       (lambda ()
  15060.                         (abbrev-mode 1)
  15061.                         (auto-fill-mode 1)
  15062.                         (if (eq window-system 'x)
  15063.                             (font-lock-mode 1))))
  15064.  
  15065.       See the Emacs manual for more information about how to customize 
  15066.       Font-lock mode. 
  15067.  
  15068.  In Octave mode, the following special Emacs commands can be used in addition 
  15069.  to the standard Emacs commands. 
  15070.  
  15071.  C-h m 
  15072.            Describe the features of Octave mode. 
  15073.  
  15074.  LFD 
  15075.            Reindent the current Octave line, insert a newline and indent the 
  15076.            new line (octave-reindent-then-newline-and-indent).  An abbrev 
  15077.            before point is expanded if abbrev-mode is non-nil. 
  15078.  
  15079.  TAB 
  15080.            Indents current Octave line based on its contents and on previous 
  15081.            lines (indent-according-to-mode). 
  15082.  
  15083.  ; 
  15084.            Insert an ``electric'' semicolon (octave-electric-semi).  If 
  15085.            octave-auto-indent is non-nil, reindent the current line. If 
  15086.            octave-auto-newline is non-nil, automagically insert a newline and 
  15087.            indent the new line. 
  15088.  
  15089.  ` 
  15090.            Start entering an abbreviation (octave-abbrev-start).  If Abbrev 
  15091.            mode is turned on, typing `C-h or `? lists all abbrevs. Any other 
  15092.            key combination is executed normally.  Note that all Octave abbrevs 
  15093.            start with a grave accent. 
  15094.  
  15095.  M-LFD 
  15096.            Break line at point and insert continuation marker and alignment 
  15097.            (octave-split-line). 
  15098.  
  15099.  M-TAB 
  15100.            Perform completion on Octave symbol preceding point, comparing that 
  15101.            symbol against Octave's reserved words and builtin variables 
  15102.            (octave-complete-symbol). 
  15103.  
  15104.  M-C-a 
  15105.            Move backward to the beginning of a function 
  15106.            (octave-beginning-of-defun). With prefix argument N, do it that many 
  15107.            times if N is positive;  otherwise, move forward to the N-th 
  15108.            following beginning of a function. 
  15109.  
  15110.  M-C-e 
  15111.            Move forward to the end of a function (octave-end-of-defun). With 
  15112.            prefix argument N, do it that many times if N is positive; 
  15113.            otherwise, move back to the N-th preceding end of a function. 
  15114.  
  15115.  M-C-h 
  15116.            Puts point at beginning and mark at the end of the current Octave 
  15117.            function, i.e., the one containing point or following point 
  15118.            (octave-mark-defun). 
  15119.  
  15120.  M-C-q 
  15121.            Properly indents the Octave function which contains point 
  15122.            (octave-indent-defun). 
  15123.  
  15124.  M-; 
  15125.            If there is no comment already on this line, create a code-level 
  15126.            comment (started by two comment characters) if the line is empty, or 
  15127.            an in-line comment (started by one comment character) otherwise 
  15128.            (octave-indent-for-comment). Point is left after the start of the 
  15129.            comment which is properly aligned. 
  15130.  
  15131.  C-c ; 
  15132.            Puts the comment character `#' (more precisely, the string value of 
  15133.            octave-comment-start) at the beginning of every line in the region 
  15134.            (octave-comment-region).  With just C-u prefix argument, uncomment 
  15135.            each line in the region.  A numeric prefix argument N means use N 
  15136.            comment characters. 
  15137.  
  15138.  C-c : 
  15139.            Uncomments every line in the region (octave-uncomment-region). 
  15140.  
  15141.  C-c C-p 
  15142.            Move one line of Octave code backward, skipping empty and comment 
  15143.            lines (octave-previous-code-line).  With numeric prefix argument N, 
  15144.            move that many code lines backward (forward if N is negative). 
  15145.  
  15146.  C-c C-n 
  15147.            Move one line of Octave code forward, skipping empty and comment 
  15148.            lines (octave-next-code-line).  With numeric prefix argument N, move 
  15149.            that many code lines forward (backward if N is negative). 
  15150.  
  15151.  C-c C-a 
  15152.            Move to the `real' beginning of the current line 
  15153.            (octave-beginning-of-line).  If point is in an empty or comment 
  15154.            line, simply go to its beginning;  otherwise, move backwards to the 
  15155.            beginning of the first code line which is not inside a continuation 
  15156.            statement,  i.e., which does not follow a code line ending in `...' 
  15157.            or `\', or is inside an open parenthesis list. 
  15158.  
  15159.  C-c C-e 
  15160.            Move to the `real' end of the current line (octave-end-of-line). If 
  15161.            point is in a code line, move forward to the end of the first Octave 
  15162.            code line which does not end in `...' or `\' or is inside an open 
  15163.            parenthesis list.  Otherwise, simply go to the end of the current 
  15164.            line. 
  15165.  
  15166.  C-c M-C-n 
  15167.            Move forward across one balanced begin-end block of Octave code 
  15168.            (octave-forward-block).  With numeric prefix argument N, move 
  15169.            forward across n such blocks (backward if N is negative). 
  15170.  
  15171.  C-c M-C-p 
  15172.            Move back across one balanced begin-end block of Octave code 
  15173.            (octave-backward-block).  With numeric prefix argument N, move 
  15174.            backward across N such blocks (forward if N is negative). 
  15175.  
  15176.  C-c M-C-d 
  15177.            Move forward down one begin-end block level of Octave code 
  15178.            (octave-down-block).  With numeric prefix argument, do it that many 
  15179.            times;  a negative argument means move backward, but still go down 
  15180.            one level. 
  15181.  
  15182.  C-c M-C-u 
  15183.            Move backward out of one begin-end block level of Octave code 
  15184.            (octave-backward-up-block).  With numeric prefix argument, do it 
  15185.            that many times; a negative argument means move forward, but still 
  15186.            to a less deep spot. 
  15187.  
  15188.  C-c M-C-h 
  15189.            Put point at the beginning of this block, mark at the end 
  15190.            (octave-mark-block). The block marked is the one that contains point 
  15191.            or follows point. 
  15192.  
  15193.  C-c ] 
  15194.            Close the current block on a separate line (octave-close-block). An 
  15195.            error is signaled if no block to close is found. 
  15196.  
  15197.  C-c f 
  15198.            Insert a function skeleton, prompting for the function's name, 
  15199.            arguments and return values which have to be entered without parens 
  15200.            (octave-insert-defun). 
  15201.  
  15202.  C-c C-h 
  15203.            Search the function, operator and variable indices of all info files 
  15204.            with documentation for Octave for entries (octave-help).  If used 
  15205.            interactively, the entry is prompted for with completion.  If 
  15206.            multiple matches are found, one can cycle through them using the 
  15207.            standard `,' (Info-index-next) command of the Info reader. 
  15208.  
  15209.            The variable octave-help-files is a list of files to search through 
  15210.            and defaults to '("octave").  If there is also an Octave Local Guide 
  15211.            with corresponding info file, say, `octave-LG', you can have 
  15212.            octave-help search both files by 
  15213.  
  15214.                       (setq octave-help-files '("octave" "octave-LG"))
  15215.  
  15216.            in one of your Emacs startup files. 
  15217.  
  15218.  A common problem is that the RET key does not indent the line to where the new 
  15219.  text should go after inserting the newline.  This is because the standard 
  15220.  Emacs convention is that RET (aka C-m) just adds a newline, whereas LFD (aka 
  15221.  C-j) adds a newline and indents it.  This is particularly inconvenient for 
  15222.  users with keyboards which do not have a special LFD key at all;  in such 
  15223.  cases, it is typically more convenient to use RET as the LFD key (rather than 
  15224.  typing C-j). 
  15225.  
  15226.  You can make RET do this by adding 
  15227.  
  15228.   (define-key octave-mode-map "\C-m"
  15229.     'octave-reindent-then-newline-and-indent)
  15230.  
  15231.  to one of your Emacs startup files.  Another, more generally applicable 
  15232.  solution is 
  15233.  
  15234.   (defun RET-behaves-as-LFD ()
  15235.     (let ((x (key-binding "\C-j")))
  15236.       (local-set-key "\C-m" x)))
  15237.   (add-hook 'octave-mode-hook 'RET-behaves-as-LFD)
  15238.  
  15239.  (this works for all modes by adding to the startup hooks, without having to 
  15240.  know the particular binding of RET in that mode!).  Similar considerations 
  15241.  apply for using M-RET as M-LFD.  As Barry A. Warsaw 
  15242.  <bwarsaw@cnri.reston.va.us> says in the documentation for his cc-mode, ``This 
  15243.  is a very common question. :-) If you want this to be the default behavior, 
  15244.  don't lobby me, lobby RMS!'' 
  15245.  
  15246.  The following variables can be used to customize Octave mode. 
  15247.  
  15248.  octave-auto-indent 
  15249.            Non-nil means auto-indent the current line after a semicolon or 
  15250.            space.  Default is nil. 
  15251.  
  15252.  octave-auto-newline 
  15253.            Non-nil means auto-insert a newline and indent after semicolons are 
  15254.            typed.  The default value is nil. 
  15255.  
  15256.  octave-blink-matching-block 
  15257.            Non-nil means show matching begin of block when inserting a space, 
  15258.            newline or `;' after an else or end keyword.  Default is t. This is 
  15259.            an extremely useful feature for automatically verifying that the 
  15260.            keywords match---if they don't, an error message is displayed. 
  15261.  
  15262.  octave-block-offset 
  15263.            Extra indentation applied to statements in block structures. Default 
  15264.            is 2. 
  15265.  
  15266.  octave-continuation-offset 
  15267.            Extra indentation applied to Octave continuation lines. Default is 
  15268.            4. 
  15269.  
  15270.  octave-continuation-string 
  15271.            String used for Octave continuation lines. Normally `\'. 
  15272.  
  15273.  octave-mode-startup-message 
  15274.            If t (default), a startup message is displayed when Octave mode is 
  15275.            called. 
  15276.  
  15277.  If Font Lock mode is enabled, Octave mode will display 
  15278.  
  15279.      strings in font-lock-string-face 
  15280.  
  15281.      comments in font-lock-comment-face 
  15282.  
  15283.      the Octave reserved words (such as all block keywords) and the text 
  15284.       functions (such as `cd' or `who') which are also reserved using 
  15285.       font-lock-keyword-face 
  15286.  
  15287.      the builtin operators (`&&', `<>', ...) using font-lock-reference-face 
  15288.  
  15289.      the builtin variables (such as `prefer_column_vectors', `NaN' or 
  15290.       `LOADPATH') in font-lock-variable-name-face 
  15291.  
  15292.      and the function names in function declarations in 
  15293.       font-lock-function-name-face. 
  15294.  
  15295.  There is also rudimentary support for Imenu (currently, function names can be 
  15296.  indexed). 
  15297.  
  15298.  You can generate TAGS files for Emacs from Octave `.m' files using the shell 
  15299.  script otags that is installed alongside your copy of Octave. 
  15300.  
  15301.  Customization of Octave mode can be performed by modification of the variable 
  15302.  octave-mode-hook.  It the value of this variable is non-nil, turning on Octave 
  15303.  mode calls its value. 
  15304.  
  15305.  If you discover a problem with Octave mode, you can conveniently send a bug 
  15306.  report using C-c C-b (octave-submit-bug-report).  This automatically sets up a 
  15307.  mail buffer with version information already added.  You just need to add a 
  15308.  description of the problem, including a reproducible test case and send the 
  15309.  message. 
  15310.  
  15311.  
  15312. ΓòÉΓòÉΓòÉ 66.3. Running Octave From Within Emacs ΓòÉΓòÉΓòÉ
  15313.  
  15314. The package `octave' provides commands for running an inferior Octave process 
  15315. in a special Emacs buffer.  Use 
  15316.  
  15317. M-x run-octave
  15318.  
  15319. to directly start an inferior Octave process.  If Emacs does not know about 
  15320. this command, add the line 
  15321.  
  15322. (autoload 'run-octave "octave-inf" nil t)
  15323.  
  15324. to your `.emacs' file. 
  15325.  
  15326. This will start Octave in a special buffer the name of which is specified by 
  15327. the variable inferior-octave-buffer and defaults to "*Inferior Octave*".  From 
  15328. within this buffer, you can interact with the inferior Octave process `as 
  15329. usual', i.e., by entering Octave commands at the prompt.  The buffer is in 
  15330. Inferior Octave mode, which is derived from the standard Comint mode, a major 
  15331. mode for interacting with an inferior interpreter.  See the documentation for 
  15332. comint-mode for more details, and use C-h b to find out about available special 
  15333. keybindings. 
  15334.  
  15335. You can also communicate with an inferior Octave process from within files with 
  15336. Octave code (i.e., buffers in Octave mode), using the following commands. 
  15337.  
  15338.  C-c i l 
  15339.            Send the current line to the inferior Octave process 
  15340.            (octave-send-line). With positive prefix argument N, send that many 
  15341.            lines. If octave-send-line-auto-forward is non-nil, go to the next 
  15342.            unsent code line. 
  15343.  
  15344.  C-c i b 
  15345.            Send the current block to the inferior Octave process 
  15346.            (octave-send-block). 
  15347.  
  15348.  C-c i f 
  15349.            Send the current function to the inferior Octave process 
  15350.            (octave-send-defun). 
  15351.  
  15352.  C-c i r 
  15353.            Send the region to the inferior Octave process (octave-send-region). 
  15354.  
  15355.  C-c i s 
  15356.            Make sure that `inferior-octave-buffer' is displayed 
  15357.            (octave-show-process-buffer). 
  15358.  
  15359.  C-c i h 
  15360.            Delete all windows that display the inferior Octave buffer 
  15361.            (octave-hide-process-buffer). 
  15362.  
  15363.  C-c i k 
  15364.            Kill the inferior Octave process and its buffer 
  15365.            (octave-kill-process). 
  15366.  
  15367.  The effect of the commands which send code to the Octave process can be 
  15368.  customized by the following variables. 
  15369.  
  15370.  octave-send-echo-input 
  15371.            Non-nil means echo input sent to the inferior Octave process. 
  15372.            Default is t. 
  15373.  
  15374.  octave-send-show-buffer 
  15375.            Non-nil means display the buffer running the Octave process after 
  15376.            sending a command (but without selecting it). Default is t. 
  15377.  
  15378.  If you send code and there is no inferior Octave process yet, it will be 
  15379.  started automatically. 
  15380.  
  15381.  The startup of the inferior Octave process is highly customizable. The 
  15382.  variable inferior-octave-startup-args can be used for specifying command lines 
  15383.  arguments to be passed to Octave on startup as a list of strings.  For 
  15384.  example, to suppress the startup message and use `traditional' mode, set this 
  15385.  to '("-q" "--traditional"). You can also specify a startup file of Octave 
  15386.  commands to be loaded on startup;  note that these commands will not produce 
  15387.  any visible output in the process buffer.  Which file to use is controlled by 
  15388.  the variable inferior-octave-startup-file.  If this is nil, the file 
  15389.  `~/.emacs-octave' is used if it exists. 
  15390.  
  15391.  And finally, inferior-octave-mode-hook is run after starting the process and 
  15392.  putting its buffer into Inferior Octave mode.  Hence, if you like the up and 
  15393.  down arrow keys to behave in the interaction buffer as in the shell, and you 
  15394.  want this buffer to use nice colors, add 
  15395.  
  15396.   (add-hook 'inferior-octave-mode-hook
  15397.             (lambda ()
  15398.               (turn-on-font-lock)
  15399.               (define-key inferior-octave-mode-map [up]
  15400.                 'comint-previous-input)
  15401.               (define-key inferior-octave-mode-map [down]
  15402.                 'comint-next-input)))
  15403.  
  15404.  to your `.emacs' file.  You could also swap the roles of C-a 
  15405.  (beginning-of-line) and C-c C-a (comint-bol) using this hook. 
  15406.  
  15407.  *Note:* If you set your Octave prompts to something different from the 
  15408.  defaults, make sure that inferior-octave-prompt matches them. Otherwise, 
  15409.  nothing will work, because Emacs will have no idea when Octave is waiting for 
  15410.  input, or done sending output. 
  15411.  
  15412.  
  15413. ΓòÉΓòÉΓòÉ 66.4. Using the Emacs Info Reader for Octave ΓòÉΓòÉΓòÉ
  15414.  
  15415. You can also set up the Emacs Info reader for dealing with the results of 
  15416. Octave's `help -i'.  For this, the package `gnuserv' needs to be installed, 
  15417. which unfortunately still does not come with GNU Emacs (it does with XEmacs). 
  15418. It can be retrieved from any GNU Emacs Lisp Code Directory archive, e.g. 
  15419. ftp://ftp.cis.ohio-state.edu/pub/gnu/emacs/elisp-archive, in the `packages' 
  15420. subdirectory.  The alpha version of an enhanced version of gnuserv is available 
  15421. at ftp://ftp.wellfleet.com/netman/psmith/emacs/gnuserv-2.1alpha.tar.gz. 
  15422.  
  15423. If `gnuserv' is installed, add the lines 
  15424.  
  15425. (autoload 'octave-help "octave-hlp" nil t)
  15426. (require 'gnuserv)
  15427. (gnuserv-start)
  15428.  
  15429. to your `.emacs' file. 
  15430.  
  15431. You can use either `plain' Emacs Info or the function octave-help as your 
  15432. Octave info reader (for `help -i').  In the former case, set the Octave 
  15433. variable INFO_PROGRAM to "info-emacs-info". The latter is perhaps more 
  15434. attractive because it allows to look up keys in the indices of several info 
  15435. files related to Octave (provided that the Emacs variable octave-help-files is 
  15436. set correctly).  In this case, set INFO_PROGRAM to "info-emacs-octave-help". 
  15437.  
  15438. If you use Octave from within Emacs, these settings are best done in the 
  15439. `~/.emacs-octave' startup file (or the file pointed to by the Emacs variable 
  15440. inferior-octave-startup-file). 
  15441.  
  15442.  
  15443. ΓòÉΓòÉΓòÉ 67. Grammar ΓòÉΓòÉΓòÉ
  15444.  
  15445. Someday I hope to expand this to include a semi-formal description of Octave's 
  15446. language. 
  15447.  
  15448.  Keywords 
  15449.  
  15450.  
  15451. ΓòÉΓòÉΓòÉ 67.1. Keywords ΓòÉΓòÉΓòÉ
  15452.  
  15453. The following identifiers are keywords, and may not be used as variable or 
  15454. function names: 
  15455.  
  15456. all_va_args             endwhile
  15457. break                   for
  15458. case                    function
  15459. catch                   global
  15460. continue                gplot
  15461. else                    gsplot
  15462. elseif                  if
  15463. end                     otherwise
  15464. end_try_catch           return
  15465. end_unwind_protect      switch
  15466. endfor                  try
  15467. endfunction             unwind_protect
  15468. endif                   unwind_protect_cleanup
  15469. endswitch               while
  15470.  
  15471. The following command-like functions are also speical.  They may be used as 
  15472. simple variable names, but not as formal parameters for functions, or as the 
  15473. names of structure variables.  Failed assignments leave them undefined (you can 
  15474. recover the orginal definition as a function using clear). 
  15475.  
  15476. casesen       echo          load          show
  15477. cd            edit_history  ls            type
  15478. chdir         format        more          which
  15479. clear         help          run_history   who
  15480. diary         history       save          whos
  15481. dir           hold          set
  15482.  
  15483.  
  15484. ΓòÉΓòÉΓòÉ 68. GNU GENERAL PUBLIC LICENSE ΓòÉΓòÉΓòÉ
  15485.  
  15486.                               Version 2, June 1991
  15487.  
  15488. Copyright (C) 1989, 1991 Free Software Foundation, Inc.
  15489. 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
  15490.  
  15491. Everyone is permitted to copy and distribute verbatim copies
  15492. of this license document, but changing it is not allowed.
  15493.  
  15494.  
  15495. ΓòÉΓòÉΓòÉ 68.1. Preamble ΓòÉΓòÉΓòÉ
  15496.  
  15497.  The licenses for most software are designed to take away your freedom to share 
  15498. and change it.  By contrast, the GNU General Public License is intended to 
  15499. guarantee your freedom to share and change free software---to make sure the 
  15500. software is free for all its users.  This General Public License applies to 
  15501. most of the Free Software Foundation's software and to any other program whose 
  15502. authors commit to using it.  (Some other Free Software Foundation software is 
  15503. covered by the GNU Library General Public License instead.)  You can apply it 
  15504. to your programs, too. 
  15505.  
  15506.  When we speak of free software, we are referring to freedom, not price.  Our 
  15507. General Public Licenses are designed to make sure that you have the freedom to 
  15508. distribute copies of free software (and charge for this service if you wish), 
  15509. that you receive source code or can get it if you want it, that you can change 
  15510. the software or use pieces of it in new free programs; and that you know you 
  15511. can do these things. 
  15512.  
  15513.  To protect your rights, we need to make restrictions that forbid anyone to 
  15514. deny you these rights or to ask you to surrender the rights. These restrictions 
  15515. translate to certain responsibilities for you if you distribute copies of the 
  15516. software, or if you modify it. 
  15517.  
  15518.  For example, if you distribute copies of such a program, whether gratis or for 
  15519. a fee, you must give the recipients all the rights that you have.  You must 
  15520. make sure that they, too, receive or can get the source code.  And you must 
  15521. show them these terms so they know their rights. 
  15522.  
  15523.  We protect your rights with two steps: (1) copyright the software, and (2) 
  15524. offer you this license which gives you legal permission to copy, distribute 
  15525. and/or modify the software. 
  15526.  
  15527.  Also, for each author's protection and ours, we want to make certain that 
  15528. everyone understands that there is no warranty for this free software.  If the 
  15529. software is modified by someone else and passed on, we want its recipients to 
  15530. know that what they have is not the original, so that any problems introduced 
  15531. by others will not reflect on the original authors' reputations. 
  15532.  
  15533.  Finally, any free program is threatened constantly by software patents.  We 
  15534. wish to avoid the danger that redistributors of a free program will 
  15535. individually obtain patent licenses, in effect making the program proprietary. 
  15536. To prevent this, we have made it clear that any patent must be licensed for 
  15537. everyone's free use or not licensed at all. 
  15538.  
  15539.  The precise terms and conditions for copying, distribution and modification 
  15540. follow. 
  15541.  
  15542.          TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  15543.  
  15544.    1. This License applies to any program or other work which contains a notice 
  15545.       placed by the copyright holder saying it may be distributed under the 
  15546.       terms of this General Public License.  The ``Program'', below, refers to 
  15547.       any such program or work, and a ``work based on the Program'' means 
  15548.       either the Program or any derivative work under copyright law: that is to 
  15549.       say, a work containing the Program or a portion of it, either verbatim or 
  15550.       with modifications and/or translated into another language. 
  15551.       (Hereinafter, translation is included without limitation in the term 
  15552.       ``modification''.)  Each licensee is addressed as ``you''. 
  15553.  
  15554.       Activities other than copying, distribution and modification are not 
  15555.       covered by this License; they are outside its scope.  The act of running 
  15556.       the Program is not restricted, and the output from the Program is covered 
  15557.       only if its contents constitute a work based on the Program (independent 
  15558.       of having been made by running the Program). Whether that is true depends 
  15559.       on what the Program does. 
  15560.  
  15561.    2. You may copy and distribute verbatim copies of the Program's source code 
  15562.       as you receive it, in any medium, provided that you conspicuously and 
  15563.       appropriately publish on each copy an appropriate copyright notice and 
  15564.       disclaimer of warranty; keep intact all the notices that refer to this 
  15565.       License and to the absence of any warranty; and give any other recipients 
  15566.       of the Program a copy of this License along with the Program. 
  15567.  
  15568.       You may charge a fee for the physical act of transferring a copy, and you 
  15569.       may at your option offer warranty protection in exchange for a fee. 
  15570.  
  15571.    3. You may modify your copy or copies of the Program or any portion of it, 
  15572.       thus forming a work based on the Program, and copy and distribute such 
  15573.       modifications or work under the terms of Section 1 above, provided that 
  15574.       you also meet all of these conditions: 
  15575.  
  15576.         a. You must cause the modified files to carry prominent notices stating 
  15577.            that you changed the files and the date of any change. 
  15578.  
  15579.         b. You must cause any work that you distribute or publish, that in 
  15580.            whole or in part contains or is derived from the Program or any part 
  15581.            thereof, to be licensed as a whole at no charge to all third parties 
  15582.            under the terms of this License. 
  15583.  
  15584.         c. If the modified program normally reads commands interactively when 
  15585.            run, you must cause it, when started running for such interactive 
  15586.            use in the most ordinary way, to print or display an announcement 
  15587.            including an appropriate copyright notice and a notice that there is 
  15588.            no warranty (or else, saying that you provide a warranty) and that 
  15589.            users may redistribute the program under these conditions, and 
  15590.            telling the user how to view a copy of this License.  (Exception: if 
  15591.            the Program itself is interactive but does not normally print such 
  15592.            an announcement, your work based on the Program is not required to 
  15593.            print an announcement.) 
  15594.  
  15595.       These requirements apply to the modified work as a whole.  If 
  15596.       identifiable sections of that work are not derived from the Program, and 
  15597.       can be reasonably considered independent and separate works in 
  15598.       themselves, then this License, and its terms, do not apply to those 
  15599.       sections when you distribute them as separate works.  But when you 
  15600.       distribute the same sections as part of a whole which is a work based on 
  15601.       the Program, the distribution of the whole must be on the terms of this 
  15602.       License, whose permissions for other licensees extend to the entire 
  15603.       whole, and thus to each and every part regardless of who wrote it. 
  15604.  
  15605.       Thus, it is not the intent of this section to claim rights or contest 
  15606.       your rights to work written entirely by you; rather, the intent is to 
  15607.       exercise the right to control the distribution of derivative or 
  15608.       collective works based on the Program. 
  15609.  
  15610.       In addition, mere aggregation of another work not based on the Program 
  15611.       with the Program (or with a work based on the Program) on a volume of a 
  15612.       storage or distribution medium does not bring the other work under the 
  15613.       scope of this License. 
  15614.  
  15615.    4. You may copy and distribute the Program (or a work based on it, under 
  15616.       Section 2) in object code or executable form under the terms of Sections 
  15617.       1 and 2 above provided that you also do one of the following: 
  15618.  
  15619.         a. Accompany it with the complete corresponding machine-readable source 
  15620.            code, which must be distributed under the terms of Sections 1 and 2 
  15621.            above on a medium customarily used for software interchange; or, 
  15622.  
  15623.         b. Accompany it with a written offer, valid for at least three years, 
  15624.            to give any third party, for a charge no more than your cost of 
  15625.            physically performing source distribution, a complete 
  15626.            machine-readable copy of the corresponding source code, to be 
  15627.            distributed under the terms of Sections 1 and 2 above on a medium 
  15628.            customarily used for software interchange; or, 
  15629.  
  15630.         c. Accompany it with the information you received as to the offer to 
  15631.            distribute corresponding source code.  (This alternative is allowed 
  15632.            only for noncommercial distribution and only if you received the 
  15633.            program in object code or executable form with such an offer, in 
  15634.            accord with Subsection b above.) 
  15635.  
  15636.       The source code for a work means the preferred form of the work for 
  15637.       making modifications to it.  For an executable work, complete source code 
  15638.       means all the source code for all modules it contains, plus any 
  15639.       associated interface definition files, plus the scripts used to control 
  15640.       compilation and installation of the executable.  However, as a special 
  15641.       exception, the source code distributed need not include anything that is 
  15642.       normally distributed (in either source or binary form) with the major 
  15643.       components (compiler, kernel, and so on) of the operating system on which 
  15644.       the executable runs, unless that component itself accompanies the 
  15645.       executable. 
  15646.  
  15647.       If distribution of executable or object code is made by offering access 
  15648.       to copy from a designated place, then offering equivalent access to copy 
  15649.       the source code from the same place counts as distribution of the source 
  15650.       code, even though third parties are not compelled to copy the source 
  15651.       along with the object code. 
  15652.  
  15653.    5. You may not copy, modify, sublicense, or distribute the Program except as 
  15654.       expressly provided under this License.  Any attempt otherwise to copy, 
  15655.       modify, sublicense or distribute the Program is void, and will 
  15656.       automatically terminate your rights under this License. However, parties 
  15657.       who have received copies, or rights, from you under this License will not 
  15658.       have their licenses terminated so long as such parties remain in full 
  15659.       compliance. 
  15660.  
  15661.    6. You are not required to accept this License, since you have not signed 
  15662.       it.  However, nothing else grants you permission to modify or distribute 
  15663.       the Program or its derivative works.  These actions are prohibited by law 
  15664.       if you do not accept this License.  Therefore, by modifying or 
  15665.       distributing the Program (or any work based on the Program), you indicate 
  15666.       your acceptance of this License to do so, and all its terms and 
  15667.       conditions for copying, distributing or modifying the Program or works 
  15668.       based on it. 
  15669.  
  15670.    7. Each time you redistribute the Program (or any work based on the 
  15671.       Program), the recipient automatically receives a license from the 
  15672.       original licensor to copy, distribute or modify the Program subject to 
  15673.       these terms and conditions.  You may not impose any further restrictions 
  15674.       on the recipients' exercise of the rights granted herein. You are not 
  15675.       responsible for enforcing compliance by third parties to this License. 
  15676.  
  15677.    8. If, as a consequence of a court judgment or allegation of patent 
  15678.       infringement or for any other reason (not limited to patent issues), 
  15679.       conditions are imposed on you (whether by court order, agreement or 
  15680.       otherwise) that contradict the conditions of this License, they do not 
  15681.       excuse you from the conditions of this License.  If you cannot distribute 
  15682.       so as to satisfy simultaneously your obligations under this License and 
  15683.       any other pertinent obligations, then as a consequence you may not 
  15684.       distribute the Program at all.  For example, if a patent license would 
  15685.       not permit royalty-free redistribution of the Program by all those who 
  15686.       receive copies directly or indirectly through you, then the only way you 
  15687.       could satisfy both it and this License would be to refrain entirely from 
  15688.       distribution of the Program. 
  15689.  
  15690.       If any portion of this section is held invalid or unenforceable under any 
  15691.       particular circumstance, the balance of the section is intended to apply 
  15692.       and the section as a whole is intended to apply in other circumstances. 
  15693.  
  15694.       It is not the purpose of this section to induce you to infringe any 
  15695.       patents or other property right claims or to contest validity of any such 
  15696.       claims; this section has the sole purpose of protecting the integrity of 
  15697.       the free software distribution system, which is implemented by public 
  15698.       license practices.  Many people have made generous contributions to the 
  15699.       wide range of software distributed through that system in reliance on 
  15700.       consistent application of that system; it is up to the author/donor to 
  15701.       decide if he or she is willing to distribute software through any other 
  15702.       system and a licensee cannot impose that choice. 
  15703.  
  15704.       This section is intended to make thoroughly clear what is believed to be 
  15705.       a consequence of the rest of this License. 
  15706.  
  15707.    9. If the distribution and/or use of the Program is restricted in certain 
  15708.       countries either by patents or by copyrighted interfaces, the original 
  15709.       copyright holder who places the Program under this License may add an 
  15710.       explicit geographical distribution limitation excluding those countries, 
  15711.       so that distribution is permitted only in or among countries not thus 
  15712.       excluded.  In such case, this License incorporates the limitation as if 
  15713.       written in the body of this License. 
  15714.  
  15715.   10. The Free Software Foundation may publish revised and/or new versions of 
  15716.       the General Public License from time to time.  Such new versions will be 
  15717.       similar in spirit to the present version, but may differ in detail to 
  15718.       address new problems or concerns. 
  15719.  
  15720.       Each version is given a distinguishing version number.  If the Program 
  15721.       specifies a version number of this License which applies to it and ``any 
  15722.       later version'', you have the option of following the terms and 
  15723.       conditions either of that version or of any later version published by 
  15724.       the Free Software Foundation.  If the Program does not specify a version 
  15725.       number of this License, you may choose any version ever published by the 
  15726.       Free Software Foundation. 
  15727.  
  15728.   11. If you wish to incorporate parts of the Program into other free programs 
  15729.       whose distribution conditions are different, write to the author to ask 
  15730.       for permission.  For software which is copyrighted by the Free Software 
  15731.       Foundation, write to the Free Software Foundation; we sometimes make 
  15732.       exceptions for this.  Our decision will be guided by the two goals of 
  15733.       preserving the free status of all derivatives of our free software and of 
  15734.       promoting the sharing and reuse of software generally. 
  15735.  
  15736.                                       NO WARRANTY
  15737.  
  15738.   12. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR 
  15739.       THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN 
  15740.       OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 
  15741.       PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER 
  15742.       EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
  15743.       WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE 
  15744.       ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. 
  15745.       SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY 
  15746.       SERVICING, REPAIR OR CORRECTION. 
  15747.  
  15748.   13. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 
  15749.       WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 
  15750.       REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR 
  15751.       DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL 
  15752.       DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING 
  15753.       BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR 
  15754.       LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO 
  15755.       OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS 
  15756.       BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 
  15757.  
  15758.                            END OF TERMS AND CONDITIONS
  15759.  
  15760.  
  15761. ΓòÉΓòÉΓòÉ 68.2. Appendix: How to Apply These Terms to Your New Programs ΓòÉΓòÉΓòÉ
  15762.  
  15763.  If you develop a new program, and you want it to be of the greatest possible 
  15764. use to the public, the best way to achieve this is to make it free software 
  15765. which everyone can redistribute and change under these terms. 
  15766.  
  15767.  To do so, attach the following notices to the program.  It is safest to attach 
  15768. them to the start of each source file to most effectively convey the exclusion 
  15769. of warranty; and each file should have at least the ``copyright'' line and a 
  15770. pointer to where the full notice is found. 
  15771.  
  15772. one line to give the program's name and a brief idea of what it does.
  15773. Copyright (C) 19yy  name of author
  15774.  
  15775. This program is free software; you can redistribute it and/or modify
  15776. it under the terms of the GNU General Public License as published by
  15777. the Free Software Foundation; either version 2 of the License, or
  15778. (at your option) any later version.
  15779.  
  15780. This program is distributed in the hope that it will be useful,
  15781. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15782. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15783. GNU General Public License for more details.
  15784.  
  15785. You should have received a copy of the GNU General Public License
  15786. along with this program; if not, write to the Free Software
  15787. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15788. 02111-1307, USA.
  15789.  
  15790. Also add information on how to contact you by electronic and paper mail. 
  15791.  
  15792. If the program is interactive, make it output a short notice like this when it 
  15793. starts in an interactive mode: 
  15794.  
  15795. Gnomovision version 69, Copyright (C) 19yy name of author
  15796. Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
  15797. type `show w'.  This is free software, and you are welcome
  15798. to redistribute it under certain conditions; type `show c'
  15799. for details.
  15800.  
  15801. The hypothetical commands `show w' and `show c' should show the appropriate 
  15802. parts of the General Public License.  Of course, the commands you use may be 
  15803. called something other than `show w' and `show c'; they could even be 
  15804. mouse-clicks or menu items---whatever suits your program. 
  15805.  
  15806. You should also get your employer (if you work as a programmer) or your school, 
  15807. if any, to sign a ``copyright disclaimer'' for the program, if necessary.  Here 
  15808. is a sample; alter the names: 
  15809.  
  15810. Yoyodyne, Inc., hereby disclaims all copyright interest in the program
  15811. `Gnomovision' (which makes passes at compilers) written by James Hacker.
  15812.  
  15813. signature of Ty Coon, 1 April 1989
  15814. Ty Coon, President of Vice
  15815.  
  15816. This General Public License does not permit incorporating your program into 
  15817. proprietary programs.  If your program is a subroutine library, you may 
  15818. consider it more useful to permit linking proprietary applications with the 
  15819. library.  If this is what you want to do, use the GNU Library General Public 
  15820. License instead of this License. 
  15821.  
  15822.  
  15823. ΓòÉΓòÉΓòÉ 69. Concept Index ΓòÉΓòÉΓòÉ
  15824.  
  15825. Sorry, no cp index 
  15826.  
  15827.  
  15828. ΓòÉΓòÉΓòÉ 70. Variable Index ΓòÉΓòÉΓòÉ
  15829.  
  15830. Sorry, no vr index 
  15831.  
  15832.  
  15833. ΓòÉΓòÉΓòÉ 71. Function Index ΓòÉΓòÉΓòÉ
  15834.  
  15835. Sorry, no fn index 
  15836.  
  15837.  
  15838. ΓòÉΓòÉΓòÉ 72. Operator Index ΓòÉΓòÉΓòÉ
  15839.  
  15840. Sorry, no op index 
  15841.  
  15842.  
  15843. ΓòÉΓòÉΓòÉ <hidden>  ΓòÉΓòÉΓòÉ
  15844.  
  15845. The `#!' mechanism works on Unix systems derived from Berkeley Unix, System V 
  15846. Release 4, and some System V Release 3 systems.
  15847.  
  15848.  
  15849. ΓòÉΓòÉΓòÉ <hidden>  ΓòÉΓòÉΓòÉ
  15850.  
  15851. Some of Octave's function are implemented in terms of functions that cannot be 
  15852. called recursively. For example, the ODE solver lsode is ultimately implemented 
  15853. in a Fortran subroutine that cannot be called recursively, so lsode should not 
  15854. be called either directly or indirectly from within the user-supplied function 
  15855. that lsode requires.  Doing so will result in undefined behavior.
  15856.  
  15857.  
  15858. ΓòÉΓòÉΓòÉ <hidden>  ΓòÉΓòÉΓòÉ
  15859.  
  15860. It would be much better to use prod (1:n), or gamma (n+1) instead, after first 
  15861. checking to ensure that the value n is actually a positive integer.
  15862.  
  15863.  
  15864. ΓòÉΓòÉΓòÉ <hidden>  ΓòÉΓòÉΓòÉ
  15865.  
  15866. The `.m' suffix was chosen for compatibility with Matlab.
  15867.  
  15868.  
  15869. ΓòÉΓòÉΓòÉ <hidden>  ΓòÉΓòÉΓòÉ
  15870.  
  15871. Yes, it's a kluge, but it seems to be a reasonably useful one.
  15872.  
  15873.  
  15874. ΓòÉΓòÉΓòÉ <hidden>  ΓòÉΓòÉΓòÉ
  15875.  
  15876. For example, to first sort based on the values in column 1, and then, for any 
  15877. values that are repeated in column 1, sort based on the values found in column 
  15878. 2,