GNU Octave a High-Level Interactive Language for Numerical Computations Edition 3 for Octave Version 2.1.X February 1997
Total Page:16
File Type:pdf, Size:1020Kb
GNU Octave A high-level interactive language for numerical computations Edition 3 for Octave version 2.1.x February 1997 John W. Eaton Copyright c 1996, 1997 John W. Eaton. This is the third edition of the Octave documentation, and is consistent with version 2.1.x of Octave. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this manual under the con- ditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this manual into another lan- guage, under the same conditions as for modified versions. Portions of this document have been adapted from the gawk, readline, gcc, and C library manuals, published by the Free Software Foundation, 59 Temple Place|Suite 330, Boston, MA 02111{1307, USA. i Table of Contents Preface . 1 Acknowledgements . 1 How You Can Contribute to Octave . 4 Distribution . 4 1 A Brief Introduction to Octave . 5 1.1 Running Octave . 5 1.2 Simple Examples . 5 Creating a Matrix . 5 Matrix Arithmetic . 6 Solving Linear Equations . 6 Integrating Differential Equations . 6 Producing Graphical Output . 7 Editing What You Have Typed. 7 Help and Documentation . 8 1.3 Conventions . 8 1.3.1 Fonts . 8 1.3.2 Evaluation Notation . 8 1.3.3 Printing Notation. 9 1.3.4 Error Messages . 9 1.3.5 Format of Descriptions . 9 1.3.5.1 A Sample Function Description . 9 1.3.5.2 A Sample Command Description . 10 1.3.5.3 A Sample Variable Description . 11 2 Getting Started. 13 2.1 Invoking Octave. 13 2.1.1 Command Line Options . 13 2.1.2 Startup Files . 15 2.2 Quitting Octave . 16 2.3 Commands for Getting Help . 16 2.4 Command Line Editing . 18 2.4.1 Cursor Motion . 18 2.4.2 Killing and Yanking . 19 2.4.3 Commands For Changing Text . 19 2.4.4 Letting Readline Type For You . 20 2.4.5 Commands For Manipulating The History . 20 2.4.6 Customizing readline . 22 2.4.7 Customizing the Prompt . 22 2.4.8 Diary and Echo Commands . 23 2.5 How Octave Reports Errors . 24 2.6 Executable Octave Programs . 25 2.7 Comments in Octave Programs . 26 ii GNU Octave 3 Data Types . 29 3.1 Built-in Data Types . 29 3.1.1 Numeric Objects . 29 3.1.2 Missing Data . 29 3.1.3 String Objects. 30 3.1.4 Data Structure Objects . 30 3.2 User-defined Data Types. 30 3.3 Object Sizes . 30 4 Numeric Data Types. 33 4.1 Matrices . 33 4.1.1 Empty Matrices . 36 4.2 Ranges . 37 4.3 Logical Values . 37 4.4 Predicates for Numeric Objects. 38 5 Strings . 39 5.1 Creating Strings . 40 5.2 Searching and Replacing . 41 5.3 String Conversions . 43 5.4 Character Class Functions . 46 6 Data Structures . 47 7 Containers . 51 7.1 Lists . 51 7.2 Cell Arrays . 51 8 I/O Streams. 53 9 Variables . 55 9.1 Global Variables . 55 9.2 Persistent Variables . 56 9.3 Status of Variables . 57 9.4 Summary of Built-in Variables . 59 9.5 Defaults from the Environment . 64 iii 10 Expressions . 65 10.1 Index Expressions . 65 10.2 Calling Functions . 66 10.2.1 Call by Value . 67 10.2.2 Recursion . 68 10.3 Arithmetic Operators. 68 10.4 Comparison Operators. 70 10.5 Boolean Expressions. 70 10.5.1 Element-by-element Boolean Operators. 71 10.5.2 Short-circuit Boolean Operators . 71 10.6 Assignment Expressions . 72 10.7 Increment Operators . 74 10.8 Operator Precedence . 75 11 Evaluation . 77 12 Statements . 79 12.1 The if Statement . 79 12.2 The switch Statement . 81 12.3 The while Statement. 82 12.4 The do-until Statement . 83 12.5 The for Statement . 84 12.5.1 Looping Over Structure Elements . 84 12.6 The break Statement. 85 12.7 The continue Statement . 86 12.8 The unwind_protect Statement. 87 12.9 The try Statement . 88 12.10 Continuation Lines . 88 13 Functions and Script Files. 91 13.1 Defining Functions.