matlab-tutorial 2 class eces-304 presented by : shubham bhat

10
MATLAB-Tutorial 2 Class ECES-304 Presented by : Shubham Bhat

Upload: bridget-goodwin

Post on 13-Dec-2015

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: MATLAB-Tutorial 2 Class ECES-304 Presented by : Shubham Bhat

MATLAB-Tutorial 2 Class ECES-304

Presented by : Shubham Bhat

Page 2: MATLAB-Tutorial 2 Class ECES-304 Presented by : Shubham Bhat

% Nise, N.S. % Control Systems Engineering, 4th ed. % John Wiley & Sons, Hoboken, NJ, 07030%% Control Systems Engineering Toolbox Version 4.0 % Copyright © 2004 by John Wiley & Sons, Inc.%

% (ch2p8) Example 2.3: Let us do Example 2.3 in the book using MATLAB.

'(ch2p8) Example 2.3' % Display label.

numy=32; % Define numerator. deny=poly([0 -4 -8]); % Define denominator.[r,p,k] = residue(numy,deny) % Calculate residues, poles, and

% direct quotient.

Page 3: MATLAB-Tutorial 2 Class ECES-304 Presented by : Shubham Bhat

The models supported by CST are continuous-time models and discrete-time models of the following types:

•transfer functions •state-space models

Creating and handling LTI-models (Linear Time-Invariant)

Page 4: MATLAB-Tutorial 2 Class ECES-304 Presented by : Shubham Bhat

We will start with continuous-time models, and then take discrete-time models.

•Continuous-time transfer functions

The function "tf" creates transfer functions.

"tf" needs two MATLAB-vectors, one containing the coefficients of the numerator polynomial - taken in descending orders - and one for the denominator polynomial of the transfer function.

As an example we will create the transfer function

H0(s)=K0*s/(T0*s+1)

Creating models

K0=2; T0=4; num0=[K0,0]; den0=[T0,1]; H0=tf(num0,den0);

Page 5: MATLAB-Tutorial 2 Class ECES-304 Presented by : Shubham Bhat

'(ch2p9)' % Display label.'Vector Method, Polynomial Form' % Display label.numf=150*[1 2 7] % Store 150(s^2+2s+7) in numf and

% display.denf=[1 5 4 0] % Store s(s+1)(s+4) in denf and % display.'F(s)' % Display label.F=tf(numf,denf) % Form F(s) and display.clear % Clear previous variables from workspace.

% Nise, N.S. % Control Systems Engineering, 4th ed. % John Wiley & Sons, Hoboken, NJ, 07030%% Control Systems Engineering Toolbox Version 4.0 % Copyright © 2004 by John Wiley & Sons, Inc.%% (ch2p9): Creating Transfer Functions% (1) Vector Method, Polynomial Form: % A transfer function can be expressed as a numerator polynomial divided by a % denominator polynomial, i.e. F(s) = N(s)/D(s).

Page 6: MATLAB-Tutorial 2 Class ECES-304 Presented by : Shubham Bhat

'Vector Method, Factored Form' % Display label.

numg=[-2 -4] % Store (s+2)(s+4) in numg and % display.deng=[-7 -8 -9] % Store (s+7)(s+8)(s+9) in deng and % display.K=20 % Define K.'G(s)' % Display label.G=zpk(numg,deng,K) % Form G(s) and display.clear % Clear previous variables from

% workspace.

Page 7: MATLAB-Tutorial 2 Class ECES-304 Presented by : Shubham Bhat

The function "ss" creates linear state-space models having the form dx/dt=Ax + Bu ; y=Cx + Du

As illustrated in the following example: Given the following state-space model:dx1/dt=x2 ; dx2/dt=-4*x1 -2*x2 + 2*u; y=x1This model is created by

To retrieve the system parameters and give them specific names, we can execute

Continuous-time state-space models

A=[0,1;-4,-2]; B=[0;2]; C=[1,0]; D=[0];ss1=ss(A,B,C,D);

[A1,B1,C1,D1,Ts]=ssdata(ss1)

Page 8: MATLAB-Tutorial 2 Class ECES-304 Presented by : Shubham Bhat

% Nise, N.S. % Control Systems Engineering, 4th ed. % John Wiley & Sons, Hoboken, NJ, 07030%% Control Systems Engineering Toolbox Version 4.0 % Copyright © 2004 by John Wiley & Sons, Inc.%% (ch3p3): The state-space representation consists of specifying the A, B, C, and % D matrices followed by the creation of an LTI state-space object using the MATLAB% command, ss(A,B,C,D). Hence, for the matrices in (ch3p1) and (ch3p2), the % state-space representation would be:

'(ch3p3)' % Display label.A=[0 1 0;0 0 1;-9 -8 -7]; % Represent A.B=[7;8;9]; % Represent column vector B.C=[2 3 4]; % Represent row vector C.D=0; % Represent D.F=ss(A,B,C,D) % Create an LTI object and display.

Page 9: MATLAB-Tutorial 2 Class ECES-304 Presented by : Shubham Bhat

Homework Problems

% 13. Find the ratio of factors and ratio of polynomials

‘Polynomial form’Gtf=tf([1 25 20 15 42],[1 13 9 37 35 50])

‘Factored Form’Gzpk=zpk(Gtf)

% 14. Generate partial fractionsnumg=[-10 -60];deng=[0 -40 -50 (roots([1 7 100]))’ (roots([1 6 90]))’];[numg,deng]=zp2tf(numg’,deng’,1e4);Gtf=tf(numg,deng);G=zpk(Gtf);[r,p,k]=residue(numg,deng);

Page 10: MATLAB-Tutorial 2 Class ECES-304 Presented by : Shubham Bhat

Homework Problems

% 10. Write the transfer function in phase variable form

‘a’Num=100;Den=[1 20 10 7 100];G=tf(num,den)[Acc,Bcc,Ccc,Dcc]=tf2ss(num,den);Af=flipud(Acc);A=fliplr(Af)B=flipud(Bcc)C=fliplr(Ccc)