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, we recommend that you try these examples to begin learning Octave by using it. Lines marked like so, 'octave:13>', are lines you type, ending each with a carriage return. Octave will respond with an answer, or by displaying a graph.
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.
type the following which will evaluate to -1 within the tolerance of the calculation.
will create a 3 row, 2 column matrix with each element set to a random value between zero and one.
This is conceptually equivalent to inv (A) * 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.
The solution in Octave is found in just three steps.
For Octave to integrate equations of this form, you must first provide a definition of the function f(x,t). This is straightforward, and may be accomplished by entering the function body directly on the command line. For example, the following commands define the right-hand side function for an interesting pair of nonlinear differential equations. Note that while you are entering a function, Octave responds with a different prompt, to indicate that it is waiting for you to complete your input.
The function lsode uses the Livermore Solver for Ordinary Differential Equations, described in A. C. Hindmarsh, ODEPACK, a Systematized Collection of ODE Solvers , in: Scientific Computing, R. S. Stepleman et al. (Eds.), North-Holland, Amsterdam, 1983, pages 55–64.
Octave will automatically create a separate window to display the plot.
explains more options for the print command and provides a list of additional output file formats.
Octave has an extensive help facility. The same documentation that is available in printed form is also available from the Octave prompt, because both forms of the documentation are created from the same input file.
In order to get good help you first need to know the name of the command that you want to use. The name of this function may not always be obvious, but a good place to start is to type help --list. This will show you all the operators, keywords, built-in functions, and loadable functions available in the current session of Octave. An alternative is to search the documentation using the lookfor function (described in Getting Help).
will display the help text for the plot function.
Octave sends output that is too long to fit on one screen through a pager like less or more. Type a RET to advance one line, a SPC to advance one page, and q to quit the pager.
The part of Octave's help facility that allows you to read the complete text of the printed manual from within Octave normally uses a separate program called Info. When you invoke Info you will be put into a menu driven program that contains the entire Octave manual. Help for using Info is provided in this manual, see Getting Help.
At the Octave prompt, you can recall, edit, and reissue previous commands using Emacs- or vi-style editing commands. The default keybindings use Emacs-style commands. For example, to recall the previous command, press Control-p (written C-p for short). Doing this will normally bring back the previous line of input. C-n will bring up the next line of input, C-b will move the cursor backward on the line, C-f will move the cursor forward on the line, etc.
A complete description of the command line editing capability is given in this manual, see Command Line Editing.