Docsity
Docsity

Prepare-se para as provas
Prepare-se para as provas

Estude fácil! Tem muito documento disponível na Docsity


Ganhe pontos para baixar
Ganhe pontos para baixar

Ganhe pontos ajudando outros esrudantes ou compre um plano Premium


Guias e Dicas
Guias e Dicas


octave, Manuais, Projetos, Pesquisas de Engenharia Elétrica

Manual do GNU Octave 3.2.4

Tipologia: Manuais, Projetos, Pesquisas

2013

Compartilhado em 16/08/2013

anderson-ferreira-sepulveda-8
anderson-ferreira-sepulveda-8 🇧🇷

6 documentos

1 / 686

Toggle sidebar

Esta página não é visível na pré-visualização

Não perca as partes importantes!

bg1
GNU Octave
A high-level interactive language for numerical computations
Edition 3 for Octave version 3.2.4
July 2007
John W. Eaton
David Bateman
Søren Hauberg
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Pré-visualização parcial do texto

Baixe octave e outras Manuais, Projetos, Pesquisas em PDF para Engenharia Elétrica, somente na Docsity!

GNU Octave

A high-level interactive language for numerical computations Edition 3 for Octave version 3.2. July 2007

John W. Eaton

David Bateman

Søren Hauberg

Copyright ©c 1996, 1997, 1999, 2000, 2001, 2002, 2005, 2006, 2007 John W. Eaton.

This is the third edition of the Octave documentation, and is consistent with version 3.2. 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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301–1307, USA.

6.3.2 Comma Separated Lists Generated from Structure Arrays

  • Preface Table of Contents
    • Acknowledgements
    • How You Can Contribute to Octave
    • Distribution
  • 1 A Brief Introduction to Octave
    • 1.1 Running Octave
    • 1.2 Simple Examples
      • 1.2.1 Elementary Calculations
      • 1.2.2 Creating a Matrix
      • 1.2.3 Matrix Arithmetic
      • 1.2.4 Solving Systems of Linear Equations
      • 1.2.5 Integrating Differential Equations
      • 1.2.6 Producing Graphical Output
      • 1.2.7 Editing What You Have Typed
      • 1.2.8 Help and Documentation
    • 1.3 Conventions
      • 1.3.1 Fonts
      • 1.3.2 Evaluation Notation
      • 1.3.3 Printing Notation
      • 1.3.4 Error Messages
      • 1.3.5 Format of Descriptions
        • 1.3.5.1 A Sample Function Description
        • 1.3.5.2 A Sample Command Description
        • 1.3.5.3 A Sample Variable Description
  • 2 Getting Started
    • 2.1 Invoking Octave from the Command Line
      • 2.1.1 Command Line Options
      • 2.1.2 Startup Files
    • 2.2 Quitting Octave
    • 2.3 Commands for Getting Help.
    • 2.4 Command Line Editing
      • 2.4.1 Cursor Motion
      • 2.4.2 Killing and Yanking
      • 2.4.3 Commands For Changing Text
      • 2.4.4 Letting Readline Type For You
      • 2.4.5 Commands For Manipulating The History
      • 2.4.6 Customizing readline
      • 2.4.7 Customizing the Prompt
      • 2.4.8 Diary and Echo Commands
    • 2.5 How Octave Reports Errors
    • 2.6 Executable Octave Programs ii GNU Octave
    • 2.7 Comments in Octave Programs
      • 2.7.1 Single Line Comments
      • 2.7.2 Block Comments
      • 2.7.3 Comments and the Help System
  • 3 Data Types
    • 3.1 Built-in Data Types
      • 3.1.1 Numeric Objects
      • 3.1.2 Missing Data
      • 3.1.3 String Objects
      • 3.1.4 Data Structure Objects.
      • 3.1.5 Cell Array Objects
    • 3.2 User-defined Data Types
    • 3.3 Object Sizes
  • 4 Numeric Data Types
    • 4.1 Matrices
      • 4.1.1 Empty Matrices
    • 4.2 Ranges
    • 4.3 Single Precision Data Types
    • 4.4 Integer Data Types
      • 4.4.1 Integer Arithmetic
    • 4.5 Bit Manipulations
    • 4.6 Logical Values
    • 4.7 Promotion and Demotion of Data Types.
    • 4.8 Predicates for Numeric Objects.
  • 5 Strings.
    • 5.1 Escape Sequences in string constants
    • 5.2 Character Arrays
    • 5.3 Creating Strings
      • 5.3.1 Concatenating Strings
      • 5.3.2 Conversion of Numerical Data to Strings.
    • 5.4 Comparing Strings
    • 5.5 Manipulating Strings
    • 5.6 String Conversions
    • 5.7 Character Class Functions
  • 6 Data Containers iii
    • 6.1 Data Structures
      • 6.1.1 Basic Usage and Examples
      • 6.1.2 Structure Arrays
      • 6.1.3 Creating Structures
      • 6.1.4 Manipulating Structures
      • 6.1.5 Processing Data in Structures
    • 6.2 Cell Arrays
      • 6.2.1 Basic Usage of Cell Arrays
      • 6.2.2 Creating Cell Array
      • 6.2.3 Indexing Cell Arrays
      • 6.2.4 Cell Arrays of Strings
      • 6.2.5 Processing Data in Cell Arrays
    • 6.3 Comma Separated Lists
      • 6.3.1 Comma Separated Lists Generated from Cell Arrays
  • 7 Variables
    • 7.1 Global Variables
    • 7.2 Persistent Variables
    • 7.3 Status of Variables
  • 8 Expressions
    • 8.1 Index Expressions
    • 8.2 Calling Functions
      • 8.2.1 Call by Value
      • 8.2.2 Recursion
    • 8.3 Arithmetic Operators
    • 8.4 Comparison Operators
    • 8.5 Boolean Expressions
      • 8.5.1 Element-by-element Boolean Operators
      • 8.5.2 Short-circuit Boolean Operators
    • 8.6 Assignment Expressions
    • 8.7 Increment Operators
    • 8.8 Operator Precedence
  • 9 Evaluation
    • 9.1 Calling a Function by its Name
    • 9.2 Evaluation in a Different Context
  • 10 Statements iv GNU Octave
    • 10.1 The if Statement
    • 10.2 The switch Statement
      • 10.2.1 Notes for the C programmer
    • 10.3 The while Statement
    • 10.4 The do-until Statement
    • 10.5 The for Statement
      • 10.5.1 Looping Over Structure Elements
    • 10.6 The break Statement
    • 10.7 The continue Statement
    • 10.8 The unwind_protect Statement
    • 10.9 The try Statement
    • 10.10 Continuation Lines
  • 11 Functions and Scripts
    • 11.1 Defining Functions
    • 11.2 Multiple Return Values
    • 11.3 Variable-length Argument Lists
    • 11.4 Variable-length Return Lists
    • 11.5 Returning From a Function
    • 11.6 Default Arguments
    • 11.7 Function Files
      • 11.7.1 Manipulating the load path
      • 11.7.2 Subfunctions
      • 11.7.3 Private Functions
      • 11.7.4 Overloading and Autoloading
      • 11.7.5 Function Locking
      • 11.7.6 Function Precedence
    • 11.8 Script Files
      • 11.9.1 Function Handles
      • 11.9.2 Anonymous Functions
      • 11.9.3 Inline Functions
    • 11.10 Commands
    • 11.11 Organization of Functions Distributed with Octave
  • 12 Errors and Warnings
    • 12.1 Handling Errors
      • 12.1.1 Raising Errors
      • 12.1.2 Catching Errors
    • 12.2 Handling Warnings
      • 12.2.1 Issuing Warnings
      • 12.2.2 Enabling and Disabling Warnings
  • 13 Debugging v
    • 13.1 Entering Debug Mode
    • 13.2 Leavinging Debug Mode
    • 13.3 Breakpoints
    • 13.4 Debug Mode
    • 13.5 Call Stack
  • 14 Input and Output
    • 14.1 Basic Input and Output
      • 14.1.1 Terminal Output
        • 14.1.1.1 Paging Screen Output
      • 14.1.2 Terminal Input
      • 14.1.3 Simple File I/O
        • 14.1.3.1 Saving Data on Unexpected Exits
      • 14.1.4 Rational Approximations
    • 14.2 C-Style I/O Functions
      • 14.2.1 Opening and Closing Files
      • 14.2.2 Simple Output
      • 14.2.3 Line-Oriented Input
      • 14.2.4 Formatted Output
      • 14.2.5 Output Conversion for Matrices
      • 14.2.6 Output Conversion Syntax
      • 14.2.7 Table of Output Conversions
      • 14.2.8 Integer Conversions
      • 14.2.9 Floating-Point Conversions
      • 14.2.10 Other Output Conversions
      • 14.2.11 Formatted Input
      • 14.2.12 Input Conversion Syntax
      • 14.2.13 Table of Input Conversions
      • 14.2.14 Numeric Input Conversions
      • 14.2.15 String Input Conversions
      • 14.2.16 Binary I/O
      • 14.2.17 Temporary Files
      • 14.2.18 End of File and Errors
      • 14.2.19 File Positioning
  • 15 Plotting
    • 15.1 Plotting Basics
      • 15.1.1 Two-Dimensional Plots
        • 15.1.1.1 Two-dimensional Function Plotting
      • 15.1.2 Three-Dimensional Plotting
        • 15.1.2.1 Three-dimensional Function Plotting
        • 15.1.2.2 Three-dimensional Geometric Shapes
      • 15.1.3 Plot Annotations
      • 15.1.4 Multiple Plots on One Page
      • 15.1.5 Multiple Plot Windows
      • 15.1.6 Printing Plots.
      • 15.1.7 Interacting with plots vi GNU Octave
      • 15.1.8 Test Plotting Functions
    • 15.2 Advanced Plotting
      • 15.2.1 Graphics Objects
      • 15.2.2 Graphics Object Properties
        • 15.2.2.1 Root Figure Properties
        • 15.2.2.2 Figure Properties
        • 15.2.2.3 Axes Properties
        • 15.2.2.4 Line Properties
        • 15.2.2.5 Text Properties
        • 15.2.2.6 Image Properties
        • 15.2.2.7 Patch Properties
        • 15.2.2.8 Surface Properties.
        • 15.2.2.9 Searching Properties
      • 15.2.3 Managing Default Properties
      • 15.2.4 Colors
      • 15.2.5 Line Styles
      • 15.2.6 Marker Styles
      • 15.2.7 Callbacks
      • 15.2.8 Object Groups
        • 15.2.8.1 Data sources in object groups
        • 15.2.8.2 Area series
        • 15.2.8.3 Bar series
        • 15.2.8.4 Contour groups
        • 15.2.8.5 Error bar series
        • 15.2.8.6 Line series
        • 15.2.8.7 Quiver group
        • 15.2.8.8 Scatter group
        • 15.2.8.9 Stair group
        • 15.2.8.10 Stem Series
        • 15.2.8.11 Surface group
      • 15.2.9 Graphics backends
        • 15.2.9.1 Interaction with gnuplot
  • 16 Matrix Manipulation
    • 16.1 Finding Elements and Checking Conditions
    • 16.2 Rearranging Matrices
    • 16.3 Applying a Function to an Array
    • 16.4 Special Utility Matrices
    • 16.5 Famous Matrices.
  • 17 Arithmetic vii
    • 17.1 Exponents and Logarithms
    • 17.2 Complex Arithmetic
    • 17.3 Trigonometry
    • 17.4 Sums and Products
    • 17.5 Utility Functions.
    • 17.6 Special Functions
    • 17.7 Coordinate Transformations.
    • 17.8 Mathematical Constants
  • 18 Linear Algebra
    • 18.1 Techniques used for Linear Algebra
    • 18.2 Basic Matrix Functions
    • 18.3 Matrix Factorizations
    • 18.4 Functions of a Matrix
    • 18.5 Specialized Solvers
  • 19 Nonlinear Equations
  • 20 Diagonal and Permutation Matrices. - 20.1.1 Creating Diagonal Matrices - 20.1.2 Creating Permutation Matrices - 20.1.3 Explicit and Implicit Conversions
    • 20.2 Linear Algebra with Diagonal and Permutation Matrices
      • 20.2.1 Expressions Involving Diagonal Matrices
      • 20.2.2 Expressions Involving Permutation Matrices
    • 20.3 Functions That Are Aware of These Matrices.
      • 20.3.1 Diagonal Matrix Functions
      • 20.3.2 Permutation Matrix Functions
    • 20.4 Some Examples of Usage
    • 20.5 The Differences in Treatment of Zero Elements
  • 21 Sparse Matrices
    • 21.1 The Creation and Manipulation of Sparse Matrices
      • 21.1.1 Storage of Sparse Matrices
      • 21.1.2 Creating Sparse Matrices
      • 21.1.3 Finding out Information about Sparse Matrices
      • 21.1.4 Basic Operators and Functions on Sparse Matrices
        • 21.1.4.1 Sparse Functions
        • 21.1.4.2 The Return Types of Operators and Functions.
        • 21.1.4.3 Mathematical Considerations
    • 21.2 Linear Algebra on Sparse Matrices
    • 21.3 Iterative Techniques applied to sparse matrices
    • 21.4 Real Life Example of the use of Sparse Matrices
  • 22 Numerical Integration viii GNU Octave
    • 22.1 Functions of One Variable.
    • 22.2 Orthogonal Collocation
    • 22.3 Functions of Multiple Variables
  • 23 Differential Equations
    • 23.1 Ordinary Differential Equations
    • 23.2 Differential-Algebraic Equations
  • 24 Optimization
    • 24.1 Linear Programming
    • 24.2 Quadratic Programming
    • 24.3 Nonlinear Programming.
    • 24.4 Linear Least Squares
  • 25 Statistics
    • 25.1 Descriptive Statistics.
    • 25.2 Basic Statistical Functions
    • 25.3 Statistical Plots
    • 25.4 Tests
    • 25.5 Models
    • 25.6 Distributions
    • 25.7 Random Number Generation
  • 26 Sets
    • 26.1 Set Operations
  • 27 Polynomial Manipulations
    • 27.1 Evaluating Polynomials
    • 27.2 Finding Roots
    • 27.3 Products of Polynomials
    • 27.4 Derivatives and Integrals
    • 27.5 Polynomial Interpolation
    • 27.6 Miscellaneous Functions.
  • 28 Interpolation
    • 28.1 One-dimensional Interpolation
    • 28.2 Multi-dimensional Interpolation
  • 29 Geometry
    • 29.1 Delaunay Triangulation
      • 29.1.1 Plotting the Triangulation
      • 29.1.2 Identifying points in Triangulation
    • 29.2 Voronoi Diagrams.
    • 29.3 Convex Hull
    • 29.4 Interpolation on Scattered Data
  • 30 Signal Processing ix
  • 31 Image Processing
    • 31.1 Loading and Saving Images
    • 31.2 Displaying Images
    • 31.3 Representing Images
    • 31.4 Plotting on top of Images
    • 31.5 Color Conversion
  • 32 Audio Processing
  • 33 Object Oriented Programming
    • 33.1 Creating a Class
    • 33.2 Manipulating Classes
    • 33.3 Indexing Objects
    • 33.4 Overloading Objects
      • 33.4.1 Function Overloading
      • 33.4.2 Operator Overloading
      • 33.4.3 Precedence of Objects
    • 33.5 Inheritance and Aggregation
  • 34 System Utilities
    • 34.1 Timing Utilities
    • 34.2 Filesystem Utilities
    • 34.3 File Archiving Utilities
    • 34.4 Networking Utilities
    • 34.5 Controlling Subprocesses
    • 34.6 Process, Group, and User IDs
    • 34.7 Environment Variables
    • 34.8 Current Working Directory
    • 34.9 Password Database Functions
    • 34.10 Group Database Functions
    • 34.11 System Information
    • 34.12 Hashing Functions
  • 35 Packages
    • 35.1 Installing and Removing Packages
    • 35.2 Using Packages
    • 35.3 Administrating Packages
    • 35.4 Creating Packages
      • 35.4.1 The DESCRIPTION File
      • 35.4.2 The INDEX file
      • 35.4.3 PKG ADD and PKG DEL directives
    • A.1 Oct-Files
      • A.1.1 Getting Started with Oct-Files
      • A.1.2 Matrices and Arrays in Oct-Files
      • A.1.3 Character Strings in Oct-Files
      • A.1.4 Cell Arrays in Oct-Files
      • A.1.5 Structures in Oct-Files.
      • A.1.6 Sparse Matrices in Oct-Files
        • A.1.6.2 Creating Sparse Matrices in Oct-Files
        • A.1.6.3 Using Sparse Matrices in Oct-Files
      • A.1.7 Accessing Global Variables in Oct-Files
      • A.1.8 Calling Octave Functions from Oct-Files
      • A.1.9 Calling External Code from Oct-Files
      • A.1.10 Allocating Local Memory in Oct-Files
      • A.1.11 Input Parameter Checking in Oct-Files
      • A.1.12 Exception and Error Handling in Oct-Files
      • A.1.13 Documentation and Test of Oct-Files
    • A.2 Mex-Files
      • A.2.1 Getting Started with Mex-Files
      • A.2.2 Working with Matrices and Arrays in Mex-Files
      • A.2.3 Character Strings in Mex-Files
      • A.2.4 Cell Arrays with Mex-Files
      • A.2.5 Structures with Mex-Files
      • A.2.6 Sparse Matrices with Mex-Files
      • A.2.7 Calling Other Functions in Mex-Files
    • A.3 Standalone Programs
  • Appendix B Test and Demo Functions
    • B.1 Test Functions
    • B.2 Demonstration Functions
  • Appendix C Tips and Standards
    • C.1 Writing Clean Octave Programs
    • C.2 Tips for Making Code Run Faster.
    • C.3 Tips on Writing Comments
    • C.4 Conventional Headers for Octave Functions
    • C.5 Tips for Documentation Strings
  • Appendix D Contributing Guidelines
    • D.1 How to Contribute
    • D.2 General Guidelines
    • D.3 Octave Sources (m-files)
    • D.4 C++ Sources.
    • D.5 Other Sources
  • Appendix E Known Causes of Trouble xi
    • E.1 Actual Bugs We Haven’t Fixed Yet
    • E.2 Reporting Bugs.
    • E.3 Have You Found a Bug?
    • E.4 Where to Report Bugs
    • E.5 How to Report Bugs
    • E.6 Sending Patches for Octave
    • E.7 How To Get Help with Octave
  • Appendix F Installing Octave
    • F.1 Installation Problems
  • Appendix G Emacs Octave Support
    • G.1 Installing EOS
    • G.2 Using Octave Mode
    • G.3 Running Octave From Within Emacs
    • G.4 Using the Emacs Info Reader for Octave
      • LICENSE Appendix H GNU GENERAL PUBLIC
  • Concept Index.
  • Function Index
  • Operator Index

2 GNU Octave

Thomas D. Dean Philippe Defert Bill Denney David M. Doolin Pascal A. Dupuis John W. Eaton Dirk Eddelbuettel Paul Eggert Stephen Eglen Peter Ekberg Rolf Fabian Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose Daniel Munoz Frias Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne Grossmann Peter Gustafson Kai Habel William P. Y. Hadisoeseno Jaroslav Hajek Benjamin Hall Kim Hansen Soren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Yozo Hida Ryan Hinton Roman Hodek A. Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher Hulbert Cyril Humbert Teemu Ikonen Alan W. Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G. Johnson Heikki Junes Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Thomas Kasper Joel Keay Mumit Khan Paul Kienzle Aaron A. King Arno J. Klaassen Geoffrey Knauth Heine Kolltveit Ken Kouno Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun Friedrich Leisch Timo Lindfors Benjamin Lindner Ross Lippert David Livings Erik de Castro Lopo Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Ricardo Marranita Orestes Mas Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G. D. McBain Alexander Mamonov Christoph Mayer Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P. Mueller Victor Munoz Carmen Navarrete Todd Neal Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael O’Brien Peter O’Gorman Thorsten Ohl Arno Onken Luis F. Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Robert Platt Hans Ekkehard Plesser Tom Poage Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potorti James B. Rawlings Eric S. Raymond Balint Reczey Michael Reifenberger Jason Riedy Petter Risholm Matthew W. Roberts

Preface 3

Andrew Ross Mark van Rossum Kevin Ruland Ryan Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schloegl Michel D. Schmid Julian Schnidder Nicol N. Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L. Scofield Daniel J. Sebald Dmitri A. Sergatskov Baylis Shanks Joseph P. Skudlarek John Smith Julius Smith Shan G. Smith Joerg Specht Quentin H. Spencer Christoph Spiel Richard Stallman Russell Standish Doug Stewart Jonathan Stickel Thomas Stuart Ivan Sutoris John Swensen Ariel Tankus Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Thomas Treichl Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R. Van Zandt Gregory Vanuxem Ivana Varekova Thomas Walter Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel Michael Weitzel Fook Fah Yap Michael Zeising Federico Zenith Alex Zvoleff

Special thanks to the following people and organizations for supporting the development of Octave:

  • The United States Department of Energy, through grant number DE-FG02-04ER25635.
  • Ashok Krishnamurthy, David Hudak, Juan Carlos Chaves, and Stanley C. Ahalt of the Ohio Supercomputer Center.
  • The National Science Foundation, through grant numbers CTS-0105360, CTS-9708497, CTS-9311420, CTS-8957123, and CNS-0540147.
  • The industrial members of the Texas-Wisconsin Modeling and Control Consortium (TWMCC).
  • The Paul A. Elfers Endowed Chair in Chemical Engineering at the University of Wisconsin-Madison.
  • Digital Equipment Corporation, for an equipment grant as part of their External Re- search Program.
  • Sun Microsystems, Inc., for an Academic Equipment grant.
  • International Business Machines, Inc., for providing equipment as part of a grant to the University of Texas College of Engineering.
  • Texaco Chemical Company, for providing funding to continue the development of this software.
  • The University of Texas College of Engineering, for providing a Challenge for Excellence Research Supplement, and for providing an Academic Development Funds grant.
  • The State of Texas, for providing funding through the Texas Advanced Technology Program under Grant No. 003658-078.
  • Noel Bell, Senior Engineer, Texaco Chemical Company, Austin Texas.

Chapter 1: A Brief Introduction to Octave 5

1 A Brief Introduction to Octave

GNU Octave is a high-level language, primarily intended for numerical computations. It provides a convenient interactive command line interface for solving linear and nonlinear problems numerically, and for performing other numerical experiments. It may also be used as a batch-oriented language for data processing.

GNU Octave is freely redistributable software. You may redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. The GPL is included in this manual in Appendix H [Copying], page 641.

This manual provides comprehensive documentation on how to install, run, use, and extend GNU Octave. Additional chapters describe how to report bugs and help contribute code.

This document corresponds to Octave version 3.2.4.

1.1 Running Octave

On most systems, Octave is started with the shell command ‘octave’. Octave displays an initial message and then a prompt indicating it is ready to accept input. You can begin typing Octave commands immediately afterward.

If you get into trouble, you can usually interrupt Octave by typing Control-C (written C-c for short). C-c gets its name from the fact that you type it by holding down CTRL and then pressing C. Doing this will normally return you to Octave’s prompt.

To exit Octave, type quit, or exit at the Octave prompt. On systems that support job control, you can suspend Octave by sending it a SIGTSTP signal, usually by typing C-z.

1.2 Simple Examples

The following chapters describe all of Octave’s features in detail, but before doing that, it might be helpful to give a sampling of some of its capabilities.

If you are new to Octave, I recommend that you try these examples to begin learning Octave by using it. Lines marked with ‘octave:13>’ are lines you type, ending each with a carriage return. Octave will respond with an answer, or by displaying a graph.

1.2.1 Elementary Calculations

Octave can easily be used for basic numerical calculations. Octave knows about arithmetic operations (+,-,*,/), exponentiation (^), natural logarithms/exponents (log, exp), and the trigonometric functions (sin, cos,... ). Moreover, Octave calculations work on real or imaginary numbers (i,j). In addition, some mathematical constants such as the base of the natural logarithm (e) and the ratio of a circle’s circumference to its diameter (pi) are pre-defined.

For example, to verify Euler’s Identity,

eıπ^ = − 1

type the following which will evaluate to -1 within the tolerance of the calculation.

octave:1> exp(i*pi)

6 GNU Octave

1.2.2 Creating a Matrix

Vectors and matrices are the basic building blocks for numerical analysis. To create a new matrix and store it in a variable so that you can refer to it later, type the command

octave:1> A = [ 1, 1, 2; 3, 5, 8; 13, 21, 34 ]

Octave will respond by printing the matrix in neatly aligned columns. Octave uses a comma or space to separate entries in a row, and a semicolon or carriage return to separate one row from the next. Ending a command with a semicolon tells Octave not to print the result of the command. For example,

octave:2> B = rand (3, 2);

will create a 3 row, 2 column matrix with each element set to a random value between zero and one.

To display the value of a variable, simply type the name of the variable at the prompt. For example, to display the value stored in the matrix B, type the command

octave:3> B

1.2.3 Matrix Arithmetic

Octave has a convenient operator notation for performing matrix arithmetic. For example, to multiply the matrix A by a scalar value, type the command

octave:4> 2 * A

To multiply the two matrices A and B, type the command

octave:5> A * B

and to form the matrix product AT^ A, type the command

octave:6> A’ * A

1.2.4 Solving Systems of Linear Equations

Systems of linear equations are ubiquitous in numerical analysis. To solve the set of linear equations Ax = b, use the left division operator, ‘\’:

x = A \ b

This is conceptually equivalent to A−^1 b, but avoids computing the inverse of a matrix directly.

If the coefficient matrix is singular, Octave will print a warning message and compute a minimum norm solution.

A simple example comes from chemistry and the need to obtain balanced chemical equations. Consider the burning of hydrogen and oxygen to produce water.

H 2 + O 2 → H 2 O

The equation above is not accurate. The Law of Conservation of Mass requires that the number of molecules of each type balance on the left- and right-hand sides of the equation. Writing the variable overall reaction with individual equations for hydrogen and oxygen one finds: