## General

• use help to get help on any function, e.g. help transpose;

## Arithmetic

• basic arithmetic: +, -, *, /.
• array division: ./
• power: ^, inverse: ^(-1), e.g. 3^(-1) for 1/3.
• special functions: sin(x), etc.
• ranges via the colon operator: :, a:b, a:s:b, e.g. 1:10 and 1:2:10, 1:0.1:10
• setting a variable: =
• comparison: ==, <, >, ~= (for not equal)

## Functions and Plotting

• declaring variable(s): syms
• plotting a function:
• solving equations: solve()
• plotv(x): plot two-dimensional vector x starting at origin
• scatter(x,y): plot points (x(i), y(i)); scatter(x,y,1) will draw points (rather than disks)
• axis: set coordinate ranges for plot
• special functions:
• max(v): maximum value in a vector, need to use twice for matrix, since it's a vector of vectors, similarly min(v)
• abs(x): absolute value, mathematicans would write |x|
• sin(x), tan(x), etc.: trigonometric functions
• exp(x): exponential function
• log(x): natural logarithm, also log2, log10
• heaviside(x): Heaviside function
• ceil(x), floor(x): floor and ceiling functions

## Calculus

• limit(f(x),x,a): lim of f(x) as x tends to a; x needs to be declared a symbolic variable usins syms x, also 'left' and 'right' version
• diff(f(x)): derivative of f, make sure x is a symblic variable, diff(f(x), k) will give you the kth derivative

## Matrix Operations and Functions

• Creating vectors:
• v = [3 1 5];
• randperm(n): random permutation of 1:n
• Creating Matrices:
• M = [1 2 3; 4 5 6];
• randi(max, n, m) function: create random matrix of dimension n x m with maximum entry max
• eye(n): identify matrix of dimension n x n (also eye(n,m) and other forms)
• diag(v): create diagonal matrix with diagonal entries given by vector v
• zeros(n), zeros(n,m): n x m all zero matrix
• Matrix arithmetic: +, -, *, also / and ^ (in particular, ^(-1) for inverse)
• Matrix indexing:
• A(i,j), A(i,:), A(:,j), etc. (this uses the colon operator :)
• in general: A(u,v), where u and v are vectors, e.g. A([1 3]; [1 3 5]) results in a 2x3 submatrix of A
• swapping two rows: A([i,j], :) = A([j,i], :)
• Vector operations and functions
• norm(v): Eucliden norm of v (other norms are available, also for matrices)
• dot(u,v): dot/inner product of vectors
• Matrix functions:
• size(A): dimension of matrix A, returns vector
• horzcat(A,B): concatenate A and B horizontally
• trace(A): trace of matrix A
• det(A): determinant of A
• rank(A): rank of A (dimension of column space of A = dimension of row space of A)
• transpose(A): tranpose of A, also A.'
• isequal(A,B): are matrices A and B equal? A == B compares column vectors
• charpoly(A): characteristic polynomial of A, that is, det(t*I-A)
• norm(A, 'fro'): Frobenius norm of A: square root of sums of squares of entries in A.
• Linear Systems, Matrix decompositions, and other Matrix algorithms:
• rref(A): reduced row echelon form
• linsolve(A,b): solve linear system Ax = b using LU decomposition with partial pivoting (for square matrix), otherwise QR factorization
• lu(A): LU decomposition with pivoting, {L U] = lu(A) returns L, U so that A = L*U, but L is permuted lower triangular; [L U P] = lu(A) will return L, U, and P so that P*A = L*U.
• null(A): orthonormal basis for null space of A, i.e. {x: Ax = 0}
• orth(A): orthonormal basis for columnspace of A, use orth(A, 'r') to get a rational basis
• qr(A,0): economy QR factorization, i.e. A = QR with Q orthonormal (Q'*Q = I), R upper triangular; if A = mxn, then Q = mxn, and R = nxn. In the full factorization, [Q R] = qr(A), Q has dimension mxm.
• eig(A): eigenvalues of A, if used as [P D] = eig(A), P contains eigenvectors and D is diagonal matrix of corresponding eigenvalues; in particular, A = P*D*P^(-1).
• svd(A): singular value decomposition; use as [U D V] = svd(A), then A = PDV'

## Images

• imread(name): read file with name; format is based on extension of file name
• imwrite(pic,name): write picture data in pic to file name
• im2double(pic): convert image information to double precision
• rgb2grayscale(pic): convert color picture to grayscale picture, loses color information

Marcus Schaefer
Last updated: February 26th, 2015.