Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Chapter Nine

Command Description
dblquad(fun,a,b,c,d) Computes the double integral of the function f (x,
y) between the limits a ! x ! b and c ! y ! d.
The input fun specifies the function that
computes the integrand. It must accept a vector
argument x and scalar y, and it must return a
vector result.
Polyint(p,c) Computes the integral of the polynomial p using
an optional user-specified constant of integration
C.
Quad(fun,a,b) Uses an adaptive Simpson rule to compute the
integral of the function fun between the limits a
and b. The input fun, which represents the
integrand f (x), is a function handle for the
integrand function. It must accept a vector
argument x and return the vector result y.
quadl(fun,a,b) Uses Lobatto integration. The syntax is identical
to quad.
trapz(x,y) Uses trapezoidal integration to compute the
integral of y with respect to x, where the array y
contains the function values at the points
contained in the array x.
triplequad(fun,a,b,c,d,e,f) Computes the triple integral of the function f (x, y,
z) between the limits a ! x ! b, c ! y ! d, and
e ! y ! f. The input fun speci es the function
that computes the integrand. It must accept a
vector argument x, scalar y, and scalar z, and it
must return a vector result.
d=diff(x) Returns a vector d containing the differences
between adjacent elements in the vector x.
[df_dx,df_dy] = gradient(f,dx,dy) Computes the gradient of the function f (x, y),
where df_dx and df_dy represent and , and
dx and dy are the spacing in the x and y values
associated with the numerical values of f.
d = polyder(p) Returns a vector d containing the
coef cients of the derivative of the
polynomial represented by the vector p.
d = polyder(p1,p2) Returns a vector d containing the coef cients of
the polynomial that is the derivative of the
product of the polynomials represented by p1
and p2.
[num, den] = polyder(p2,p1) Returns the vectors num and den
containing the coef cients of the
numerator and denominator polynomials
of the derivative of the quotient p2/p1,
where p1 and p2 are polynomials.
[t, y] = ode45(@ydot, tspan, y0, Solves the vector differential equation speci ed
options) by the function le whose handle is @ydot and
whose inputs must be t and y, and whose output
must be a column vector representing dy"dt; that
is, f(t, y). The number of rows in this column
vector must equal the order of the equation. The
vector tspan contains the starting and ending
values of the independent variable t, and
optionally any intermediate values of t where the
solution is desired. The vector y0 contains the
initial values. The function le must have two input
arguments, t and y, even for equations where f
(t, y) is not a function of t. The options
argument is created with the odeset function.
The syntax is
identical for the solver ode15s.

options = (‘name1’, ‘value1’ Creates an integrator options structure options


‘name2’, ‘value2’. . .) to be used with the ODE solver, in which the
named properties have the specified values,
where name is the name of a property and
value is the value to be assigned to the
property. Any unspecified properties have default
values. Typing odeset with no input arguments
displays all property names and their
possible values.
sys = ss(A, B, C, D) Creates an LTI object in state-space form, where
the matrices A, B,C, and D correspond to
those in the model x=Ax+Bu,y =Cx " Du.
[A, B, C, D] = ssdata(sys) Extracts the matrices A, B, C and D
corresponding to those in the model x=Ax+Bu,y
=Cx " Du.
sys = tf(right,left) Creates an LTI object in transfer function form,
where the vector right is the vector of coef
cients of the right-hand side of the equation,
arranged in descending derivative order, and
left is the vector of coef cients of the left-hand
side of the equation, also
arranged in descending derivative order
sys2 = tf(sys1) Creates the transfer function model sys2 from
the state model sys1.
sys1 = ss(sys2) Creates the state model sys1 from the transfer
function model sys2.
[right, left] = tfdata(sys,’v’) Extracts the coef cients on the right- and left-
hand sides of the reduced-form model speci ed
in the transfer function model sys.
When the optional parameter ‘v’ is used, the
coef cients are returned as vectors rather than as
cell arrays.
impulse(sys) Computes and plots the impulse response of the
LTI object sys.
initial(sys,x0) Computes and plots the free response of the LTI
object sys given in state-model form, for the
initial conditions speci ed in the vector x0.
lsim(sys,u,t) Computes and plots the response of the LTI
object sys to the input specified by the vector u,
at the times speci ed by the vector t.
step(sys) Computes and plots the step response of the LTI
object sys.

CHAPTER 8 Linear Algebraic Equations

det(A) Computes the determinant of the array A.

inv(A) Computes the inverse of the matrix A.


pinv(A) Computes the pseudoinverse of the matrix A.
rank(A) Computes the rank of the matrix A.
rref([A b]) Computes the reduced row echelon form
corresponding to the augmented matrix [Ab].
x = inv(A)*b Solves the matrix equation Ax ! b using the
matrix inverse.
x =A\b Solves the matrix equation Ax ! b using left
division.
CHAPTER 7 Statistics, Probability, and Interpolation

bar(x,y) Creates a bar chart of y versus x.


hist(y) Aggregates the data in the vector y into 10 bins
evenly spaced between the minimum and
maximum values in y.
hist(y,n) Aggregates the data in the vector y into n bins
evenly spaced
between the minimum and maximum values in y.
hist(y,x) Aggregates the data in the vector y into bins
whose center locations are speci ed by the
vector x. The bin widths are the distances
between the centers.
[z,x] = hist(y) Same as hist(y) but returns two vectors z
and x that contain the frequency count and the
bin locations.
[z,x] = hist(y,n) Same as hist(y,n) but returns two vectors z
and x that contain the frequency count and the
bin locations.
[z,x] = hist(y,n) Same as hist(y,x) but returns two vectors z
and x thatncontain the frequency count and the
bin locations. The returned vector x is the same
as the user-supplied vector x.
rand Generates a single uniformly distributed random
number between 0 and 1.
rand(n) Generates an n ( n matrix containing uniformly
distributed random numbers between 0 and 1.
rand(m,n) Generates an m ( n matrix
s = rand(‘state’) Returns a vector s containing the current state
of the uniformly distributed generator.
rand(‘twister’,s) Sets the state of the uniformly distributed
generator to s.
rand(‘twister’,0) Resets the uniformly distributed generator to its
initial state.
rand(‘twister’,j) Resets the uniformly distributed generator to
state j, for integer j.
rand(‘twister’,sum(100*clock)) Resets the uniformly distributed generator to a
different state each time it is executed.
randn Generates a single normally distributed random
number having a mean of 0 and a standard
deviation of 1.
randn(n) Generates an n ( n matrix containing normally
distributed random numbers having a mean of 0
and a standard deviation of 1.
randn(m,n) Generates an m ( n matrix containing normally
distributed random numbers having a mean of 0
and a standard deviation of 1.
s = randn(‘state’) Like rand(‘state’) but for the normally
distributed generator.
randn(‘state’,s) Like rand(‘state’,s) but for the normally
distributed generator
randn(‘state’,0) Like rand(‘state’,0) but for the normally
distributed generator.
randn(‘state’,j) Like rand(‘state’,j) but for the normally
distributed generator.
randn(‘state’,sum(100*clock)) Like rand(‘state’,sum(100*clock)) but
for the normally distributed generator.
randperm(n) Generates a random permutation of the integers
from 1 to n.
y_int=interp1(x,y,x_int) Used to linearly interpolate a function of one
variable: y " f (x). Returns a linearly
interpolated vector y_int at the speci ed
value x_int, using data stored in x and y.
z_int=interp2(x,y,z,x_,y_int) Used to linearly interpolate a function of two
variables: y " f (x, y). Returns a linearly
interpolated vector z_int at the speci ed
values x_int and y_int, using data stored
in x, y, and z.
y_est = interp1(x,y,x_est, method) Returns a column vector y_est that contains
the estimated values of y that correspond to the
x values speci ed in the vector x_est, using
interpolation speci ed by method. The choices
for method are ‘nearest’, ‘linear’, ‘spline’,
‘pchip’, and ‘cubic’.
y_int = spline(x,y,x_int) and y are vectors containing the data and
x_int is a vector containing the values of the
independent variable x at which we wish to
estimate the dependent variable y. The result
y_int is a vector the same size as x_int
containing the interpolated values of y that
correspond to x_int.
y_int = pchip (x,y,x_int) Similar to spline but uses piecewise cubic
Hermite polynomials for interpolation to preserve
shape and respect monotonicity.
[breaks, coeffs, m, n] = Computes the coef cients of the cubic spline
unmkpp(spline(x,y)) polynomials for the data in x and y. The vector
breaks contains the x values, and the matrix
coeffs is an m ( n matrix containing the
polynomial coef cients. The scalars m and n
give the dimensions of the matrix coeffs; m is
the number of polynomials, and n is the number
of coef cients for each polynomial.

CHAPTER 6 Model Building and Regression

p = polyfit(x,y,n) Fits a polynomial of degree n to data described


by the vectors x and y, where x is the
independent variable. Returns a row vector p of
length n " 1 that contains the polynomial coef
cients in order of descending powers.
[p,s, mu] = poly t(x,y,n) Fits a polynomial of degree n to data described
by the vectors x and y, where x is the
independent variable. Returns a row vector p of
length n+1 that contains the polynomial coef
cients in order of descending powers and a
structure s for use with polyval to
obtain error estimates for predictions. The
optional output variable mu is a two-element
vector containing the mean and standard
deviation of x.
[y,delta] = polyval(p,x,s,mu) Uses the optional output structure s generated
by [p,s,mu] =polyfit(x,y,n) to generate
error estimates. If the errors in the
data used with poly t are independent and
normally distributed with constant variance, at
least 50 percent of the data will lie within
the band y + delta.

CHAPTER 5 Advanced Plotting


axis([xmin xmax ymin ymax]) Sets the minimum and maximum limits of the x
and y axes.
fplot(function,[xmin xmax]) Performs intelligent plotting of functions, where
function is a function handle that describes
the function to be plotted and [xmin xmax]
speci es the minimum and maximum values of
the independent variable. The range of the
dependent variable can also be speci ed. In this
case the syntax is fplot(function, [xmin
xmax ymin,ymax]).
grid Displays gridlines at the tick marks
corresponding to the tick labels.
plot(x,y) Generates a plot of the array y versus the array
x on rectilinear axes.
plot(y) Plots the values of y versus their indices if y is
a vector. Plots the imaginary parts of y versus
the real parts if y is a vector having complex
values.
polyval(p,x) Evaluates the polynomial p at speci ed values of
its independent variable x.
print Prints the plot in the Figure window.
title(‘text’) Puts text in a title at the top of a plot.
xlabel(‘text’) Adds a text label to the x axis (the abscissa).
ylabel(‘text’) Adds a text label to the y axis (the ordinate).
gtext(‘text’) Places the string text in the Figure window at a
point speci ed by the mouse.
hold Freezes the current plot for subsequent graphics
commands.
legend(‘leg1’,’leg2’,...) Creates a legend using the strings leg1, leg2,
and so on and enables its placement with the
mouse.
plot(x,y,u,v) Plots, on rectilinear axes, four arrays: y versus x
and v versus u.
plot(x,y,’type’) Plots the array y versus the array x on
rectilinear axes, using the line type,
data marker, and colors speci ed in the string
type. See Table 5.2–1.
plot(A) Plots the columns of the m & n array A versus
their indices and generates n
curves.
plot(P,Q) Plots array Q versus array P. See the text for a
description of the possible variants involving
vectors and/or matrices: plot(x,A),
plot(A,x), and plot(A,B).
subplot(m,n,p) Splits the Figure window into an array of
subwindows with m rows and n
columns and directs the subsequent plotting
commands to the pth subwindow.
text(x,y,’text’) Places the string text in the Figure window at a
point speci ed by
coordinates x, y.
bar(x,y) Creates a bar chart of y versus x.
loglog(x,y) Produces a log-log plot of y versus x.
plotyy(x1,y1,x2,y2) Produces a plot with two y axes, y1 on the left
and y2 on the right.
polar(theta,r,’type’) Produces a polar plot from the polar coordinates
theta and r, using the line type, data marker,
and colors speci ed in the string type.
semilogx(x,y) Produces a semilog plot of y versus x with
logarithmic abscissa scale.
semilogy(x,y) Produces a semilog plot of y versus x with
logarithmic ordinate scale.
stairs(x,y) Produces a stairs plot of y versus x.
contour(x,y,z) Creates a contour plot.
mesh(x,y,z) Creates a three-dimensional mesh surface plot.
meshc(x,y,z) Same as mesh but draws a contour plot under
the surface.
meshz(x,y,z) Same as mesh but draws a series of vertical
reference lines under the surface
surf(x,y,z) Creates a shaded three-dimensional mesh
surface plot.
surfc(x,y,z) Same as surf but draws a contour plot under
the surface.
[X,Y] = meshgrid(x,y) Creates the matrices X and Y from the vectors
x and y to de ne a rectangular grid.
[X,Y] = meshgrid(x) Same as [X,Y] = meshgrid(x,x).
waterfall(x,y,z) Same as mesh but draws mesh lines in one
direction only.

CHAPTER 4 Programming with MATLAB

< Less than.

<= Less than or equal to.

> Greater than.

>= Greater than or equal to.

== Equal to.
~= Not equal to.
~ NOT ~A returns an array of the same dimension as A;
the new array has 1s where A is 0 and 0s where
A is nonzero.
& AND A & B returns an array of the same dimension
as A and B; the new array has 1s
where both A and B have nonzero elements
and 0s where either A or B is 0.
| OR A | B returns an array of the same dimension
as A and B; the new array has 1s
where at least one element in A or B is nonzero
and 0s where A and B are both 0.
&& Short-Circuit AND Operator for scalar logical expressions. A && B
returns true if both A and B
evaluate to true, and false if they do not.
|| Short-Circuit OR Operator for scalar logical expressions. A || B
returns true if either A or B or
both evaluate to true, and false if they do not.
break Terminates the execution of a for or a while
loop.
case Used with switch to direct program execution.
continue Passes control to the next iteration of a for or
while loop
double Converts a logical array to class double.
else Delineates an alternate block of statements.
elseif Conditionally executes statements
end Terminates for, while, and if statements.
for Repeats statements a speci c number of times.
if Executes statements conditionally.
input(‘s1’, ‘s’) Display the prompt string s1 and stores user
input as a string.
logical Converts numeric values to logical values.
nargin Determines the number of input arguments of a
function.
nargout Determines the number of output arguments of a
function.
switch Directs program execution by comparing the
input expression with the associated case
expressions.
while Repeats statements an inde nite number of
times.
xor Exclusive OR function.

CHAPTER 3 Functions and Files


exp(x) Exponential; ex.
sqrt(x) Square root
log(x) Natural logarithm; ln x.
log10(x) Common (base-10) logarithm; log x ! log10 x.
abs(x) Absolute value;
angle(x) Angle of a complex number
conj(x) Complex conjugate.
imag(x) Imaginary part of a complex number
real(x) Real part of a complex number
ceil(x) Round to the nearest integer toward infinity
fix(x) Round to the nearest integer toward zero.
floor(x) Round to the nearest integer toward -infinity
round(x) Round toward the nearest integer
sign(x) Signum function, +1 if x =0; 0 if x =0; -1 if x < 0.
fminbnd(@function,x1,x2) Returns a value of x in the interval x1 ) x
) x2 that corresponds to a minimum of the
single-variable function described by the
handle @function.
fminsearch(@function,x0) Uses the starting vector x0 to nd a minimum
of the multivariable function described
by the handle @function.
fzero(@function,x0) Uses the starting value x0 to nd a zero of
the single-variable function described by the
handle @function.

CHAPTER 2 Numeric, Cell, and Structure Arrays

You might also like