11.07.2015 Views

Octave Quick Reference Octave Version 1.1.1

Octave Quick Reference Octave Version 1.1.1

Octave Quick Reference Octave Version 1.1.1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Arithmetic and Increment Operatorsx + yadditionx - ysubtractionx * ymatrix multiplicationx .* yx / y(inverse (y’) * x’)’x ./ yx \ yinverse (x) * yx .\ yelement by element left divisionx ^ ypower operatorx .^ yelement by element multiplicationright division, conceptually equivalent toelement by element right divisionleft division, conceptually equivalent toelement by element power operator- x negation+ x unary plus (a no-op)x ’complex conjugate transposex .’transpose++ x (-- x) increment (decrement) x, returnnew valuex ++ (x --) increment (decrement) x, returnold valueAssignment Expressionsvar = exprvar (idx) =exprassign expression to variableassign expression to indexed variableComparison and Boolean OperatorsThese operators work on an element-by-element basis. Botharguments are always evaluated.x < ytrue if x is less than yx = ytrue if x is greater than or equal to yx > ytrue if x is equal to yx != ytrue if x is not equal to yx & ytrue if both x and y are truex | ytrue if at least one of x or y is true! bool true bool is falseShort-circuit Boolean OperatorsOperators evaluate left-to-right, expecting scalar operands.Operands are only evaluated if necessary, stoppingonce overalltruth value can be determined. Operands are converted toscalars by applyingthe all function.x && ytrue if both x and y are truex || ytrue if at least one of x or y is trueOperator PrecedenceHere is a table of the operators in <strong>Octave</strong>, in order ofincreasingprecedence.; , 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”^ .^ exponentiationStatementsfor identifier = expr stmt-list endforExecute stmt-list once for each column of expr. The variableidentifier is set to the value of the current column duringeach iteration.while (condition) stmt-list endwhileExecute stmt-list while condition is true.breakcontinuereturnexit innermost loopgo to beginning of innermost loopreturn to callingfunctionif (condition) if-body [else else-body] endifExecute if-body if condition is true, otherwise execute elsebody.if (condition) if-body [elseif (condition) elseif-body] endifExecute if-body if condition is true, otherwise execute theelseif-body correspondingto the first elseif condition thatis true, otherwise execute else-body.Any number of elseif clauses may appear in an ifstatement.unwind protect body unwind protect cleanup cleanup endExecute body. Execute cleanup no matter how control exitsbody.Defining Functionsfunction [ret-list] function-name [ (arg-list) ]function-bodyendfunctionret-list may be a single identifier or a comma-separated list ofidentifiers delimited by square-brackets.arg-list is a comma-separated list of identifiers and may beempty.Basic Matrix Manipulationsrows (a)columns (a)all (a)any (a)find (a)sort (a)sum (a)prod (a)return number of rows of areturn number of columns of acheck if all elements of a nonzerocheck if any elements of a nonzeroreturn indices of nonzero elementsorder elements in each column of asum elements in columns of aproduct of elements in columns of amin (args)find minimum valuesmax (args)find maximum valuesrem (x, y)find remainder of x/yreshape (a, m, n) reformat a to be m by ndiag (v, k) create diagonal matriceslinspace (b, l, n) create vector of linearly-spaced elementslogspace (b, l, n) create vector of log-spaced elementseye (n, m) create n by m identity matrixones (n, m) create n by m matrix of oneszeros (n, m) create n by m matrix of zerosrand (n, m) create n by m matrix of random valuesLinear Algebrachol (a)det (a)eig (a)expm (a)hess (a)inverse (a)norm (a, p)pinv (a)qr (a)rank (a)schur (a)svd (a)syl (a, b, c)Cholesky factorizationcompute the determinant of a matrixeigenvalues and eigenvectorscompute the exponential of a matrixcompute Hessenbergdecompositioninvert a square matrixcompute the p-norm of a matrixcompute pseudoinverse of acompute the QR factorization of a matrixmatrix rankSchur decomposition of a matrixsingular value decompositionsolve the Sylvester equationEquations, ODEs, DAEs, Quadrature*fsolve*lsodeintegrate nonlinear ODEs*dasslintegrate nonlinear DAEs*quadintegrate nonlinear functionssolve nonlinear algebraic equationsperror (nm, code) for functions that return numeric codes,print error message for named functionand given error code* See the on-line or printed manual for the complete list ofarguments for these functions.Signal Processingfft (a)ifft (a)Fast Fourier Transform usingFFTPACKinverse FFT usingFFTPACKfreqz (args) FIR filter frequency responsesinc (x) returns sin (π x)/(π x)Image Processingcolormap (map)gray2ind (i, n)set the current colormapconvert gray scale to <strong>Octave</strong> imageimage (img, zoom) display an <strong>Octave</strong> image matriximagesc (img, zoom) display scaled matrix as imageimshow (img, map) display <strong>Octave</strong> imageimshow (i, n)display gray scale imageimshow (r, g, b)display RGB imageind2gray (img, map) convert <strong>Octave</strong> image to gray scaleind2rgb (img, map) convert indexed image to RGBloadimage (file)load an image filergb2ind (r, g, b) convert RGB to <strong>Octave</strong> imagesaveimage (file, img, fmt, map) save a matrix to fileSetscreate set (a, b)complement (a, b)intersection (a, b)union (a, b)Stringsstrcmp (s, t)strcat (s, t, ...)create row vector of unique valueselements of b not in aintersection of sets a and bunion of sets a and bcompare stringsconcatenate strings


C-style Input and Outputfopen (name, mode) open file namefclose (file)close fileprintf (fmt, ...) formatted output to stdoutfprintf (file, fmt, ...) formatted output to filesprintf (fmt, ...) formatted output to stringscanf (fmt)formatted input from stdinfscanf (file, fmt) formatted input from filesscanf (str, fmt) formatted input from stringfgets (file, len)read len characters from filefflush (file)flush pendingoutput to fileftell (file)return file pointer positionfrewind (file)move file pointer to beginningfreportprint a info for open filesfread (file, size, prec) read binary data filesfwrite (file, size, prec) write binary data filesfeof (file)determine if pointer is at EOFA file may be referenced either by name or by the numberreturned from fopen. Three files are preconnected when <strong>Octave</strong>starts: stdin, stdout, andstderr.Other Input and Output functionssave file var ...load filedisp (var)Miscellaneous Functionseval (str)feval (str, ...)error (message)clear patternexist (str)whoPolynomialscompan (p)conv (a, b)deconv (a, b)poly (a)polyderiv (p)polyreduce (p)polyval (p, x)polyvalm (p, x)roots (p)residue (a, b)Statisticscorrcoef (x, y)cov (x, y)mean (a)median (a)std (a)var (a)save variables in fileload variables from filedisplay value of var to screenevaluate str as a commandevaluate function named by str, passingremainingargs to called functionprint message and return to top levelclear variables matchingpatterncheck existence of variable or functionlist current variablescompanion matrixconvolutiondeconvolve two vectorscreate polynomial from a matrixderivative of polynomialintegral of polynomialvalue of polynomial at xvalue of polynomial at xpolynomial rootspartial fraction expansion of ratio a/bcorrelation coefficientcovariancemean valuemedian valuestandard deviationvarianceBasic Plottinggplot [ranges] expr [using] [title] [style]2D plottinggsplot [ranges] expr [using] [title] [style]3D plottingrangesspecify data rangesexprexpression to plotusingspecify columns to plottitlespecify line title for legendstylespecify line styleIf ranges are supplied, they must come before the expressionto plot. The using, title, andstyle options may appear in anyorder after expr. Multiple expressions may be plotted with asingle command by separating them with commas.set options set plottingoptionsshow options show plottingoptionsreplotredisplay current plotcloseplotclose stream to gnuplot processpurge tmp files clean up temporary plottingfilesautomatic replot built-in variableOther Plotting Functionsplot (args)semilogx (args)semilogy (args)loglog (args)bar (args)stairs (x, y)hist (y, x)title (string)axis (limits)xlabel (string)ylabel (string)grid [on|off]hold [on|off]isholdmesh (x, y, z)meshdom (x, y)2D plot with linear axes2D plot with logarithmic x-axis2D plot with logarithmic y-axis2D plot with logarithmic axesplot bar chartsplot stairstepsplot histogramsset plot titleset axis rangesset x-axis labelset y-axis labelset grid stateset hold statereturn 1 if hold is on, 0 otherwiseplot 3D surfacecreate mesh coordinate matricesEdition 1.1for <strong>Octave</strong> <strong>Version</strong> <strong>1.1.1</strong>. Copyright 1996, John W. Eaton(jwe@che.utexas.edu). The author assumes no responsibility for anyerrors on this card.This card may be freely distributed under the terms of the GNUGeneral Public License.TEX Macros for this card by Roland Pesch (pesch@cygnus.com),originally for the GDB reference card<strong>Octave</strong> itself is free software; you are welcome to distribute copiesof it under the terms of the GNU General Public License. There isabsolutely no warranty for <strong>Octave</strong>.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!