You are on page 1of 14

Help CC version 5

Para descargar: http://www.programcc.com/download.asp

Program CC provides high level graphics as well as numerical routines for system building, analysis, and
design of linear control systems.
For detailed information, type WINHELP with a function name or WINHELP in the command line. For
instance,
CC>winhelp poles Or

CC>winhelp
Also, all functions can be listed using the WHAT command:
CC>what
*************************************************************************
A default directory can be set to save and load files using the PATH command.
For instance, to set the default directory:

CC>path('c:\cc')
*************************************************************************
To change the current working directory use the CD command:
CC>cd c:\dir Or

CC>cd('c:\dir')
*************************************************************************
Variable names are case sensitive and must start with a letter or underscore. To enter real and complex
numbers:

CC>a=2
CC>a
a=2

CC>b=3+4*j
CC>b
b = 3 + 4j
*************************************************************************
To enter real and complex matrices:
CC>c=(1,2;3,4)
CC>c
c=
1 2
3 4

CC>d=(1+j,2;3,4+5*j)
CC>d
d=
1 + 1j 2 + 0j
3 + 0j 4 + 5j
*************************************************************************

To enter a s-domain transfer function:

CC>g = 5/(s+5)

1
CC>g

5
g(s) = —————
s+5
*************************************************************************
To enter a z-domain transfer function:

CC>gd=5*(z+1)/(z+.8)
CC>gd

5(z+1)
gd(z) = ————————
z+0,8
*************************************************************************
Transfer function matrices are created whenever matrix elements are transfer functions such as:

CC>h=(g,1; 0,1/s)
CC>h
#rows = 2, #columns = 2
---- column # 1 ----
5
h(1,1)(s) = —————
s+5
h(2,1)(s) = 0
---- column # 2 ----

h(1,2)(s) = 1

1
h(2,2)(s) = ———
s
*************************************************************************
String variables are defined by characters enclosed in single quotes:
CC>str='string variable'
CC>str
str = 'string variable'
*************************************************************************
A vector of string variables can have ragged lengths and are created like rows in a matrix separated by
semicolons:

CC>vstr=('first row';'second row')


CC>vstr
vstr =
'first row'
'second row'

*************************************************************************
Transfer functions are entered as algebraic expressions. To enter the following transfer function:
10(s+1)
g(s) = -----------------
s(s^2 +2s +100)

CC>g=10*(s+1)/(s*(s^2+2*s+100))
CC>g
10(s+1)

2
g(s) = —————————————————
s(s^2 +2s +100)
*************************************************************************
Polynomials are treated as transfer functions with a unit denominator. For example:
CC>p=s^3+3*s^2+10*s+100; p
p(s) = s^3 +3s^2 +10s +100
*************************************************************************
Transfer funtions can also be entered with a vector of coefficients.
The transfer function g(s) can be re-entered with its coefficients:
(1) the number of polynomials in the numerator
(2) the polynomials, each starting with its order
(3) the number of polynomials in the denominator
(4) the polynomials, each starting with its order
CC>g=enter(2,0,10,1,1,1, 2,1,1,0,2,1,2,100)
CC>g
10(s+1)
g(s) = —————————————————
s(s^2 +2s +100)
*************************************************************************
The STI shorthand form (s+a = (a), s^2+2*zeta*w*s+w^2 = [zeta, w]) can be used to enter transfer
functions. For the g(s) example, type the coefficients:
(1) the number of numerator factors
(2) the factors
(3) the number of denominator factors
(4) the factors
CC>g=senter(2,0,10,1,1, 2,1,0,2,.1,10)
CC>sho(g)

10( 1)
g(s) = ——————————————
(0)[ 0,1, 10]
*************************************************************************
Transfer functions can be displayed in several different ways as suggested by the names of the following
functions.
CC>display(g) Or

CC>disp(g)
10(s+1)
g(s) = —————————————————
s(s^2 +2s +100)
*************************************************************************
To display g(s) in the shorthand form:
CC>shorthand(g) Or

CC>sho(g)
10( 1)
g(s) = ——————————————
(0)[ 0,1, 10]
*************************************************************************
To display as single numerator and denominator polynomials:
CC>single(g)
10s+10
g(s) = —————————————————
s^3 +2s^2 +100s
*************************************************************************
To display with each high order coefficient set to one:

3
CC>unitary(g)
10(s+1)
g(s) = —————————————————
s(s^2 +2s +100)
*************************************************************************
To display as the pole-zero-form:
CC>pzf(g)
10(s+1)
g(s) = ————————————————————
s[(s+1)^2+9,95^2]
*************************************************************************
To display as the time-constant-form:
CC>tcf(g)
0,1(s+1)
g(s) = ———————————————————————
s( 0,01s^2 +0,02s +1)
*************************************************************************
For partial fraction expansion:
CC>pfe(g)
0,1 0,1s-9,8
g(s) = ————— - ———————————————————
s [(s+1)^2+9,95^2]
*************************************************************************
For inverse Laplace transform:
CC>ilt(g)

g(t) = 0,1 + sin(9,95t-0,1002)*exp(-t) for t >= 0


*************************************************************************
A matrix with at least one polynomial or transfer function element is a transfer function matrix.
For example:
CC>h=(1/s, 5*(s+1)/(s^3+s^2+s+1))
CC>h
#rows = 1, #columns = 2
---- column # 1 ----
1
h(1,1)(s) = ———
s
---- column # 2 ----
5(s+1)
h(1,2)(s) = ————————————————
s^3 +s^2 +s +1
*************************************************************************
The same display commands used for transfer functions can be used for tf
matrices. These are disp, sho, pzf, tcf, single, and unitary. For example:
CC>sho(h)
#rows = 1, #columns = 2
---- column # 1 ----
1
h(1,1)(s) = ———
(0)
---- column # 2 ----
5( 1)
h(1,2)(s) = ———————————
( 1)[0, 1]
*************************************************************************

4
Matrix algebra including matrix inversion, selection of elements or blocks, and changing elements or blocks
are all possible. For example, to extract the 1,2 element:
CC>h(1,2)
5(s+1)
ans(s) = ————————————————
s^3 +s^2 +s +1
*************************************************************************
Transfer functions can be manipulated algebraically. Consider the following two systems:
1
g1(s) = -----
(5)

-2(0)
g2(s) = -----------
[0.5, 10]
**************************************************************************
Enter the system model:
CC>g1=senter(1,0,1, 1,1,5)
CC>sho(g1)
1
g1(s) = ————
( 5)
CC>g2=senter(2,0,-2,1,0, 1,2,.5,10)
CC>sho(g2)
-2(0)
g2(s) = ———————————
[ 0,5, 10]
**************************************************************************
To add the two transfer functions:
CC>g=g1+g2
CC>sho(g)
-(-10)( 10)
g(s) = ———————————————
( 5)[ 0,5, 10]
**************************************************************************
To subtract g2(s) from g1(s):
CC>g=g1-g2
CC>sho(g)
3[ 0,5774, 5,774]
g(s) = ——————————————————
( 5)[ 0,5, 10]
**************************************************************************
The product of g1(s) and g2(s) is:
CC>g=g1*g2
CC>g
-2s
g(s) = —————————————————————
(s+5)(s^2 +10s +100)
**************************************************************************
Dividing g2(s) into g1(s) gives:
CC>g=g1/g2
CC>g
-0,5(s^2 +10s +100)
g(s) = —————————————————————
s(s+5)
**************************************************************************

5
Program CC provides a feedback operator to close a loop, which is convenient in controller design and
analysis. The feedback operator is defined as:
g|h = g/(1+h*g)
where, g is the open loop system and h is the feedback loop.
**************************************************************************
The variables g and h can be of any compatible type and the dimensions of g and tranpose of h must be the
same. For unity feedback systems the closed-loop system is computed by:

g|1
If g is multivariable, it must be square, and the unity gain in the
feedback path expands to the correct size identity matrix.
The feedback operator has higher precedence than multiplication.
**************************************************************************
In the following example a closed-loop system is computed and displayed.
The system transfer function is given as:
CC>g=10*(s+1)/s/(s+2)
The feedback loop is:
CC>h=3/(s+4)
The closed-loop system is:
CC>cl=g|h
To display the closed-loop transfer functions in the pole-zero form:
CC>pzf(cl)
10(s+1)(s+4)
cl(s) = ——————————————————————————————————
(s+0,8977)[(s+2,551)^2+5,188^2]
**************************************************************************
The transfer functions can be converted to a state space model and a closed- loop state space model can be
built.
CC>pg=ccf(g)
CC>ph=ccf(h)
CC>pg|ph
ans.a =
0 1 0
0 -2 -3
10 10 -4
ans.b =
0
1
0
ans.c =
10 10 0
ans.d = 0
**************************************************************************
To check the system:
CC>what(pg|ph)
Quadruple with 1 output, 1 input and 3 states
**************************************************************************
Program CC provides interactive graphics: BODE, NYQUIST, and NICHOLS plot for frequency response.
Consider a system with the following transfer function:
2000
g(s) = ------------------
(s+2)(s+7)(s+16)
**************************************************************************
The transfer function is entered:
CC>g=2000/((s+2)*(s+7)*(s+16))
**************************************************************************

6
To plot the frequency responses of the transfer function above, use the BODE command:
CC>bode(g)
**************************************************************************
To improve scales, asymptotes, title, and labels:
CC>bode(g,'asymptotes','xlim',-.01,1000,4,'ylim',-40,40,4)
CC>title('Bode of G(s)','fontsize',11)

Also, the magnitude and phase curves can be plotted in two seperate plots:
CC>subplot(211); bode(g,'bodeoption',1,'xlabel',','asy','ylim',-40,40,4)
CC>subplot(212); bode(g,'bodeoption',2)
CC>title('Bode of G(s)','fontsize',11)
**************************************************************************
To check the robustness margin, use the MARGIN command:
CC>margin(g)
At w= 9,18 r/s, Phase margin= 19,79 deg, Delay margin= 0,0376 sec
At w= 9,76 r/s, Mp= 3,16 (10,00 dB)
At w= 12,6 r/s, Gain margin= 1,86 ( 5,40 dB)
**************************************************************************
To check the robustness margin at specific frequency:
CC>point(g,1)
At s = 0 + 1j
g(s) = 6,195 - 4,887j
Magnitude = 7,890 (17,94 dB)
Phase = -38,27 deg
*************************************************************************
For a Nyquist plot:
CC>nyquist(g,'grid','polar','xlim',-2,2,4,'ylim',-4,2,3)
CC>title('Nyquist of G(s)','fontsize',11)
**************************************************************************
For a Nichols plot:
CC>nichols(g,'grid','polar')
CC>title('Nichols of G(s)','fontsize',11)
**************************************************************************
Add a zero at s = -1 and a pole s = -3, and plot the above frequency
response plots:
CC>g=g*(s+1)/(s+3)
2000(s+1)
g(s) = ——————————————————————
(s+2)(s+7)(s+16)(s+3)
CC>bode(g)
CC>title('Bode of G(s)','fontsize',11)
CC>nyquist(g,'redo')
CC>nichols(g,'redo')
**************************************************************************
Program CC provides interactive graphics. TIME plots open- and closed-loop step responses as well as user
specified input vectors.
**************************************************************************
As an example, the step responses of a second order system for five different damping ratios will be plotted.
The transfer function is given as:
omega^2
g(s) = ------------------------------
(s^2+2*zeta*omega*s+omega^2)
Where omega = 1 and zeta will vary from .2 to 1
**************************************************************************
The transfer function can be entered directly or the TWOPOLES command can be used.
In this example, use the TWOPOLES command:

7
CC>g1=twopoles(0.2,1)
CC>g2=twopoles(0.4,1)
CC>g3=twopoles(0.6,1)
CC>g4=twopoles(0.8,1)
CC>g5=twopoles(1,1)

**************************************************************************
To plot the step responses of the transfer functions above:
CC>time(g1,'-',g2,':',g3,'--',g4,'-.',g5,'-..')
**************************************************************************
Change x and y limits, and add title and y-label:
CC>title('Step Responses with Different Dampings','fontsize',11)
CC>ylabel('Output')
CC>text('zeta=0.2',4.98,1.53,'callout',4.13,1.4)
CC>text('0.4',2.84,1.3)
CC>text('0.6',3,1.14)
CC>text('0.8',3.5,1.05)
CC>text('1',3.69,.9)
**************************************************************************
To plot the response to other inputs, determine the Laplace transformation of the input, multiply it by G(s),
and then plot the response of the product. Responses to three different inputs
(1) unit step
(2) exp(-2t)
(3) sin(2t)
for the transfer function:
s-5
g(s) = ----------
s^2+3s+2
will be ploted.
**************************************************************************
Enter the transfer function:
CC>g=(s-5)/(s^2+3*s+2)
CC>gexp=g/(s+2)
CC>gsin=g*2/(s^2+4)
To plot responses:
CC>time(g,'-',gexp,':',gsin,'--','xlim',0,10,5,5,'ylim',-3,1,4)
CC>title('Responses to Different inputs','fontsize',11)
CC>ylabel('Output')
CC>text('sine',5.31,-0.53,'callout',4.42,-.79)
CC>text('exp',7.82,-1.62,'callout',7.39,-1.25)
CC>text('step',5.37,-1.92,'callout',4.03,-2.37)
**************************************************************************
The root locus is one of the classical control anaysis techniques.
Program CC provides the ROOTLOCUS (or in shorthand form RL) command which takes non-uniform
steps in gain, plots the closed-loop poles for each value, and connects the points.
To plot the root locus of the transfer function:
1
g(s) = -------------------
s(s+3)(s^2+6s+64)
**************************************************************************
Enter the transfer function:
CC>g=1/(s*(s+3)*(s^2+6*s+64))
**************************************************************************
The root locus plot:
CC>rootlocus(g,'zetaomega','xlim',-10,10,4)
CC>title('Root Locus of G(s)','fontsize',11)

8
*************************************************************************
Add a zero at s = -5:
CC>g=g*(s+5)
And plot the root locus:
CC>rootlocus(g,'redo')
CC>title('Adding a zero at s = -5\n','fontsize',11)

To mark some closed-loop poles:


CC>rootlocus(g,'clgains',100:50:300,'redo')
**************************************************************************
In this example, an altitude autopilot is designed using the pole placement design method. The full state is
assumed to be available for feed- back. The elevator is used as the control input.
The state space system from the input delta_e to the states (u,w,q,theta,h) is known.
**************************************************************************
First, build the state space model by entering system matrices:
CC>a=( -9.7e-3,1.6e-3,0,-32.17,0;...
-0.0955,-1.43,660,0,0;...
1.2415e-4,-0.021641,-2.778,0,0;...
0,0,1,0,0;...
0,-1,0,660,0 )
CC>b=(-69.8;0;-26.1;0;0)
CC>c=eye(5)
CC>d=zeros(5,1)
**************************************************************************
Now, build the state space quadruple for design:
CC>p=pack(a,b,c,d)
CC>what(p)
Quadruple with 5 outputs, 1 input and 5 states
**************************************************************************
Pole Placement Design:
Desired closed-loop poles:
CC>clpoles=(-3, -3, -2, -0.2, -0.01)
Pole placement:
CC>f=poleplace(p(:,1),clpoles)
CC>f
f=
1,378026e-004 9,801347e-004 -0,1533302 -0,5954131 -1,359636e-004
**************************************************************************
We build closed-loop system with full state feedback gain:
CC>f1=(f(1:4),0)
CC>f2=f(5)
CC>fb0=(1/p.c(1:5,1:5))
CC>fb1=(0,0,0,0,1)
CC>cl=p(:,1)|(f1*fb0)
CC>cl=(cl*f2)|(fb1*fb0)
CC>what(cl)
Quadruple with 5 outputs, 1 input and 5 states
**************************************************************************
Step response with altitude command of 100 ft and zero initial condition:
CC>(yt,y)=sim(100*cl,'step',1,'delta',.01,'tmax',30)
Conversion of units from rad to degrees:
CC>y(:,3:4)=y(:,3:4)*57.3
**************************************************************************
The intersample behavior of a sampled-data system can be simulated using a combination of the CONVERT
and EXPAND commands. This type of problem is complicated because the input/output response cannot be

9
represented by a transfer function. What we must do is compute the output z-transform that is valid for a
particular input.
Start with a double integrator analog system:
1
g(s) = -----
s^2

and a lead compensator:

25(s+1)
k(s) = ---------
(s+10)
**************************************************************************
The system transfer function is:
CC>g=1/s^2
CC>g
1
g(s) = —————
s^2
**************************************************************************
The lead compensator transfer function is:
CC>k=25*(s+1)/(s+10)
CC>k
25(s+1)
k(s) = —————————
s+10
**************************************************************************
And, the system input r(s) is:
CC>r=1/s
CC>r
1
r(s) = ———
s
**************************************************************************
The closed loop analog output from the input is computed using the feedback operator:
The closed loop system is:
CC>cl=(g*k)|1
CC>cl
25(s+1)
cl(s) = —————————————————————
s^3 +10s^2 +25s +25
**************************************************************************
The output from input of the analog system is:
CC>y=cl*r
CC>y
25(s+1)
y(s) = ————————————————————————
s(s^3 +10s^2 +25s +25)
**************************************************************************
The zero-order-hold equivalence of the system g(s) with 0.2 second sampling time is computed using the
CONVERT command.
CC>T=0.2
CC>gd=convert(g,8,T)
CC>gd
0,02(z+1)
gd(z) = ———————————

10
(z-1)^2
**************************************************************************
Let us consider finding a desired cascade compensator k(s) that will satisfy:
(1) closed-loop step response within 20% of overshoot
(2) closed-loop step response within 2% settling time of 4 seconds
(3) at least 45 degrees of phase margin
In this example, we try an iterative approach to reach the solution in three attempts.
**************************************************************************
The plant considered in this example is a double-integrator
1
g(s) = -----
s^2
To enter the transfer function:
CC>g=1/s^2
CC>g
1
g(s) = —————
s^2
**************************************************************************
First, we translate a time domain specification into the frequency domain to find the approximate bandwidth
of the closed-loop system. To find the approximate starting point, we assume the closed-loop system will be
first order. In this case, the pole location of the closed-loop system a/(s+a) that results in 2% error at 4
seconds is:
a = -ln(.2)/4 = .978
**************************************************************************
If the compensator k(s) is a pure gain, gk(s) will have a phase margin of 0 degree and phase lead is needed,
which we will get using a lead compensator.
Use the LEADLAG command to find a compensator with PM = 45 degrees at a frequency of 1 rad/sec.
CC>k=leadlag(1,45)
CC>k
5,828(s+0,4142)
k(s) = —————————————————
s+2,414
**************************************************************************
Compute gk(s) and use the 'point' command to find the gain at 1 rad/sec
CC>gk=g*k
CC>gk
5,828(s+0,4142)
gk(s) = —————————————————
s^2(s+2,414)
CC>point(gk,1)
At s = 0 + 1j
gk(s) = -1,707 - 1,707j
Magnitude = 2,414 (7,656 dB)
Phase = -135 deg
**************************************************************************
The gain is 2.414, so divide k(s) by 2.414 so that the unit magnitude crossover is 1 rad/sec, which matches
the approximate closed-loop band- width which we initially started with:
CC>k=k/2.414
CC>gk=g*k
CC>gk
2,414(s+0,4142)
gk(s) = —————————————————
s^2(s+2,414)
**************************************************************************
Change display format:

11
CC>format mini
Display k(s) in shorthand form:
CC>sho(k)
2,414( 0,4142)
k(s) = ——————————————
( 2,414)
**************************************************************************

The transfer function of the closed-loop system is:


CC>cl=gk|1
The closed-loop transfer function in shorthand form:
CC>sho(cl)
2,414( 0,4142)
cl(s) = ——————————————————————
( 0,9998)[ 0,7071, 1]
**************************************************************************
Now, we survey the design using 'Bode', and 'Root Locus', and 'closed- loop step response' plots.
To draw the Bode plot:
CC>subplot(311);bode(gk,'bodeoption',3,'asy')
CC>title('Bode of GK(s)')
To draw the Root Locus plot:
CC>subplot(312);rootlocus(gk,'xlim',-10,2,6,'ylim',0,10,5,'grid','polar')
CC>title('Root Locus of GK(s)')
To draw the closed-loop step response plot:
CC>subplot(313);time(cl,'ylabel','output')
CC>title('Closed-Loop Step Response')
**************************************************************************
From the Bode plot it is seen that the phase margin specification of 45 degrees is satisfied. The zero and pole
breaks are clearly seen from the magnitude asypmtotes, and the unit magnitude crossover is seen to
satisfy the desired property. From the closed-loop step response, however, it is seen that the 33% overshoot
violates the 20% spec, and the 6.2 seconds settling time violates the 4 seconds spec.
**************************************************************************
In the second attempt the settling time is going to be decreased to 4 seconds. This is done by increasing the
unit magnitude crossover by the ratio of achieved to desired settling time; 6.2/4.0*1=1.55 rad/sec.
A lead compensator k(s) with 45 degrees at this frequency is created, and the the gain is adjusted so that
gk(s) has its unit magnitude crossover at 1.55 rad/sec.
Use the LEADLAG command to find k(s) at the frequency of 1.55 rad/sec with 45 degrees of phase angle.
CC>k=leadlag(1.55,45)
CC>sho(k)

5,828( 0,642)
k(s) = —————————————
( 3,742)
**************************************************************************
Compute the closed-loop transfer function with the new compensator:
CC>cl=(g*k)|1
Display the closed-loop transfer function in shorthand form:
CC>sho(cl)
5,828( 0,642)
cl(s) = ————————————————————————
( 1,532)[ 0,707, 1,563]
*************************************************************************
Survey the design using 'Bode', 'Root Locus', and 'closed-loop step response'
CC>subplot(311);bode(gk,'redo')
CC>subplot(312);rootlocus(gk,'redo')
CC>subplot(313);time(cl,'redo')

12
**************************************************************************
From the Bode plot it is seen that phase margin spec of 45 degrees is satisfied. The zero and pole breaks are
clearly seen from the magnitude asymptotes, and the unit magnitude crossover is seen to satisfy the desired
property.
From the closed-loop step response, however, it is seen that the 33% overshoot violates the 20% spec, and
the 6.2 seconds settling time violates the 4 seconds spec.
**************************************************************************

In the third and last attempt the overshoot is reduced. The overshoot is related to the phase margin and the
analytical relations between overshoot and phase margins for systems with two poles and no zeros are well
established.
For systems with more than two poles and non-zero zeros, the trial and error approach would be easier and
appropriate.
So after a few attempts, it is determined that a phase margin of 60 degrees results in a 20% overshoot.
Use the LEADLAG command:
CC>k=leadlag(1.55,60)
Take a look at the properties at the frequency of 1.55 rad/sec
CC>point((g*k),1.553
At s = 0 + 1,553j
tf(s) = -0,775 - 1,342j
Magnitude = 1,550 (3,807 dB)
Phase = -120,0 deg
Divide k(s) by 1.553 so that the unit magnitude crossover is 1.55 rad/sec
CC>k=k/1.553
**************************************************************************
The closed-loop response is not shown, but the settling time has increased to 6.2 seconds, so the desired unit
magnitude crossover of gk(s) bumped up to 6.2/4.0*1.55=2.4 rad/sec
Use the LEADLAG command again to find compensator k(s)
CC>k=leadlag(2.44,60)
CC>sho(k)
At the frequency of 2.4 rad/sec:
CC>point((g*k),2.4)
At s = 0 + 2,4j
tf(s) = -0,3194 - 0,5531j
Magnitude = 0,639 (-3,894 dB)
Phase = -120,0 deg
Divide k(s) by the magnitude of gk(s):
CC>k=k/.648
Closed-loop transfer function is:
CC>cl=(g*k)|1
CC>sho(cl)
21,49( 0,6538)
cl(s) = ————————————————————————
( 1,119)( 2,151)( 5,836)
**************************************************************************
Survey the design:
CC>subplot(311);bode(gk,'redo')
CC>subplot(312);rootlocus(gk,'redo')
CC>subplot(313);time(cl,'redo')
**************************************************************************
To verify the robustness margin, use the MARGIN command:
CC>margin(g*k)
At w= 1,11 r/s, Mp= 1,22 (1,74 dB)
At w= 2,37 r/s, Phase margin= 59,99 deg, Delay margin= 0,442 sec
No gain margin found

13
**************************************************************************
From the Bode plot the phase margin of 60 degrees satisfies the spec and the overshoot and settling time is
20% and 4 seconds, which satisfy the specifications.

14

You might also like