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

In the command window you will see a prompt that looks like >> .

You type your commands immediately after this prompt. Once you
have typed the command you wish MATLAB to perform, press
<enter>. If you want to interupt a command that MATLAB is
running, type <ctrl> + <c>.
clear Command Window
Alternatives

As an alternative to the clc function, select Edit > Clear Command Window in the
MATLAB desktop.
Syntax

clc

Description

clc clears all input and output from the Command Window display, giving you a
"clean screen."

After using clc, you cannot use the scroll bar to see the history of functions, but
you still can use the up arrow to recall statements from the command history.
Examples

Use clc in a MA

close all deletes all figures whose handles are not hidden.

Clear all
Removes all functions and MEX-files, and variables and global variables from
your base workspace, as soon as possible. If called from a function, clear all also
clears the function workspace, leaving both workspaces empty. clear all removes
debugging breakpoints in code files and reinitializes persistent variables
clc;
close all;
clear all;
x = -pi:0.1:pi;
y = sin (x);
disp (y);
no graph was obtained as display command just displays the value of y

25

20

15

10

0
-4

clc
close all
clear all
subplot (1,1,1)
x = -pi:0.1:pi
y = exp(x)
disp (y)
plot (x,y)

-3

-2

-1

25

20

15

10

10

clc
close all
clear all
subplot (1,1,1)
x = -pi:0.1:pi
y = exp(x)
disp (y)
plot (y)

clc;
close all;
clear all;
subplot (1,1,1);
x = -pi:0.1:pi;

y = exp(x)

20

30

40

50

60

70

plot (y)

the command window was cleared

clc;
close all;
clear all;
subplot (1,1,1);
x = -pi:0.1:pi;

y = exp(x)
plot (y)

the command window was not cleared

When placed at the end of a command, the semicolon tells MATLAB not to display any output from that
command

Impulse
stem(X,Y) plots the data sequence, Y, at values specified by X. The X and Y inputs must be vectors or
matrices of the same size. Additionally, X can be a row or column vector and Y must be a matrix
with length(X) rows.

If X and Y are both vectors, then stem plots entries in Y against corresponding entries in X.

If X is a vector and Y is a matrix, then stem plots each column of Y against the set of values specified
by X, such that all elements in a row of Y are plotted against the same value.

If X and Y are both matrices, then stem plots columns of Y against corresponding columns of X.

clc;
close all;
t= -5:1:5;
y = ones(1,100);
y (1:5)=0;
stem (t,y);

??? Error using ==> stem at 44


X must be same length as Y.
Error in ==> su at 6
stem (t,y);

stem(Y) plots the data sequence, Y, as stems that extend from a baseline along the x-axis. The data values

are indicated by circles terminating each stem.


If Y is a vector, then the x-axis scale ranges from 1 to length(Y).
If Y is a matrix, then stem plots all elements in a row against the same x value, and the x-axis scale
ranges from 1 to the number of rows in Y.

clc;
close all;
t = 1:1:100
y = ones(1,100);
y (1:5)=0;
stem (y);
alternate
clc;
close all;
t= 1:1:100;
y (1:100)= 1;
y (1:5)=0;
stem (t,y);

1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0

10

20

30

40

50

60

70

80

90

100

The Transfer Fcn block assumes the following conditions:

The transfer function has the form

where u and y are the system input and outputs, respectively, nn and nd are
the number of numerator and denominator coefficients, respectively. num(s)
and den(s) contain the coefficients of the numerator and denominator in
descending powers of s.

The order of the denominator must be greater than or equal to the order of the
numerator.

For a multiple-output system, all transfer functions have the same


denominator and all numerators have the same orde

sys =
sys =
sys =
sys =
tfsys

tf(num,den)
tf(num,den,Ts)
tf(M)
tf(num,den,ltisys)
= tf(sys)

tfsys = tf(sys, 'measured')


tfsys = tf(sys, 'noise')
tfsys = tf(sys, 'augmented')
Description
Use tf to create real- or complex-valued transfer function models (TF objects) or to convert state-space or zeropole-gain models to transfer function form. You can also use tf to create generalized state-space (genss)
models or uncertain state-space (uss) models.

Creation of Transfer Functions

sys = tf(num,den) creates a continuous-time transfer function with numerator(s) and denominator(s)
specified by num and den. The output sys is:
A tf model object, when num and den are numeric arrays.

In the SISO case, num and den are the real- or complex-valued row vectors of numerator and denominator
coefficients ordered in descendingpowers of s. These two vectors need not have equal length and the transfer
function need not be proper. For example, h = tf([1 0],1)specifies the pure derivative h(s) = s.

Print the transfer function


clc;
close all;
clear all;
disp ('enter the transfer ');
n = input ('enter the coefficient') ;
d = input ('enter the coefficient');
sys = tf (n,d)

bode plot
clc;
close all;
clear all;
disp ('enter the transfer ');
n = input ('enter the coefficient') ;
d = input ('enter the coefficient');
sys = tf (n,d)
bode (sys)

nyquist
clc;
close all;
clear all;
disp ('enter the transfer ');
n = input ('enter the coefficient') ;
d = input ('enter the coefficient');
sys = tf (n,d)
subplot (1,2,1)
bode (sys)
subplot(1,2,2)
nyquist (sys)

TO FIND THE POLES, ZEROES AND GAIN

[z,p,k] = zpkdata(sys) returns the zeros z, poles p, and gain(s) k of the zero-pole-gain
model sys. The outputs z and p are cell arrays with the following characteristics:
z and p have as many rows as outputs and as many columns as inputs.
The (i,j) entries z{i,j} and p{i,j} are the (column) vectors of zeros and poles of the
transfer function from input j to output i.
The output k is a matrix with as many rows as outputs and as many columns as inputs such that k(i,j) is the
gain of the transfer function from input j to output i. If sys is a transfer function or state-space model, it is first
converted to zero-pole-gain form using zpk.
For SISO zero-pole-gain models, the syntax
[z,p,k] = zpkdata(sys,'v')
forces zpkdata to return the zeros and poles directly as column vectors rather than as cell arrays (see
example below).

DISPLAY

disp(X)example
Description
example

disp(X) displays the contents of X without printing the variable name. disp does not display empty
variables.

DISPLAY MULTIPLE CHARACTERS ON A SINGLE LINE


Concatenate strings together using the [] operator. Convert any numeric values to characters using
the num2str function.
name = 'Alice';
age = 12;
X = [name, ' will be ', num2str(age), ' this year.'];
Display the string.
disp(X)
Alice will be 12 this year.

Plotting poles and zeroes


clc;
close all;
clear all;
disp ('enter the transfer ');
n = [1 5];
d = [1 -5 6];
sys = tf (n,d);
[ z p k]= zpkdata (sys,'v')

pzmap (sys)

plot function
The plot function has different forms depending on the input arguments. For example, if y is a
vector, plot(y) produces a linear graph of the elements of y versus the index of the elements of y. If you
specify two vectors as arguments, plot(x,y) produces a graph of y versus x.
For example, the following statements create a vector of values in the range [0, 2] in increments of /100 and
then use this vector to evaluate the sine function over that range. MATLAB plots the vector on the x-axis and the
value of the sine function on the y-axis.
t = 0:pi/100:2*pi;
y = sin(t);
plot(t,y)
grid on % Turn on grid lines for this plot

Search R2013b Documentation

Search

MATLAB
Mathematics
Elementary Math
Polynomials

residue
Convert between partial fraction expansion and polynomial coefficients
expand all in page

Syntax
[r,p,k] = residue(b,a)
[b,a] = residue(r,p,k)
Description
The residue function converts a quotient of polynomials to pole-residue representation, and back again.

[r,p,k] = residue(b,a) finds the residues, poles, and direct term of a partial fraction expansion of
the ratio of two polynomials, b(s) anda(s), of the form

where bj and aj are the jth elements of the input vectors b and a.

[b,a] = residue(r,p,k) converts the partial fraction expansion back to the polynomials with
coefficients in b and a.

Definitions
If there are no multiple roots, then

The number of poles n is

n = length(a)-1 = length(r) = length(p)


The direct term coefficient vector is empty if length(b) < length(a); otherwise

length(k) = length(b)-length(a)+1
If p(j)

= ... = p(j+m-1) is a pole of multiplicity m, then the expansion includes terms of the form

Arguments
b,a
Vectors that specify the coefficients of the polynomials in descending powers of s

R
Column vector of residues

P
Column vector of poles

K
Row vector of direct terms

Limitations
Numerically, the partial fraction expansion of a ratio of polynomials represents an ill-posed problem. If the
denominator polynomial, a(s), is near a polynomial with multiple roots, then small changes in the data, including
roundoff errors, can make arbitrarily large changes in the resulting poles and residues. Problem formulations
making use of state-space or zero-pole representations are preferable.

Examples
If the ratio of two polynomials is expressed as

then

b = [ 5 3 -2 7]
a = [-4 0 8 3]
and you can calculate the partial fraction expansion as

[r, p, k] = residue(b,a)

r =
-1.4167
-0.6653
1.3320

p =
1.5737
-1.1644
-0.4093

k =
-1.2500
Now, convert the partial fraction expansion back to polynomial coefficients.

[b,a] = residue(r,p,k)

b =
-1.2500

-0.7500

0.5000

-1.7500

-0.0000

-2.0000

-0.7500

a =
1.0000

The result can be expressed as

Note that the result is normalized for the leading coefficient in the denominator.

SIMPLE PARTIAL FRACTION


partfrac(x^2/(x^3 - 3*x + 2))

You might also like