You are on page 1of 3

Starting Octave

octave octave octave --help

Octave Quick Reference


le

Octave Version 1.0

start interactive Octave session run Octave on commands in le describe command line options exit Octave (e.g. C-c) terminate current command and return to top-level prompt

C-k C-y M-d M-DEL M-y

Killing and Yanking

kill to the end of the line yank the most recently killed text kill to the end of the current word kill the word behind the cursor rotate the kill ring and yank the new top

Stopping Octave
quit or exit INTERRUPT

Getting Help
help help help -i help -i

command

list all commands and built-in variables brie y describe command use Info to browse Octave manual command search for command in Octave manual scroll forward one screenful scroll backward one screenful redraw the display select the next node select the previous node select the `up' node select the `top' node select the directory node select the rst node in the current le select the last node in the current le reads the name of a node and selects it kills the current node search for a string search forward incrementally search backward incrementally search index & go to corresponding node go to next match from last `i' command move back one character move forward one character move the the start of the line move to the end of the line move forward a word move backward a word clear screen, reprinting current line at top insert a tab character delete character to the left of the cursor delete character under the cursor add the next character verbatim transpose characters at the point transpose words at the point

Motion in Info
SPC DEL C-l

or C-v or M-v

n p u t d < > g C-x k

Node Selection in Info

complete a command or variable name list possible completions enter the current line move `up' through the history list move `down' through the history list move to the rst line in the history move to the last line in the history search backward in the history list search forward in the history list history -q] N ] list N previous history lines, omitting history numbers if -q history -w le] write history to le ( /.octave hist if no le argument) history -r le] read history from le ( /.octave hist if no le argument) edit history lines edit and then run previous commands from the history list run history lines run previous commands from the history list beg ] end ] Specify the rst and last history commands to edit or run. If beg is greater than end, reverse the list of commands before editing. If end is omitted, select commands from beg to the end of the history list. If both arguments are omitted, edit the previous item in the history list.
TAB M-? RET C-p C-n M-< M-> C-r C-s

Command Completion and History

A string constant consists of a sequence of characters enclosed in either double-quote or single-quote marks. \\ a literal backslash \" a literal double-quote character \' a literal single-quote character \n newline, ASCII code 10 \t horizontal tab, ASCII code 9

Strings and Common Escape Sequences

var (idx) var (idx1, idx2) scalar vector range


:

Index Expressions

select elements of a vector select elements of a matrix select row (column) corresponding to scalar select rows (columns) corresponding to the elements of vector select rows (columns) corresponding to the elements of range select all rows (columns)

Global Variables
global

Searching in Info
s C-s C-r i ,

Shell Commands
cd pwd

dir

ls

getenv (

options] string) cmd)

Command-Line Cursor Motion


C-b C-f C-a C-e M-f M-b C-l

shell cmd (

change working directory to dir print working directory print directory listing return value of named environment variable execute arbitrary shell command string

Matrices

Inserting or Changing Text


M-TAB DEL C-d C-v C-t M-t
]

Square brackets delimit literal matrices. Commas separate elements on the same row. Semicolons separate rows. Commas may be replaced by spaces, and semicolons may be replaced by one or more newlines. Elements of a matrix may be arbitrary expressions, provided that all the dimensions agree. x, y, ... ] enter a row vector x; y; ... ] enter a column vector w, x; y, z ] enter a 2 2 matrix

maximum representable value minimum representable value automatic replot automatically redraw plots Fortran-style indexing of matrices do fortran indexing implicit str to num ok allow strings to become numbers output max field width maximum numeric eld width min signi cant gures displayed output precision page screen output control whether output is paged prefer column vectors create column vectors by default resize on range error automatic resizing of matrices digits stored by save command save precision silent functions suppress output from functions warn divide by zero suppress divide by zero errors
commas in literal matrix

EDITOR Inf, NaN LOADPATH PAGER ans eps pi realmax realmin

Selected Built-in Variables

var1 ... Declare variables global. Global variables may be accessed inside the body of a function without having to be passed in the function parameter list provided they are also declared global within the function.
editor to use with edit history IEEE in nity, NaN path to search for function les program to use to paginate output last result not explicitly assigned machine precision

control handling of spaces in matrices

surround optional arguments ... show one or more arguments Copyright 1994, John W. Eaton Permissions on back

base : limit base : incr : limit Specify a range of values beginning with base with no elements greater than limit. If it is omitted, the default value of incr is 1. Negative increments are permitted.

Ranges

ignore function time stamp ok to lose imaginary part prefer zero one indexing

ignore changes in function les during session allow complex to real conversion if ambiguous, prefer 0-1 style indexing

Arithmetic and Increment Operators


x+y x-y x*y x .* y x/y x ./ y x\y x .\ y x^y x .^ y - x + x x' x .' ++ x (-- x) x ++ (x --) var = expr var (idx) = expr

addition subtraction matrix multiplication element by element multiplication right division, conceptually equivalent to element by element right division left division, conceptually equivalent to
(inverse (y') * x')' inverse (x) * y

Statements
for

identi er = expr stmt-list endfor Execute stmt-list once for each column of expr. The variable identi er is set to the value of the current column during each iteration. condition) stmt-list endwhile Execute stmt-list while condition is true.
exit innermost loop go to beginning of innermost loop return to calling function

Linear Algebra
chol ( ) det ( ) eig ( ) expm ( ) hess ( ) inverse ( ) norm ( , ) pinv ( ) qr ( ) rank ( ) schur ( ) svd ( ) syl ( , , )

while (

a a a a a

element by element left division power operator element by element power operator negation unary plus (a no-op) complex conjugate transpose transpose increment (decrement) x, return new value increment (decrement) x, return old value assign expression to variable assign expression to indexed variable

break continue return if (

a a p a

Assignment Expressions

Comparison and Boolean Operators

These operators work on an element-by-element basis. Both arguments are always evaluated. x<y true if x is less than y x <= y true if x is less than or equal to y x == y true if x is greater than y x >= y true if x is greater than or equal to y x>y true if x is equal to y x != y true if x is not equal to y x&y true if both x and y are true x|y true if at least one of x or y is true ! bool true bool is false

condition) if-body else else-body] endif Execute if-body if condition is true, otherwise execute elsebody. if (condition) if-body elseif (condition) elseif-body] endif Execute if-body if condition is true, otherwise execute the elseif-body corresponding to the rst elseif condition that is true, otherwise execute else-body. Any number of elseif clauses may appear in an if statement. unwind protect body unwind protect cleanup cleanup end Execute body. Execute cleanup no matter how control exits body.

a a a b c

Cholesky factorization compute the determinant of a matrix eigenvalues and eigenvectors compute the exponential of a matrix compute Hessenberg decomposition invert a square matrix compute the p-norm of a matrix compute pseudoinverse of a compute the QR factorization of a matrix matrix rank Schur decomposition of a matrix singular value decomposition solve the Sylvester equation solve nonlinear algebraic equations integrate nonlinear ODEs integrate nonlinear DAEs integrate nonlinear functions

*fsolve *lsode *dassl *quad

Equations, ODEs, DAEs, Quadrature

perror (

nm, code) for functions that return numeric codes, print error message for named function and given error code * See the on-line or printed manual for the complete list of arguments for these functions.

De ning Functions
function endfunction

Signal Processing
fft ( ) ifft ( ) freqz ( sinc ( )

ret-list] function-name (arg-list) ] function-body

a x

args)

Fast Fourier Transform using FFTPACK inverse FFT using FFTPACK FIR lter frequency response returns sin ( x)/( x)

Operators evaluate left-to-right, expecting scalar operands. Operands are only evaluated if necessary, stopping once overall truth value can be determined. Operands are converted to scalars by applying the all function. x && y true if both x and y are true x || y true if at least one of x or y is true Here is a table of the operators in Octave, in order of increasing precedence. ; , statement separators = assignment, groups left to right || && logical \or" and \and" | & element-wise \or" and \and" < <= == >= > != relational operators : colon + addition and subtraction * / \ .* ./ .\ multiplication and division ' .' transpose + - ++ -- ! unary minus, increment, logical \not" ^ .^ exponentiation

Short-circuit Boolean Operators

ret-list may be a single identi er or a comma-separated list of identi ers delimited by square-brackets. arg-list is a comma-separated list of identi ers and may be empty.
rows ( ) columns ( ) all ( ) any ( ) find ( ) sort ( ) sum ( ) prod ( ) min ( ) max ( ) rem ( , ) reshape ( ,

Basic Matrix Manipulations


a a

Operator Precedence

return number of rows of a return number of columns of a a check if all elements of a nonzero a check if any elements of a nonzero a return indices of nonzero elements a order elements in each column of a a sum elements in columns of a a product of elements in columns of a args nd minimum values args nd maximum values x y nd remainder of x/y a m, n) reformat a to be m by n create diagonal matrices b l n) create vector of linearly-spaced elements b l n) create vector of log-spaced elements n m create n by m identity matrix n m create n by m matrix of ones n m create n by m matrix of zeros n m create n by m matrix of random values

colormap ( ) gray2ind ( , ) image ( , ) imagesc ( , ) imshow ( , ) imshow ( , ) imshow ( , , ) ind2gray ( , ) ind2rgb ( , ) loadimage ( ) rgb2ind ( , , ) saveimage ( , ,

Image Processing

diag ( , ) linspace ( , , logspace ( , , eye ( , ) ones ( , ) zeros ( , ) rand ( , )

v k

create set ( , ) complement ( , ) intersection ( , ) union ( , )

Sets

map set the current colormap i n convert gray scale to Octave image img zoom display an Octave image matrix img zoom display scaled matrix as image img map display Octave image i n display gray scale image r g b display RGB image img map convert Octave image to gray scale img map convert indexed image to RGB le load an image le r g b convert RGB to Octave image le img fmt, map) save a matrix to le a b a b a b
create row vector of unique values elements of b not in a intersection of sets a and b union of sets a and b compare strings concatenate strings

a b

Strings

strcmp ( , ) strcat ( , , ...)

s t s t

C-style Input and Output


fopen ( , ) fclose ( ) printf ( , ...) fprintf ( , , ...) sprintf ( , ...) scanf ( ) fscanf ( , ) sscanf ( , ) fgets ( , ) fflush ( ) ftell ( ) frewind ( ) freport fread ( , , ) fwrite ( , , ) feof ( )

open le name close le formatted output to stdout formatted output to le formatted output to string formatted input from stdin formatted input from le formatted input from string read len characters from le ush pending output to le return le pointer position move le pointer to beginning print a info for open les le size prec read binary data les le size prec write binary data les le determine if pointer is at EOF A le may be referenced either by name or by the number returned from fopen. Three les are preconnected when Octave starts: stdin, stdout, and stderr.

name mode le fmt le fmt fmt fmt le fmt str fmt le len le le le

ranges] expr using] title] style] 2D plotting gsplot ranges] expr using] title] style] 3D plotting ranges specify data ranges expr expression to plot using specify columns to plot title specify line title for legend style specify line style If ranges are supplied, they must come before the expression to plot. The using , title , and style options may appear in any order after expr . Multiple expressions may be plotted with a single command by separating them with commas. set options set plotting options show options show plotting options replot redisplay current plot closeplot close stream to gnuplot process purge tmp files clean up temporary plotting les automatic replot built-in variable
gplot

Basic Plotting

Other Input and Output functions


save load disp (

Other Plotting Functions


plot ( ) semilogx ( ) semilogy ( ) loglog ( ) bar ( ) stairs ( , ) hist ( , )

le var ... le var)

save variables in le load variables from le display value of var to screen

eval ( ) feval ( , ...) error ( clear exist ( who

Miscellaneous Functions
str str message)

evaluate str as a command evaluate function named by str, passing remaining args to called function print message and return to top level

args args args args x y y x string)

args

2D plot with linear axes 2D plot with logarithmic x-axis 2D plot with logarithmic y-axis 2D plot with logarithmic axes plot bar charts plot stairsteps plot histograms set plot title set axis ranges set x-axis label set y-axis label set grid state set hold state return 1 if hold is on, 0 otherwise plot 3D surface create mesh coordinate matrices

title (

pattern str)

Polynomials
p a b a b a p p

clear variables matching pattern check existence of variable or function list current variables companion matrix convolution deconvolve two vectors create polynomial from a matrix derivative of polynomial integral of polynomial value of polynomial at x value of polynomial at x polynomial roots partial fraction expansion of ratio a/b correlation coe cient covariance mean value median value standard deviation variance

axis ( xlabel ( ylabel ( grid hold ishold

limits) string) string) onjo ] onjo ] x y z x y

compan ( ) conv ( , ) deconv ( , ) poly ( ) polyderiv ( ) polyreduce ( ) polyval ( , ) polyvalm ( , ) roots ( ) residue ( , )

mesh ( , , ) meshdom ( , )

p p x p x a b

Statistics
x y a a a a

corrcoef ( , cov ( , ) mean ( ) median ( ) std ( ) var ( )

x y)

Edition 1.1 for Octave Version 1.1.0. Copyright 1994, 1995, John W. Eaton (jwe@che.utexas.edu). The author assumes no responsibility for any errors on this card. This card may be freely distributed under the terms of the GNU General Public License. TEX Macros for this card by Roland Pesch (pesch@cygnus.com), originally for the GDB reference card Octave itself is free software; you are welcome to distribute copies of it under the terms of the GNU General Public License. There is absolutely no warranty for Octave.

You might also like