Very high level langauge for numerical computations such as Matrix Math. Command Line Interface (with a simple GUI IDE available). ^ Change prompt with PS1('>>')

Seperate commands with , or ; Suppress responses by ending the line with
; if the line isn't terminated, an "ans = " will display the result. Use
`disp( )` to print to stdio without "ans =". `sprintf` available.

`format short` or `format long` for displayed resolution of
numbers.

Any standard math command can be entered, E.g. `1+2` `log() abs()
exp() max() sum() floor() ceil(). `-v returns the negative of v.

**Equal** is `==`, **Not equal** is `~=`. **And**
`&&`, **Or** `||`, **XOR** is `xor( )`.

**False** is 0, **True** is 1.

**Variable** assignment with =. Multiple values can be "broken out" on
the left side with []. E.g. `[val, ind] = max(a)`

**Strings** in single quotes. `hi = 'hello';`

**matrix** `[ row {; row}] `where

indexes a row and colum from the matrix variable. E.g.matrix(row,col)A(2, 1)returns the first value in the second row of A. Assuming A is defined as above, that would be 3.

indexes a row from the matrix variable, returning a vector. E.g.matrix(row, :)A(2, :)returns the second row of A. Assuming A is defined as above, that would be [3 4]. Note thatA(2)does NOT return the entire row; it only returns the first column of the second row.

indexes a colum from the matrix variable, returning a 1xmatrix(:,col)colmatrix. E.g.A(:, 1)returns the first column of A. Assuming A is defined as above, that would be [1; 3; 5]

addresses the rows of the matrix indexed by matrix2. E.g.matrix(matrix2, :)A([1 3]),:)returns the 1st and 3rd rows of matrix A. Assuming A is defined as above, that would be [1 2; 5 6]

returns a vector with all the rows and columns of A. E.g.matrix(:)A(:)returns [1;3;5;10;11;12]

NOTE: all the above can be used in assignments (on the left side) as well as returning values on the right side. e.g.A(:,2) = [10;11;12]replaces the second column of A with 10, 11, and 12

A row or column can be appended by makeing a new matrix using the old value of the matrix with the new values included and then assigning that to the matrix. e.g.A = [A, [100; 101; 102]]appends a new column making A a 3x3 matrix.C = [A B]joins two matrixes, etc...C = [A; B]joins them top to bottom.All the standard matrix math functions are available.

A*B; A/B; A+B; A-B;etc... For Matrix multiply or divide^, the second dimension of A must match the first dimension of B, and the result will be a matrix which is the first dimension of A by the second dimension of B.

If A is[n x m]*[m x p] = [n x p]nxmand B ismxpthe result AB will benxp.Dot operations, such as .* , or .^ will apply each element by each element. e.g.

A .^ 2returns each element of A squared. Note:A ^ 2is NOT the same; instead it computes A * A1 ./ Areturns the reciprocal of each element.v < 3returns true or false for each element. True (1) if the element is less than 3, false (0) otherwise. See find() below.

Note: Uniary math operators are dot wise. e.g.log(A)takes the log of each element of A.

transpose(or justmatrix)(the matrix followed by a dot and single quote) transposes the matrix; makes the rows into columns and columns into rows.matrix.'

ctranspose(or justmatrix)(the matrix followed by a single quote) conjugate transpose of the matrix. Complex conjugate is a complex number with the sign of it's imaginary part swapped. (i.e x+iy ? x-iy or vice versa). The complex conjugate of a matrix is obtained by replacing each element by its complex conjugate. The conjugate transpose by doing thatmatrix'andtransposing it.

flipud(Flip array upside down.matrix)

fliplr(Flip array left right.matrix)

ones(makes a rowsxcol matrix filled with 1'srows,cols)

eye(returns an identity matrix. E.g.size)eye(3)returns [1 0 0; 0 1 0; 0 0 1]

eye(makes an identity matrix of that size. e.g.rows,cols)A .* eye(3,2)returns [1 0; 0 4; 0 0]

rand(makes a rowsxcol matrix filled with random values between 0 and 1. multiply by a scaler to make a matrix with values between 1 and n; add or subtract to offset, etc...rows,cols)

randn(makes a rowsxcol matrix filled with gausian random values.rows,cols)size(

matrix) returns a 1x2 matrix showing the size of each dimision of the matrix.

size(matrix,dim) returns a scalar showing the size of thedimdimision of the matrix.

length(returns a scaler with the longest dimision of matrix. e.g.matrix)v + ones(length(v),1)returns a matrix with each element of v incremented. (but it turns out that this is the same asv + 1)

max(returns a 1x2 matrix with the maximum value and the index at which that value was found. e.g.vector)val = max(v)returns the maximum value found in vector v.[val, ind] = max(a)returns the maximum in val and the index where that value was found in ind.

max(returns the column-wise maximum value; the max of each row. To find the max value in the entire matrix, usematrix)max(max(. ormatrix)max(A(:))

max(returns the maximum along thematrix, [],dim)dimdiminsion.

max(returns the pair-wise maximum between the two matrix. e.g.matrix,matrix)max([1 2; 2 3; 5 6],[6 5; 4 3; 2 1])returns [6 5; 4 3; 5 6]

find(returns the position of the element if the element is true. E.g.vector)find([1 15 2 0.5] < 3)returns [1 3 4] because the 1st, 3rd, and 4th elements are less than 3.

find(returns a matrix of positions of the elements which are true.matrix)

prod(returns all the elements multiplied together.vector)

prod(returns each columns elements multiplied together.matrix)

sum(returns all the elements summed together along dimensionmatrix{,dim})dim. dim is assumed to be the first dimision that is not 1 if ommitted. e.g.sum(A)returns [9 12] andsum(A,2)returns [3;7;11]

Note: a common error is thinking that sum will return a scalar when used on a multidimisional matrix. To produce a scalar usesum(sum())or convert the matrix to a vector using (:) e.g.sum(A(:))

inv(amatrix)^{-1}is inv(a). returns the inverse of the matrix which must be square and the determinant can not be zero. Inverse is the matrix version of the recriprocal of a number. a * a^{-1}will be the identity matrix of the same size. Division by a matrix is multiplication by the inverse of the matrix.

pinv(returns the pseudoinverse.matrix)

**vector** e.g. `v = [1; 2; 3] `

**range** ` start:inc:end `where start is the
starting value, end is the last value, and inc is the (optional) amount to
increment. E.g.

pwdPrint Working Directory

cdChange Directorypath

lsList Stuff(?) like DIR in DOS.

savesaves a memory variable to a file on the disk. The typical extension is .mat or .dat. The -ascii option makes the file human readable instead of the default binary.file variable{-ascii}

loadloads data from the file into memoryfile

whoshows current memory variables

whosshows details about current memory variables; attr, size, bytes, class

clearerases a variable from memory. There is no undo.variable

hist(plots a histogrammatrix)

plot(plot data points from y per xx,y)

hold onprevents a graph from being erased by the next plot command so that two vplots can be shown on one graph.

hold off

xlabel('string')

xlabel('string')

title('string')

legend(add labels to the graph. use one string for each diminsion in the legend command.strings)

axis ([Set axis limitsX_lo X_hi{Y_lo Y_hi{Z_lo Z_hi}}])

print -dpngsave the current graph to a file as a png.file

closecloses a graph.

figure(switches between multiple graphs.number)

subplot(divides up a graph into parts, and selects the part indicated by number.rows,cols, number)

imagesc(Display a scaled version of the matrixas a color image. Each element represents a color or intensity.matrix)

colorbarAdd a colorbar (legend) to the current axes.

colormap grayuse grey scale instead of colors.

forvariable=range,statements, end

whilecondition,statements, {break}, end

ifcondition,statements, {elseifcondition}, {else}, end

functionMultiple values can be "broken out" on the left side with [].OUTPUTS= function (INPUT, ...)Anonymous Functions are defined using the syntax

@(argument-list) expression^ Example uses:

- Pass the output of one function as a parameter into another function without needing a temporary variable inbetween:

quad (@(x) (x.^2), 0, pi)- Adapt a function with several parameters so that some of those parrameters are filled from the environment. In this example, the values of a and b that are passed to betainc are inherited from the current environment.
a = 1; b = 2; quad (@(x) betainc (x, a, b), 0, 0.4)

**Literals**

- pi

See also:

- https://octave-online.net Online Octave service, very nice for trying out quick commands.+
- https://gnu.org/software/octave/ Official Web Site.

file: /Techref/language/octave.htm, 12KB, , updated: 2019/1/29 23:14, local time: 2023/3/25 12:59, |

©2023 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?<A HREF="http://massmind.org/techref/language/octave.htm"> Octave Programming Language</A> |

Did you find what you needed? |

## Welcome to massmind.org! |

## Welcome to massmind.org! |

.