# MEHRAN UNIVERSITY OF ENGINEERING AND TECHNOLOGY JAMSHORO Batch 10ES (3rd year 1st Term

)

PRACTICAL HANDOUTS FEEDBACK CONTROL SYSTEMS Lab-01

Introduction to MATLAB Environment and Basics

Name : ------------------------------------------------------------Roll No:-----------------------------------------------------------Date :--------------------------------------------------------------Score:---------------------------------------------------------------

Signature:-----------------------

• Operations performed on vectors: Various operations can be performed on the command window including Addition.. It is an interactive. Visit www. Control Engineering and applications. D=A*B • Point Operator: Point operator is used for element by element calculations.com for Assistance. it will multiply corresponding elements of A with A D=A .4] Both will give same results
. Digital Signal Processing. develop your own block diagrams etc. It is a powerful programming language which is used for symbolic and numerical computations effectively. can find the desired Transfer Function . it will divide corresponding elements of A with A (Make sure order of matrix should be same) • Transpose: Transpose can be found using compliment operator or any matrix can be converted to column matrix by use of semicolon. without writing programs in traditional languages like C and FORTRAN.. Matlab interprets commands like Basic does.
Basic Commands used for vector Analysis and Other functions:
Various command and used in MATLAB for vector analysis including: • Entering a Vector: Any vector can be entered in the command window containing certain values. The aim of Matlab is to enable us to solve complex numerical problems.mathsworks. division etc B=A+A .Lab Outline:
• • • • • To be familiar with the Basics of MATLAB Use of MATLAB in Control Systems Basic Commands used for vector Analysis Basic Plotting techniques Examples
Introduction to MATLAB:
MATLAB stands for Matrix Laboratory. Simulate and analyse the result. A=[1234] B =[ 0 1 3 4 ]. Thus. instead of compiling source code like C and FORTRAN require. C=A .2. multiplication. MATLAB will be used extensively in the labs of Signals and Systems./B………. C=A-B . can work in frequency and time domain. It is a High level programming language.
Use of MATLAB in Control Engineering:
It’s a very powerful tool used in Control System Designing. B=A’ C= [1.*A…….3. Simulink library gives a huge range of defined blocks for creating applications without writing codes. User can develop its own applications. Check out various possibilities for multiple inputs. matrix-based computer program for scientific and engineering numeric computation and visualization.

logarithmic etc x = 20. will yield 1 by 1 matrix containing all elements ones ones(2).g rand(1. E..hyperbolic of sine Zeros and Ones: Zeros….• • •
•
• • • • • • • • • •
Use of Semicolon and Parenthesis: Semicolon is used to terminate the corresponding line operation and shift the cursor to the next line without executing it while ( ) are used to execute ay function you specified. cos(x)……Cosine of 20 asin(x)….. EYE(M. will yield 1 by 1 matrix containing all elements zeros Ones…. Linspace(1. will yield 2 by 2 matrix containing all elements zeros WHO command: who command is used to display all the variables which are declared in the command window before using CLEAR command.5) Logspace: It generates again certain vectors which are logarithmically spaced of 50 logarithmically equally spaced points between decades 10^X1 and 10^X2.N) or EYE([M. Clc command just clear the screen or the command window.Linear spaced generates a row vector of 100 linearly equally spaced points between X1 and X2. cosine. Clear and Clc command: Clear command clear all the variables which are used from the memory location preventing any unpredictable result.3) RANDPERM(N) : A random permutation of the integers 1 to n can be generated using the RANDPERM(N) function
.. RAND(M.will yield 2 by 2 matrix containing all elements one Zeros…..x2) Identity Matrix: Matlab allows you to find identity Matrix by ‘eye’ command Eye(n)……where n = order of the matrix DET Determinant: DET(X) is the determinant of the square matrix X.. inverse and hyperbolic of these function.1). tangent.…….inverse of cosine csc(x).1 2].N) or RAND([M.inverse of sine sin(x)…… sine of 20 acos(x)….. Who…… press enter Inverse of a Matrix: Inverse can be calculated using inv command A=[1 3. EYE(N) is the N-by-N identity matrix.……cosecant of 20 sinh(x)…. Trigonometric functions: You have variety of trigonometric functions on MATLAB incuding sine.
•
INV Matrix inverse: INV(X) is the inverse of the square matrix X.(Matrix should be square Matrix) Inv(A) Linspace:.N]) returns an M-by-N matrix.N]) is an M-by-N matrix with 1's on the diagonal and zeros elsewhere. DIAG(x): Diagonal matrices and diagonals of a matrix RAND random number: RAND (N) returns an N-by-N matrix containing pseudorandom values drawn from the standard uniform distribution on the open interval(0.. Logspace(x1.

3)
Saving arrays to a file:
To save arrays for example M v. the file myvar. To restore the variables. 1 shows one is plotted and last one shows out of 2 functions 1 st function is plotted first.mat would be saved in the current directory.1. type the following command on MATLAB command prompt load myvar • To restore any specific variable(s) from the saved file.y2) Plot(t.1.axis2. Plot(t. we can use following command a=1.y)…… where ‘y’ is desired function and t is time is seconds Subplot: It is used to display 2 or more graphical function on the same graph with two different plots as shown in the figure. subplot(2.y2. type the following command on MATLAB command prompt load myvar M
Basic Plotting Commands and Codes:
Continous Time Plots: • Plot command: PLOT command is used to plot continuous tome signal defined in time domain as shown in figure.y1.2) •
Multiple functions on same plot: to plot 2 or more function simultaneously on one graph use the following code Plot (axis1.’*’)
•
.mat. Data files in MATLAB have extension .•
randperm(5) To create a random number between interval a and b.function1.t.y1.t. b=5 a+(b-a)*rand(1.1) 2 shows number of graphs.function2) Plot(t. (Note: Use plot command first) subplot(2.’o’. type type the following command on MATLAB command prompt save myvar M v Here myvar is name of the MATLAB file.

Modifying Your Graph:
AXIS Command: Define x and y axis and give range for x and y axis axis ([x1 x2 y1 y2]) X-LABEL Command: It gives x-axis appropriate label xlabel(‘time in seconds’)
.y..’*’)… Graph along function and distinct points are plotted
•
• Bar charts: Bar(x)
Discrete Plots: Use • Stem Command: STEM command to plot discrete time signals. Define n vector rather t. just points in form of * are plotted Plot(t.’*’).Plotting with symbols: To plot certain distinct values on the continuous graph use the following code. Plot(t.

01:7.’Electronics Engineering’) text (1. HOLD OFF: hold off returns to the default mode whereby PLOT commands erase the previous plots and reset all axis properties before drawing new plots. HOLD ON: hold on holds the current plot and all axis properties so that subsequent graphing commands add to the existing graph. .p). hold does not affect axis auto ranging properties.2) plot(t. plot(t. toggles the hold state. exp function and M-file.subplot(2.q) xlabel(‘sine function) text(0. HOLD: hold by itself. (Attach their answers in the handouts)
. HOLD ALL: hold all holds the plot and the current color and line style so that subsequent plotting commands will not reset the color an line style.01.1.1.q).p. ‘string2’ . hold off sets the Next Plot property of the current axes to “replace". text (a. p=cos(t) q=sin(p).0. hold on sets the Next Plot property of the current figure and axes to "add".’ string3’ .subplot(2.1.
Programs to Explore (just observe the result):
1. plot(t. title(‘Electronics’) TEXT: It adds text on the desired position (row and column) on the graph...’Electronics Engineering’) Where a and b are row and column positions Legend: LEGEND(‘string1’.10) and Linspace(1.6. hold on and hold off command. Matlab Environment.t=0:0.1. b. q=sin(3).2.3. Square root function (sqrt).10) 2.’Graph’) title(‘Plotting of sine function’) 3.005:10. t=0:0.q)
Explore:
Help.) puts a legend on the current plot using the specified strings as labels.Y-LABEL Command: It gives x-axis appropriate label ylabel(‘particular function’) TITLE: It gives suitable title to your graph.linspace(1.t.2.1) plot(t.

Explain the results 3.end-1) xix) M(:.:) xxi) M(:.1:2) xv) M(:. Generate the following row vector: a=1:5. a(1.1) xiv) M(1:2. and w = [1 3 8
Investigate the effect of the following command and explain operation/function: i) v(2) ii) sum = v + w iii) diff = v – w iv) vw = [v w] v) vw(2: 6) vi) v’ vii) z’ viii) z*v ix) [v. Investigate the following commands and explain: i.2)=[] xxii) fliplr(M) xxiii) flipud(M) xxiv) M(:) convert matrix column vector xxv) M=M(:)’ convert matrix to row vector xxvi) M=reshape(M.3) convert back to matrix 2. Apply DIAG function to vector v and matrix M mentioned in exercise#1. a(2)=6.end) xviii) M(:.1) xvi) M(2. a([1 4])=[]
.
1 1 1 and M = 2 9]. z = 0 4 0
2 3 6 3 1 5
1.[1 3]) xx) M(:. a([ 1 3])=0 iii.:) xvii) M(:.2)=100 iv. v’] xii) z + v’ xiii) M(1.2.Lab Activity: (To be Submitted)
You are supposed to perform them on MATLAB and copy them to word along attached printouts. ii. If v = [2 4 7
5]. w] x) v*z xi) [z. a(3)=[ ] v.

What role command windows plays here?
.2 8.) (NOTE: Write your roll number .t. Repeat problem 4 using the command plot(t.2 and 1.01:10 (i) cos (pi*t) (ii) sin(t) (iii) cos(t) (iv) cosec(2*pi*t) 5. ylabel on each graph. 6.10) and logspace(1. 7. What is the advantage of writing a program in M-file and if any error occurs in M-file how can you check that error. How can you save a program in MATLAB.y1. Use text command to plot sine(x*y) where x=your roll number*2. Repeat problem 4 using subplot command for plotting the following functions. Differentiate Linspace(1.y2…. Write a matlab code to plot following functions( attach graphs) Using t=1:0. y=cos(your roll number) and it should contain distinct points ‘*’ in the code with a suitable text (Your Name) at position 0. 9.4. xlabel.10) ..