Control Lab Report Experiment No. 01
Control Lab Report Experiment No. 01
2/5
However, it is much more convenient to use an M-file (with .m extension) than to enter commands line by line at the MATLAB prompt. In MATLAB Command Window, click New->M-file to bring up a new M-file. In M-files, statements that begin with a % are considered to be comments and are ignored by MATLAB. The commands in these files are executed in the MATLAB environment simply by entering the name of the file without the .m. For this lab, create a new M-file Lab1.m and write the MATLAB code provided by the teacher in this file. Save the file in the D:\Control_SP_08\SecD folder. To execute the commands written in this file you have to change your working directory by writing the following commands at your MATLAB prompt as: >>D:\Control_SP_08\SecD Now write the file name at MATLAB prompt to run your file from the directory like following: >>Lab1 and then press ENTER. You will get the answers like following: p1 = 1 0 5 6 num/den = s^3 + 5 s + 6 ------------1 ans = 12 With the help of the teacher, run the M-file on a PC in MATLAB environment. Write down the answers from the MATLAB command prompt in your notebook and analyze them. Remember, in MATLAB, if the semicolon at the end of a command is not used, it will display computed answer for that command in the MATLAB command window. After running the M-file, two figures will pop up. Go to Figure No. 2. Click on Tools-Axes Properties. In Edit Axes Properties window, click the Manual in Tick Step option. Enter 0.2 for time in seconds. Keep the default value for y(t). Click Manual in the Limits option. Enter 1.8 in the right cell for time in seconds. Keep the left cell as 0. Click Apply and then Ok. This will allow you to analyze both the figures within the same zone. Report: Write a report on this experiment. The MATLAB code and plots will be provided in the course website. Comment on the step responses for different control systems. Did you find any difference in the step responses of open loop and closed loop control systems? Provide your comments and recommendations for it.
3/5
Matlab codes: %EEE 4101 (Control Systems) %Lab 1 %MATLAB codes clc; %Clears the MATLAB Command Window close all; clear all; %Closes all figures %Clears all variables
%Part 1 %Creating equations, Calculating roots, Displaying transfer functions etc. p1=[1 0 5 6] printsys(p1,[0 0 0 1],'s') %Defines the coefficients of a linear equation %Outputs the polynomial of the equation %as a transfer function and also in %symbolic form, where the variable %is labelled as "s" %Evaluates the polynomial of the equation %with a value of 1 %Calculates the roots of the equation %Creates an equation from the roots (r1). %This should match with the original equation(p1). %But it will not match exactly in this case. %This is because the imaginary portion of the %complex root has fractions and MATLAB cannot %incorporate all digits to the right of a %fraction in computations. %Outputs the equation as a transfer function %and also in symbolic form, where the variable %is labelled as "s".This should match with %the previous transfer function
polyval(p1,1)
r1=roots(p1) p2=poly(r1)
printsys(p2,[0 0 0 1],'s')
%Define an expression called exp1 %Define an expression called exp2 %Multiply these two expresions and store the %result in exp
4/5
%Part 2 %Simulating an open loop control system clear all; OL_TRF_num = [1 1] OL_TRF_den = conv([1 3], [1 5]) %Clears all variables (i.e. p1,r1,p2 etc.) %Define the numerator of a transfer function %Define the denominator of a transfer function
printsys(OL_TRF_num, OL_TRF_den, 's') %Outputs the transfer function (open-loop) in %symbolic form, where the variable is "s"
[y, x, t]=step(OL_TRF_num, OL_TRF_den); %Simulate this system for a step input.It will %store the simulation results in certain %variables like y,x,t figure (1) plot(t, y) grid %Label the figure %Display the simulation in a 2-D plot %Add gridlines in the figure %Add a title to the figure %Label y axis %Label x axis
title('Unit step responce for open loop') ylabel('y(t)') xlabel('time in seconds') %Part 3 %Simulating a close loop control system %This control system has unity feedback
[CL_TRF_num, CL_TRF_den] = cloop(OL_TRF_num, OL_TRF_den) %Calculates the close-loop transfer function %from the open-loop transfer function printsys(CL_TRF_num, CL_TRF_den, 's') %Outputs the transfer function (closed-loop) in %symbolic form where the variable is "s" [y, x, t]=step(CL_TRF_num, CL_TRF_den); %Simulate this system for a step input.It will %store the simulation results in certain %variables like y,x,t Prepared by Shahriyar Masud Rizvi 4
5/5
%Label the figure %Display the simulation in a 2-D plot %Add gridlines in the figure %Add a title to the figure