Docsity

MATLAB Commands for Chemistry: A Comprehensive Guide - Prof. Michael S. Sommer, Study notes of Chemistry

Toggle sidebar
bg1
! ! CHEM!4515/5515!
MATLAB!COMMANDS! ! 1!
A!work!in!progress!!
!
A
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)',
[x1,x2])
Same as above, but with the bounds of x given by the "x1" and
"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
pf3
pf4

Partial preview of the text

Download MATLAB Commands for Chemistry: A Comprehensive Guide - Prof. Michael S. Sommer and more Study notes Chemistry in PDF only on Docsity!

A work in progress! A (^) 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) AB (^) 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)', [x1,x2]) Same as above, but with the bounds of x given by the "x1" and "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

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 eye(size(A)) An identity matrix that is either nxn or the same dimension as matrix A ones(n,m) or ones(size(A)) A matrix of all ones (1) that is of dimension nxm or the same dimension as matrix A zeros(n,m) or zeros(size(A)) A matrix of all zeroes (0) that is of dimension nxm or the same dimension as matrix A [A B] or [A, B] or cat(2,A,B) If A and B are predefined matrices, this command combines them into a new matrix that has all the elements of both (concatenation of the matrices) side by side [A; B] or cat(1,A,B) Similar to the previous command, except the new matrix has 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. A–^1 ; 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), asin(A), atan(A) Inverse (“arc”) trigonometric functions for the elements of the array A, in RADIAN units acosd(A), asind(A), atand(A) Inverse trigonometric functions in DEGREE units cos(A), sin(A), tan(A) Trigonometric functions of the elements of matrix A, assuming the elements are in RADIAN units cosd(A), sind(A), tand(A) Trigonometric functions of the elements of matrix A, assuming the elements are in DEGREE units acosh(A), cosh(A), etc. Hyperbolic functions 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

std(A) (^) Standard Deviation of the numbers in the row matrix A var(A) (^) The variance of the numbers in row matrix A length(A) Counts the number of elements in the vector A cumsum(A) (^) Gives the sum of the elements in a row vector bar(freq,data) (^) Generates a bar graph of the data (in the y-axis) versus the frequency (in the x-axis) hist(data,freq) (^) 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 hist(data,n) (^) 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)