You are on page 1of 4

Aworkinprogress!

A [ ]

CHEM4515/5515

Vector, scalar, or matrix variable Elements of the matrix, etc. are within these brackets. The elements in a row may be separated by commas or by spaces; the elements for different rows should be separated by semicolons : Separates the limits of a range (e.g. a:b, a is lower bound and b is upper, where the number of elements in the range equals the integer difference between b and a), or the limits and the step size (e.g. a:c:b, a and b are the same as above but c is the interval (or increment)) ; Separates the elements of each row in a matrix OR suppresses printing (when placed at the end of a statement or assignment) , Separates elements of a matrix or commands (e.g. the coordinates in a plot command) A*B Matrix (row by column) multiplication A.*B Element by element multiplication A/B Matrix division (A over B) A\B Matrix division (B over A) A./B Element by element division (A over B) A.\B Element by element division (B over A) A' Transpose and complex conjugate of A A.' Transpose of A (without complex conjugation) Indicates that the command continues on the next line % Indicates that the line is not evaluated; a comment ------plot(X,Y) Two-dimensional plot of Y vs. X (must have the same number of elements in X and Y) plot(X,Y1,X,Y2) Plots two functions of X (i.e. Y1 and Y2) on the same graph (note: can use this for more than two functions by including "X,Y3" etc.) hold on Suppress making a plot until all "plot" commands are given; all plots are done on the same graph (regardless of type of graph, so be careful!!) polar(X,Y) Polar graph of Y on X ezplot('fnc(x)') Graphs the function vs. x, without giving explicit bounds for x (note the single quotes!) may not work in a ".m" file fplot('fnc(x)', Same as above, but with the bounds of x given by the "x1" and [x1,x2]) "x2" plot3(X,Y,Z) A three-dimensional graph surf(X,Y,Z) Pretty much the same as "plot3" mesh(X,Y,Z) Same a "surf" xlabel('string') Assigns a label to the x-axis (given by the 'string'); smiliar commands for y and z axes; these commands appear on the

MATLABCOMMANDS

CHEM4515/5515

same line as the plot command, and can be separated from it and each other by commas title('string') Assigns the title 'string' to the graph grid on Apply a grid to the graph ----------------size(A) The nxm dimension of matrix A (see next few commands for usage) eye(n) or An identity matrix that is either nxn or the same dimension as eye(size(A)) matrix A ones(n,m) or A matrix of all ones (1) that is of dimension nxm or the same ones(size(A)) dimension as matrix A zeros(n,m) or A matrix of all zeroes (0) that is of dimension nxm or the same zeros(size(A)) dimension as matrix A [A B] or [A, B] If A and B are predefined matrices, this command combines or cat(2,A,B) them into a new matrix that has all the elements of both (concatenation of the matrices) side by side [A; B] or Similar to the previous command, except the new matrix has cat(1,A,B) the elements of the original matrix A on top of matrix B cat(3,A,B,C) This creates a three dimensional array with elements of matrix A in the first layer, matrix B in the middle layer, and matrix C in the bottom layer det(A) Determinant of a square matrix inv(A) Inverse of A (i.e. A1; use only if det(A) 0) pinv(A) Pseudo-inverse of A (to be used when det(A) = 0) rref(A) Reduce matrix to Row Echelon Form rank(A) Rank of variable A sqrt(A) Square root of the elements of matrix A log(A) Natural logarithm of the elements of matrix A log10(A) Common (base 10) logarithm of the elements of matrix A exp(A) Exponentiate (ex) the elements of matrix A acos(A), Inverse (arc) trigonometric functions for the elements of the asin(A), atan(A) array A, in RADIAN units acosd(A), Inverse trigonometric functions in DEGREE units asind(A), atand(A) cos(A), sin(A), Trigonometric functions of the elements of matrix A, assuming tan(A) the elements are in RADIAN units cosd(A), Trigonometric functions of the elements of matrix A, assuming sind(A), tand(A) the elements are in DEGREE units acosh(A), Hyperbolic functions cosh(A), etc. dot(A,B) The dot product of two vectors A and B cross(A,B) The cross product of two vectors A and B norm(A) The length of vector A abs(z) Absolute value of (complex) number z angle(z) The argument (angle) of complex number z MATLABCOMMANDS 2

conj(z) real(z) imag(z) sum(A)

CHEM4515/5515

The complex conjugate of complex number z The real part of complex number z The imaginary part of complex number z Adds the elements of each column of matrix A; if A is a row vector, this returns the sum of the row elements disp(string or Display the text written between single quotation marks variable) (string) or the value of a variable (or matrix) --eig(A) Displays the eigen values of matrix A [V,D] = eig(A) This gives the eigen vectors (in matrix V) and eigen values (in matrix D) of matrix A. Note, the vectors appear as the columns in V, and the values are along the diagonal of D (i.e. this is the diagonalized version of A) --ode45(@funct, Runge-Kutta algorithm for solving first order ordinary differential equations; the function describes the actual diffeq, [range], the range is for the independent variable, and the initial value is for the solution. This can also be used for second order init_val) diffeqs if the function treats the second derivative as the derivative of the first derivative, and the first derivative as a simple differential equation. The result will be a 2 by 1 matrix with y and y as the entries, but the initial conditions must have two entries (y(0) and y(0)) --for counter = A programming command equivalent to a do loop start:step:stop while (counter This is another form of the do loop where the counter is condition checked based on some condition (see next entry); used when value) the number of loop cycles is not predetermined if (statement A decision making command; the conditions are equal (==), condition not equal (~=), greater than (>), less than (<), greater value) than or equal (>=), and less than or equal (<=). This is followed by the actual operation needed elseif () Another decision making command that is used after a regular if command if there is another decision to be made else This is the alternative operation if the condition in the if or elseif is not met break This gets you out of a loop without completing it, and without terminating the program end Closes the loop for any of the previous commands; this is required to tell the program what lines are IN and what lines are not in the loop --mean(A) Mean value of the numbers in the row matrix A median(A) Median value of the numbers in the row matrix A mode(A) The most probable value within the array MATLABCOMMANDS 3

std(A) var(A) length(A) cumsum(A) bar(freq,data) hist(data,freq) hist(data,n)

CHEM4515/5515

Standard Deviation of the numbers in the row matrix A The variance of the numbers in row matrix A Counts the number of elements in the vector A Gives the sum of the elements in a row vector Generates a bar graph of the data (in the y-axis) versus the frequency (in the x-axis) Generates a histogram of the data (in the x-axis) versus the frequency (in the y-axis). NOTE: If the frequency is omitted, the program will bin the data into 10 evenly spaced groups Groups the data into n-evenly spaced groups and generates the histogram; this data may be retrieved as two vectors, one with the frequencies and the other with the bin locations, by typing [freq,bin]=hist(data,n)

MATLABCOMMANDS

You might also like