Control Engineering-I Lab-1 Dated: 24-10-2007 1. What Is MATLAB
Control Engineering-I Lab-1 Dated: 24-10-2007 1. What Is MATLAB
ans =
1 1 1
1 1 1
1 1 1
(ii) zeros
Solution:
ZEROS Zeros array.
ZEROS(N) is an N-by-N matrix of zeros.
ZEROS(M,N) or ZEROS([M,N]) is an M-by-N matrix of zeros.
ZEROS(M,N,P,...) or ZEROS([M N P ...]) is an M-by-N-by-P-
by-...
array of zeros.
ZEROS(SIZE(A)) is the same size as A and all zeros.
Example program:
» zeros(3)
ans =
0 0 0
0 0 0
0 0 0
(iii) linspace
Solution:
» help linspace
ans =
Columns 1 through 7
0 0.0101 0.0202 0.0303 0.0404 0.0505
0.0606
(iv) logspace
Solution:
LOGSPACE Logarithmically spaced vector.
LOGSPACE(d1, d2) generates a row vector of 50
logarithmically
equally spaced points between decades 10^d1 and 10^d2. If
d2
is pi, then the points are between 10^d1 and pi.
LOGSPACE(d1, d2, N) generates N points.
See also LINSPACE, :.
Example program:
ans =
Columns 1 through 7
1.0000 1.0481 1.0985 1.1514 1.2068 1.2649
1.3257
5.graphs
The results of many control computations in Matlab are huge matrices containing, for
example, frequency responses, that one would like to display in graphical form.
We will plot graph of
ys=sin(t)
for t going from 0 to 5 seconds. First we need to generate a vector t containing the values
of time that we want to use. Type:
» t=linspace(0,5,51)
which makes t into a row vector of 51 values from0 to 5 inclusive. Another way of doing
same thing would be to type
» t=(0:0.1:5)
both ways will result in:
t =
Columns 1 through 7
0 0.1000 0.2000 0.3000 0.4000 0.5000
0.6000
» plot(t,ys)
1
0 .8
0 .6
0 .4
0 .2
-0 . 2
-0 . 4
-0 . 6
-0 . 8
-1
0 0.5 1 1 .5 2 2 .5 3 3 .5 4 4.5 5
the graph can be prettied using thee following self explanatory sequence of commands:
» xlabel('time[in seconds]');
» ylabel('graph of sin(t)');
» title('2KES23');
2K E S 23
1
0.8
0.6
0.4
0.2
graph of sin(t)
-0 . 2
-0 . 4
-0 . 6
-0 . 8
-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
t im e [ in s e c o n d s ]
more than one set of points can be plotted on the same axes, and more than one graph can
be displayed on the screen at once.
EXERCISE-5
(i) Generate a vector containing the values of cos (t) for the same time
range before.
Solution:
» yc=cos(t)
yc =
Columns 1 through 7
1.0000 0.9950 0.9801 0.9553 0.9211
0.8776 0.8253
» plot(t,yc)
0.8
0.6
0.4
0.2
-0 . 2
-0 . 4
-0 . 6
-0 . 8
-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
(ii) From “help” entry for “plot” find out how to get both ys an yc plotted
against t on the same axes.
Solution:
» t=(0:0.1:5);
» ys=sin(t);
» plot(t,ys)
» hold on
» plot(t,yc)
» hold off
1
0 .8
0 .6
0 .4
0 .2
-0 . 2
-0 . 4
-0 . 6
-0 . 8
-1
0 0 .5 1 1 .5 2 2 .5 3 3 .5 4 4 .5 5
(iii) From the “help” entry for “subplot” find out how to plot ys and yc
plotted on two separate graphs, one above the other.
Solution:
» subplot(2,1,1),plot(t,ys)
» subplot(2,1,2),plot(t,yc)
0.5
-0.5
-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
0.5
-0.5
-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5