Comando S Dem at Lab
Comando S Dem at Lab
ARITHMETIC OPERATIONS
Arithmetic operation Symbol Example
Addition + 6+3=9
Subtraction 63=3
Multiplication * 6 * 3 = 18
Right division / 6/3 = 2
Left division \ 6\3 = 3/6 = 1/2
Exponentiation ^ 6 ^ 3 = 63 = 216
DISPLAY FORMATS
Function Description
sin(x) Computes the sine of x, where x is in radians.
cos(x) Computes the cosine of x, where x is in radians.
tan(x) Computes the tangent of x, where x is in radians.
asin(x) Computes the arcsine or inverse sine of x, where x must be between 1 and 1. The
function returns an angle in radians between /2 and /2.
sinh x
cosh(x) Computes the hyperbolic tangent of x, which is equal to
cosh x
tanh(x)
Computes the inverse hyperbolic sine of x, which is equal to ln( + 2 + 1)
asinh(x)
Computes the inverse hyperbolic cosine of x, which is equal to ln( + 2 1)
1+
acosh(x) Computes the inverse hyperbolic tangent of x, which is equal to ln
1
Function Description
conj(x) Computes the complex conjugate of the complex number x. Thus, if
x is equal to a + ib, then conj(x) will be equal to a ib.
angle(x) Computes the real portion of the complex number x.
real(x) Computes the imaginary portion of the complex number x.
imag(x) Computes the absolute value of magnitude of the complex number x.
abs(x) Computes the angle using the value of atan2(imag(x), real(x)); thus,
the angle value is between and .
Arithmetic operations with complex numbers
Operation Result
1 + 2 (1 + 2) + (1 + 2)
1 + 2 (1 2) + (1 2)
1 1 2 + 12 2 1 21
2 +
2 2 2
+ 2 22 + 22
|1| 12 + 12
1 1 1 (conjugate of c1)
(Assume that 1 = 1 + 1 and 2 = 2 + 2.)
PREDEFINED VARIABLES
Command Description
clear Removes all variables from the memory.
clear x, y, z Clears/removes only variables x, y and z from the memory.
who Lists the variables currently in the workspace.
whos Displays a list of the variables currently in the memory and their
size together with information about their bytes and class.
GENERAL COMMANDS
General information
Function Description
compute Tells you the computer type you are using.
r clock Gives you wall clock time and date as a vector.
date Tells you the date as a string.
more Controls the paged output according to the screen size.
ver Gives the license and the version information about MATLAB installed on your computer.
bench Benchmarks your computer on running MATLAB compared to other computers.
Termination
Function Description
c (Control-c) Local abort, kills the current command execution.
quit Quits MATLAB.
exit Same as quit.
ARRAYS
Colon use for a matrix
Command Description
(: , ) Refers to the elements in all the rows of a column n of the matrix A.
(, ) Refers to the elements in all the columns of row n of the matrix A. Refers to the
(: , : ) elements in all the rows between columns m and n of the matrix A.
(: , ) Refers to the elements in all the columns between rows m and n of the matrix A.
Element-By-Element Operations
Arithmetic operators
Matrix operators Array operators
+ Addition + Addition
Subtraction Subtraction
* Multiplication .* Array multiplication
^ Exponentiation .^ Array exponentiation
/ Right division ./ Array right division
\ Left division .\ Array left division
MATLAB built-in array functions
PROGRAMMING IN MATLAB
Precedence Operation
1 (highest) Parentheses (If nested parentheses exist, inner have precedence).
2 Exponentiation.
3 Logical NOT (~).
4 Multiplication, Division.
5 Addition, Subtraction.
6 Relational operators (>, <, >=, <=, = =, ~=).
7 Logical AND (&).
8 (lowest) Logical OR (|).
Additional logical built-in functions Truth table
Command Description
break Terminates the execution of MATLAB for and while loops. In nested
loops, break will terminate only the innermost loop in which it is placed.
return Primarily used in MATLAB functions, return will cause a normal return
from a function from the point at which the return statement
is executed.
error (text) Terminates execution and displays the message contained in text
on the screen. Note, the text must be enclosed in single quotes.
Function Description
Relational A MATLAB logical relation is a comparison between two
operators variables x and y of the same size effected by one of the six
operators, <, <=, >, >=, = =, ~ =. The comparison involves
corresponding elements of x and y, and yields a matrix or scalar
of the same size with values of true or false for each of its
elements. In MATLAB, the value of false is zero, and true
has a value of one. Any non-zero quantity is interpreted as
true.
Combinatorial The operators & (AND) and | (OR) may be used to combine two
operators logical expressions.
Break
Return
error (text)
while
GRAPHICS
Color, line-style and marker-style options List of functions for plotting x-y data
Color style-option Line style-option Marker style-option Function Description
y yellow solid + plus sign area Creates a filled area plot.
m magenta dashed o circle bar Creates a bar graph.
c cyan : dotted * asterisk barh Creates a horizontal bar graph.
r red . dash-dot x x-mark comet Makes an animated 2-D plot.
g green . point compass Creates arrow graph for complex numbers.
b blue ^ up triangle contour Makes contour plots.
w white s square contourf Makes filled contour plots.
k black d diamond, etc. errorbar Plots a graph and puts error bars.
feather Makes a feather plot.
fill Draws filled polygons of specified color.
fplot Plots a function of a single variable.
hist Makes histograms.
loglog Creates plot with log scale on both x and y axes.
pareto Makes pareto plots.
pcolor Makes pseudo color plot of matrix.
pie Creates a pie chart.
plotyy Makes a double y-axis plot.
plotmatri Makes a scatter plot of a matrix.
x polar Plots curves in polar coordinates.
quiver Plots vector fields.
rose Makes angled histograms.
scatter Creates a scatter plot.
semilogx Makes semilog plot with log scale on the x-axis.
semilogy Makes semilog plot with log scale on the y-axis.
stairs Plots a stair graph.
stem Plots a stem graph.
mesh If x and y are two vectors containing a range of points for the evaluation of a function,
[X,Y] = meshgrid(x, y) returns two rectangular matrices containing the x and y values at each point of a two-
dimensional grid.
grid
If X and Y are rectangular arrays containing the values of the x and y coordinates at each point of a rectangular
grid , and if z is the value of a function evaluated at each of these points, mesh(X,Y,z) will produce a three-
mesh(X,Y,z) dimensional perspective graph of the points. The same results can be obtained with mesh(x,y,z) can also be
used.
If the xy grid is rectangular, these two functions are merely variations of the basic plotting program
mesh, and they operate in an identical fashion. meshc will produce a corresponding contour plot drawn on
meshc, meshz the xy plane below the three-dimensional figure, and meshz will add a vertical wall to the outside features of
the figures drawn by mesh.
Produces a three-dimensional perspective drawing. Its use is usually to draw surfaces, as opposed to plotting
surf functions, although the actual tasks are quite similar. The output of
surf will be a shaded figure. If row vectors of length n are by x = r cos and y = r sin , with 0 2, they
correspond to a circle of radius r. If G is a column vector r equal to r = [0 1 2]; then z = r*ones(size(x)) will
be a rectangular, 3 n, arrays of 0s and 2s, and surf(x, y, z) will produce a shaded surface bounded by three
circles; i.e., a cone.
SYMBOLIC MATHEMATICS
Simplification Basic operations
collect Collect common terms ccode C code representation of a symbolic expression
expand Expand polynomials and elementary functions conj Complex conjugate
factor Factorization findsym Determine symbolic variables
horner Nested polynomial representation fortran Fortran representation of a symbolic expression
numden Numerator and denominator imag Imaginary part of a complex number
simple Search for shortest form latex LaTeX representation of a symbolic expression
simplify Simplification pretty Pretty prints a symbolic expression
subexpr Rewrite in terms of subexprssions real Real part of an imaginary number
sym Create symbolic object
syms Shortcut for creating multiple symbolic objects
Solution of equations
compose Functional composition
dsolve Solution of differential equations
finverse Functional inverse
solve Solution of algebraic equations
Calculus
Calculus Pedagogical and graphical applications
diff Differentiate ezcontour Contour plotter
int Integrate ezcontourf Filled contour plotter
jacobian Jacobian matrix ezmesh Mesh plotter
ezmeshc Combined mesh and contour plotter
limit Limit of an expression
ezplot Function plotter
symsum Summation of series
ezplot Easy-to-use function plotter
taylor Taylor series expansion ezplot3 Three-dimensional curve plotter
ezpolar Polar coordinate plotter
Conversions ezsurf Surface plotter
char Convert symbolic object to string ezsurfc Combined surface and contour plotter
double Convert symbolic matrix to double funtool Function calculator
poly2sym Function calculator rsums Riemann sums
sym2poly Symbolic polynomial to coefficient vector taylortool Taylor series calculator
Linear algebra
Integral transforms
colspace Basis for column space
fourier Fourier transform det Determinant
ifourier Inverse Fourier transform diag Create or extract diagonals
ilaplace Inverse Laplace transform eig Eigenvalues and eigenvectors
expm Matrix exponential
iztrans Inverse Z-transform
inv Matrix inverse
laplace Laplace transform jordan Jordan canonical form
ztrans Z-transform null Basis for null space
poly Characteristic polynomial
rank Matrix rank
rref Reduced row echelon form
svd Singular value decomposition
tril Lower triangle
triu Upper triangle
CONTROL SYSTEMS