7.9.8.2
The following MATLAB program computes the graph of the three cost func-
tions.
%Cost function program
gaininc = 1
gainmin = 50
gainmax = 70
gain = gainmin;;
kount = 1;;
p=10
K=1870
kount = 1
while (gain <= gainmax);;
chareq(1) = 1;;
chareq(2) = p+gain;;
chareq(3) = p*gain;;
chareq(4) = K;;
x=roots(chareq);;
if imag( x(1) ) > 0
w=imag( x(1) );;
x=abs( real( x(i) ) );;
zeta = cos( atan( w/x ) );;
cf = 0.34*abs( 4.0 - w )/4.0 +0.33*abs( 0.8 - zeta)/0.8 + 0.33 * abs(K-1870)/1870;;
elseif imag( x(2) ) > 0
w=imag( x(2) );;
x=abs( real( x(2) ) );;
zeta = cos( atan( w/x ) );;
cf = 0.34*abs( 4.0 - w )/4.0 +0.33*abs( 0.8 - zeta)/0.8 + 0.33 * abs(K-1870)/1870;;
elseif imag( x(3) ) > 0
w=imag( x(3) );;
x=abs( real( x(3) ) );;
zeta = cos( atan( w/x ) );;
cf = 0.34*abs( 4.0 - w )/4.0 +0.33*abs( 0.8 - zeta)/0.8 + 0.33 * abs(K-1870)/1870;;
end
a(kount) = gain;;
b(kount) = cf;;
gain = gain + gaininc;;
kount = kount + 1;;
end
K=2270
gain=gainmin
kount = 1
while (gain <= gainmax);;
1
chareq(1) = 1;;
chareq(2) = p+gain;;
chareq(3) = p*gain;;
chareq(4) = K;;
x=roots(chareq);;
if imag( x(1) ) > 0
w=imag( x(1) );;
x=abs( real( x(i) ) );;
zeta = cos( atan( w/x ) );;
cf = 0.34*abs( 4.0 - w )/4.0 +0.33*abs( 0.8 - zeta)/0.8 + 0.33 * abs(k-1870)/1870;;
elseif imag( x(2) ) > 0
w=imag( x(2) );;
x=abs( real( x(2) ) );;
zeta = cos( atan( w/x ) );;
cf = 0.34*abs( 4.0 - w )/4.0 +0.33*abs( 0.8 - zeta)/0.8 + 0.33 * abs(K-1870)/1870;;
elseif imag( x(3) ) > 0
w=imag( x(3) );;
x=abs( real( x(3) ) );;
zeta = cos( atan( w/x ) );;
cf = 0.34*abs( 4.0 - w )/4.0 +0.33*abs( 0.8 - zeta)/0.8 + 0.33 * (K-1870)/1870;;
end
c(kount) = gain;;
d(kount) = cf;;
gain = gain + gaininc;;
kount = kount + 1;;
end
K=2680
gain=gainmin
kount = 1
while (gain <= gainmax);;
chareq(1) = 1;;
chareq(2) = p+gain;;
chareq(3) = p*gain;;
chareq(4) = K;;
x=roots(chareq);;
if imag( x(1) ) > 0
w=imag( x(1) );;
x=abs( real( x(i) ) );;
zeta = cos( atan( w/x ) );;
cf = 0.34*abs( 4.0 - w )/4.0 +0.33*abs( 0.8 - zeta)/0.8 + 0.33 * (K-1870)/1870;;
elseif imag( x(2) ) > 0
w=imag( x(2) );;
x=abs( real( x(2) ) );;
zeta = cos( atan( w/x ) );;
cf = 0.34*abs( 4.0 - w )/4.0 +0.33*abs( 0.8 - zeta)/0.8 + 0.33 * (K-1870)/1870;;
2
elseif imag( x(3) ) > 0
w=imag( x(3) );;
x=abs( real( x(3) ) );;
zeta = cos( atan( w/x ) );;
cf = 0.34*abs( 4.0 - w )/4.0 +0.33*abs( 0.8 - zeta)/0.8 + 0.33 * (K-1870)/1870;;
end
e(kount) = gain;;
f(kount) = cf;;
gain = gain + gaininc;;
kount = kount + 1;;
end
plot(a,b,'go',c,d,'r+',e,f,'b*')
print -deps cf7982.eps
For eachvalue ofK,the program nds the roots of the closed loop system
for 50 <
<70. It then checks to nd the complex roots. MATLAB is not
consistentinthewayitassigns roots to the vectors, so you havetodothe
IF-test. The program is crude. Wecould get bywith one loop if wespent
some time on the code. My view is that it is not worth spending the time
improving the code. It runs in the blink of an eyeanyway.Fig.1isaplot
of the cost function for eachvalue of gain K.
3
50 52 54 56 58 60 62 64 66 68 70
0
0.05
0.1
0.15
0.2
0.25
0.3
0.35
0.4
Figure 1: Cost Functions for Three Gains
4