from __future__ import print_function
import numpy as np

from utils import poles, zeros, tf, mimotf

s = tf([1, 0], [1])
G = 1 / (s + 2) * mimotf([[s - 1, 4], [4.5, 2 * (s - 1)]])
print('Poles: ', poles(G))
print('Zeros: ', zeros(G))
import utils
import utilsplot
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

mpl.rcParams['figure.facecolor'] = 'white'


s = utils.tf([1, 0], 1)
A = np.asarray([[-10, 0], [0, -1]])
B = np.eye(A.shape[0])
C = np.asarray([[10., 1.1], [10., 0]])
D = np.asarray([[0., 0.], [0., 1.]])

G = utils.mimotf(C*utils.mimotf(s*np.eye(2) - A).inverse()*B + D)

# a) Controllability analysis

G_poles = G.poles()
G_rhp_poles = utils.RHPonly(G_poles)
# G has stable poles, -10 with multiplicity of 2 and -1
G_zeros = G.zeros()
G_rhp_zeros = utils.RHPonly(G_zeros)
# G has a LHP zero @ -10 and a RHP zero @ 0.1
# Zero at 0.1 limits bandwidth to wB* < 0.05

pairing1 = np.asmatrix(np.eye(2))
pairing2 = np.asmatrix(pairing1[[1, 0]])

utilsplot.rga_nm_plot(G, pairing_list=[pairing1, pairing2], 
Example #3
0
from __future__ import print_function
import numpy as np

from utils import pole_zero_directions, BoundST, tf, mimotf, RHPonly
from reporting import display_export_data

s = tf([1, 0])

p = 3
z = 2
d = 30. / 180. * np.pi
g1 = mimotf([[1 / (s - p), 0], [0, 1 / (s + 3)]])
g2 = mimotf([[np.cos(d), -np.sin(d)], [np.sin(d), np.cos(d)]])
g3 = mimotf([[(s - z) / (0.1 * s + 1), 0], [0, (s + 2) / (0.1 * s + 1)]])
G = g1 * g2 * g3

p = G.poles()
z = G.zeros()
print('All Poles: {0}'.format(p))
print('All Zeros: {0}\n'.format(z))

RHPzeros = RHPonly(z)
RHPpoles = RHPonly(p)
print("RHP poles only: ", RHPpoles)
print("RHP zeros only: ", RHPzeros)

# selected p & z
p = [3.]
z = [2.]

pdata = pole_zero_directions(G, p, 'p')
Example #4
0
import matplotlib.pyplot as plt

from utilsplot import mimo_bode, condtn_nm_plot
from utils import tf, mimotf

s= tf([1, 0])

s1 = 1 / (75 * s + 1)
G1 = mimotf([[s1 * 87.8, s1 * -86.4], 
             [s1 * 108.2, s1 * -109.6]])

s2 = 1/(s**2 + 10**2)
G2 = mimotf([[s2 * (s - 1e2), s2 * (10 * (s + 1))], 
             [s2 * (-10 * (s + 1)), s2 * (s - 1e2)]])

processes = [[G1, '(a) Distillation process', -4, 1],
             [G2, '(b) Spinning satellite', -2, 2]]

plt.figure('Figure 3.7')
for i, [G, title, minw, maxw] in enumerate(processes):
    plt.subplot(2, 2, i + 1)
    plt.title(title)
    mimo_bode(G, minw, maxw)
    
    #this is an additional plot to the textbook
    plt.subplot(2, 2, 3 + i)
    condtn_nm_plot(G, minw, maxw)

plt.show()
import matplotlib.pyplot as plt
import numpy as np
import sympy as sp

from utilsplot import dis_rejctn_plot, input_perfect_const_plot, input_acceptable_const_plot
from utils import distRHPZ, tf, mimotf

s = tf([1, 0])

G11 = (s - 1) / (s + 2)
G12 = 4 / (s + 2)
G21 = 4.5 / (s + 2)
G22 = 2 * (s - 1) / (s + 2)

G = mimotf([[G11, G12],
            [G21, G22]])
                                        
def Gdk(s, k):
    return 6 / (s + 2) * np.matrix([[k],
                                    [1]])

def Gd(s):
    k = 1
    return Gdk(s, k)   

def Gdz(s):
    k = sp.Symbol('k')
    return Gdk(s, k)  

z_vec = G.zeros()
for z in z_vec:
from __future__ import print_function

from utils import tf, mimotf

s = tf([1, 0], 1)
G = 1 / (1.25 * (s + 1) * (s + 2)) * mimotf([[s - 1, s], [-6, s - 2]])

print('Poles: ', G.poles())
# TODO: Incorrect result. G has no zeros
print('Zeros: ', G.zeros())
from utils import pole_zero_directions, tf, mimotf
from reporting import display_export_data

s = tf([1, 0])

G = 1/(s + 2)*mimotf([[s - 1, 4],
                      [4.5, 2*(s - 1)]])

# Poles and zeros calculated in Example 4.11

zerodata = pole_zero_directions(G, [4.], 'z')
poledata = pole_zero_directions(G, [-2.], 'p')
rowhead = ['   u', '   y', '   e ']

display_export_data(zerodata, 'Zeros', rowhead)
display_export_data(poledata, 'Poles', rowhead)
from __future__ import print_function

from utils import tf, mimotf

s = tf([1, 0], 1)
G = 1/(1.25*(s + 1)*(s + 2)) * mimotf([[s - 1, s],
                                       [-6, s - 2]])

print('Poles: ', G.poles())
print('Zeros: ', G.zeros())
Example #9
0
"""

Test function checking dimensions of tf2ss

"""

import utils

s = utils.tf([1, 0], 1)

G = utils.mimotf([
    [0.66/(6.7*s + 1), -0.61/(8.64*s + 1), -0.0049/(9.06*s + 1)],
    [1.11/(3.25*s + 1), -2.36/(5.0*s + 1), -0.012/(7.09*s + 1)],
    [-34.68/(8.15*s + 1), 46.2/(10.9*s + 1), 0.87*(11.61*s + 1)/((3.89*s + 1)*(18.8*s + 1))]
    ])

A, B, C, D = utils.tf2ss(G)

Nstates = A.shape[0]
Ninputs = B.shape[1]
Noutputs = C.shape[0]

print(A.shape, B.shape)
print(C.shape, D.shape)

assert A.shape[0] == A.shape[1], "A must be square"
assert B.shape[0] == Nstates, "B must have the same number of rows as A"
assert C.shape[1] == Nstates, "C must have the same number or columns as A"
assert D.shape[0] == Ninputs, "D must have the same number of rows as C"
import matplotlib.pyplot as plt

from utilsplot import mimo_bode, condtn_nm_plot
from utils import tf, mimotf

s = tf([1, 0])

s1 = 1 / (75 * s + 1)
G1 = mimotf([[s1 * 87.8, s1 * -86.4], [s1 * 108.2, s1 * -109.6]])

s2 = 1 / (s**2 + 10**2)
G2 = mimotf([[s2 * (s - 1e2), s2 * (10 * (s + 1))],
             [s2 * (-10 * (s + 1)), s2 * (s - 1e2)]])

processes = [[G1, '(a) Distillation process', -4, 1],
             [G2, '(b) Spinning satellite', -2, 2]]

plt.figure('Figure 3.7')
for i, [G, title, minw, maxw] in enumerate(processes):
    plt.subplot(2, 2, i + 1)
    plt.title(title)
    mimo_bode(G, minw, maxw)

    #this is an additional plot to the textbook
    plt.subplot(2, 2, 3 + i)
    condtn_nm_plot(G, minw, maxw)

plt.show()
from __future__ import print_function
import sympy
import utils

s = utils.tf([1, 0], 1)
M = utils.mimotf([[(s - 1) * (s + 2), 0, (s - 1) ** 2],
                   [-(s + 1) * (s + 2), (s - 1) * (s + 1), (s - 1) * (s + 1)]])
G = 1/((s + 1)*(s + 2)*(s - 1)) * M
print("The poles of the system are = ", G.poles())
import numpy as np

from utils import pole_zero_directions, tf, mimotf, BoundKS, BoundST
from reporting import display_export_data

s = tf([1, 0], 1)

z = 2.5
p = 2

G = np.matrix([[(s - z)/(s - p), -(0.1*s + 1)/(s - p)],[(s - z)/(0.1*s + 1), 1]])
G = mimotf(G)

p_list = G.poles()
z_list = G.zeros()
print('Poles: {0}'.format(p_list))
print('Zeros: {0}\n'.format(z_list))

zerodata = pole_zero_directions(G, z_list, 'z')
poledata = pole_zero_directions(G, p_list, 'p')
rowhead = ['   u', '   y', '   e ']
display_export_data(zerodata, 'Zeros', rowhead)
display_export_data(poledata, 'Poles', rowhead)
up = poledata[0][1]

# Obtain stable plant
p = -2
Gs = np.matrix([[(s - z)/(s - p), -(0.1*s + 1)/(s - p)],[(s - z)/(0.1*s + 1), 1]])
Gs = mimotf(Gs)

#||KS||inf MSmin, MTmin using Utils functions
import numpy as np

from utils import pole_zero_directions, tf, mimotf, BoundKS, BoundST
from reporting import display_export_data

s = tf([1, 0], 1)

z = 2.5
p = 2

G = np.matrix([[(s - z) / (s - p), -(0.1 * s + 1) / (s - p)],
               [(s - z) / (0.1 * s + 1), 1]])
G = mimotf(G)

p_list = G.poles()
z_list = G.zeros()
print('Poles: {0}'.format(p_list))
print('Zeros: {0}\n'.format(z_list))

zerodata = pole_zero_directions(G, z_list, 'z')
poledata = pole_zero_directions(G, p_list, 'p')
rowhead = ['   u', '   y', '   e ']
display_export_data(zerodata, 'Zeros', rowhead)
display_export_data(poledata, 'Poles', rowhead)
up = poledata[0][1]

# Obtain stable plant
p = -2
Gs = np.matrix([[(s - z) / (s - p), -(0.1 * s + 1) / (s - p)],
                [(s - z) / (0.1 * s + 1), 1]])
Gs = mimotf(Gs)
from utils import tf, mimotf, poles, zeros
import numpy as np

s = tf([1,0],[1])
G = mimotf([[(11*s**3 - 18*s**2 - 70*s - 50)/(s*(s + 10)*(s + 1)*(s - 5)), (s + 2)/((s + 1)*(s - 5))],
            [5*(s + 2)/((s + 1)*(s - 5)), 5*(s + 2)/((s + 1)*(s - 5))]])

print("The poles of the system are:", set(np.round(G.poles(),3)))
import matplotlib.pyplot as plt
import numpy as np
import sympy as sp

from utilsplot import dis_rejctn_plot, input_perfect_const_plot, input_acceptable_const_plot
from utils import distRHPZ, tf, mimotf

s = tf([1, 0])

G11 = (s - 1) / (s + 2)
G12 = 4 / (s + 2)
G21 = 4.5 / (s + 2)
G22 = 2 * (s - 1) / (s + 2)

G = mimotf([[G11, G12], [G21, G22]])


def Gdk(s, k):
    return 6 / (s + 2) * np.matrix([[k], [1]])


def Gd(s):
    k = 1
    return Gdk(s, k)


def Gdz(s):
    k = sp.Symbol('k')
    return Gdk(s, k)

Example #16
0
from __future__ import print_function
import numpy as np

from utils import pole_zero_directions, BoundST, tf, mimotf, RHPonly
from reporting import display_export_data

s = tf([1, 0])

p = 3
z = 2
d = 30. / 180. * np.pi
g1 = mimotf([[1 / (s - p), 0],
             [0, 1 / (s + 3)]])
g2 = mimotf([[np.cos(d), -np.sin(d)],
             [np.sin(d), np.cos(d)]])
g3 = mimotf([[(s - z) / (0.1 * s + 1), 0],
             [0, (s + 2) / (0.1 * s + 1)]])
G = g1 * g2 * g3

p = G.poles()
z = G.zeros()
print('All Poles: {0}'.format(p))
print('All Zeros: {0}\n'.format(z))

RHPzeros = RHPonly(z)
RHPpoles = RHPonly(p)
print("RHP poles only: ", RHPpoles)
print("RHP zeros only: ", RHPzeros)

# selected p & z
p = [3.]
Example #17
0
import utils
import utilsplot
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

mpl.rcParams['figure.facecolor'] = 'white'

s = utils.tf([1, 0], 1)
A = np.asarray([[-10, 0], [0, -1]])
B = np.eye(A.shape[0])
C = np.asarray([[10., 1.1], [10., 0]])
D = np.asarray([[0., 0.], [0., 1.]])

G = utils.mimotf(C * utils.mimotf(s * np.eye(2) - A).inverse() * B + D)

# a) Controllability analysis

G_poles = G.poles()
G_rhp_poles = utils.RHPonly(G_poles)
# G has stable poles, -10 with multiplicity of 2 and -1
G_zeros = G.zeros()
G_rhp_zeros = utils.RHPonly(G_zeros)
# G has a LHP zero @ -10 and a RHP zero @ 0.1
# Zero at 0.1 limits bandwidth to wB* < 0.05

pairing1 = np.asmatrix(np.eye(2))
pairing2 = np.asmatrix(pairing1[[1, 0]])

utilsplot.rga_nm_plot(
Example #18
0
from __future__ import print_function
import sympy
import utils

s = sympy.Symbol('s')
M = sympy.Matrix([[(s - 1)*(s + 2), 0, (s - 1)**2],
                  [-(s + 1)*(s + 2), (s - 1)*(s + 1),  (s - 1)*(s + 1)]])
G = (1/((s + 1)*(s + 2)*(s - 1)))*M

poles = utils.poles(G)

print("The poles of the system are = ", poles)

s = utils.tf([1, 0], 1)
M = utils.mimotf([[(s - 1) * (s + 2), 0, (s - 1) ** 2],
                  [-(s + 1) * (s + 2), (s - 1) * (s + 1), (s - 1) * (s + 1)]])
G = 1/((s + 1)*(s + 2)*(s - 1)) * M
print("The poles of the system are = ", G.poles())