import numpy as np
import scipy as sp
import matplotlib.pyplot as plt
import control as ct
%matplotlib nbagg
# only needed when developing python-control
%load_ext autoreload
%autoreload 2
# Distillation column model as in Equation (3.81) of Multivariable Feedback Control, Skogestad and Postlethwaite, 2st Edition.
den = [75, 1]
G = ct.tf([[[87.8], [-86.4]],
[[108.2], [-109.6]]],
[[den, den],
[den, den]])
display(G)
sampleTime = 10
display('Nyquist frequency: {:.4f} Hz, {:.4f} rad/sec'.format(1./sampleTime /2., 2*np.pi*1./sampleTime /2.))
'Nyquist frequency: 0.0500 Hz, 0.3142 rad/sec'
# MIMO discretization not implemented yet...
Gd11 = ct.sample_system(G[0, 0], sampleTime, 'tustin')
Gd12 = ct.sample_system(G[0, 1], sampleTime, 'tustin')
Gd21 = ct.sample_system(G[1, 0], sampleTime, 'tustin')
Gd22 = ct.sample_system(G[1, 1], sampleTime, 'tustin')
Gd = ct.tf([[Gd11.num[0][0], Gd12.num[0][0]],
[Gd21.num[0][0], Gd22.num[0][0]]],
[[Gd11.den[0][0], Gd12.den[0][0]],
[Gd21.den[0][0], Gd22.den[0][0]]], dt=Gd11.dt)
Gd
omega = np.logspace(-4, 1, 1000)
plt.figure()
response = ct.freqplot.singular_values_response(G, omega)
sigma_ct, omega_ct = response
response.plot();
plt.figure()
response = ct.freqplot.singular_values_response(Gd, omega)
sigma_dt, omega_dt = response
response.plot();
plt.figure()
ct.freqplot.singular_values_plot([G, Gd], omega);
plt.figure()
ct.freqplot.singular_values_plot(G, omega);
ct.freqplot.singular_values_plot(Gd, omega);
G_dc = np.array([[87.8, -86.4],
[108.2, -109.6]])
U, S, V = np.linalg.svd(G_dc)
S, sigma_ct[:, 0]
(array([197.20868123, 1.39141948]), array([197.20313497, 1.39138034]))