CM1_IS Perturbetd linear cable mass problem of order 20 J. A. Burns and B.B. King, "A reduced bases approach to the design of low order feedback controllers for nonlinear continuous systems", ICAM Virginia Polytechnic Institute and State University, Blacksburg Note CM1_IS instable version of CM1, i.e. A of CM1 is redefined by A=A+dA, where dA=[0 | 0 0 | ds*eye0.5*nx] such that the system matrix A=A+dA is not Hurwitz! Max. real part of eigA > 0, sd=9.5825e-003
simulation.py
# This file was autogenerated from the template: simulation.py.template (2022-10-10 15:55:37).
import numpy as np
import system_model
from scipy.integrate import solve_ivp, odeint
from ackrep_core import ResultContainer
from ackrep_core.system_model_management import save_plot_in_dir
import matplotlib.pyplot as plt
import os
from ipydex import Container
# link to documentation with examples: https://ackrep-doc.readthedocs.io/en/latest/devdoc/contributing_data.html
def simulate():
"""
simulate the system model with scipy.integrate.solve_ivp
:return: result of solve_ivp, might contains input function
"""
model = system_model.Model()
rhs_xx_pp_symb = model.get_rhs_symbolic()
rhs = model.get_rhs_func()
# initial state values
xx0 = np.ones(model.sys_dim)
t_end = 10
tt = np.linspace(0, t_end, 1000)
simulation_data = solve_ivp(rhs, (0, t_end), xx0, t_eval=tt)
# using odeint for models with large state vectors
# res = odeint(rhs, y0=xx0, t=tt, tfirst=True)
# simulation_data = Container()
# simulation_data.y = res.transpose()
# simulation_data.t = tt
# postprocessing: calc output
ny = 2
C = model.get_parameter_value("C")
D21 = model.get_parameter_value("D21")
output = np.zeros((ny, len(tt)))
for i in range(len(tt)):
output[:,i] = np.matmul(C, simulation_data.y[:,i]) # + np.matmul(D21, w)
simulation_data.output = output
save_plot(simulation_data)
return simulation_data
def save_plot(simulation_data):
"""
plot your data and save the plot
access to data via: simulation_data.t array of time values
simulation_data.y array of data components
simulation_data.uu array of input values
:param simulation_data: simulation_data of system_model
:return: None
"""
for i in range(simulation_data.output.shape[0]):
plt.plot(simulation_data.t, simulation_data.output[i], label=f"$y_{i}$")
plt.legend()
plt.tight_layout()
save_plot_in_dir()
def evaluate_simulation(simulation_data):
"""
assert that the simulation results are as expected
:param simulation_data: simulation_data of system_model
:return:
"""
expected_final_state = np.array([-0.09258797, -0.4453579 , -0.83458234, -1.19684374, -1.53530647,
-1.83411814, -2.00664911, -1.92028664, -2.13055197, -2.32299367,
1.91594073, 1.02788281, -0.27194388, -0.92860243, 1.1394141 ,
3.3305619 , 2.23211939, 0.71366279, 2.89036968, -0.02735931])
rc = ResultContainer(score=1.0)
simulated_final_state = simulation_data.y[:, -1]
rc.final_state_errors = [
simulated_final_state[i] - expected_final_state[i] for i in np.arange(0, len(simulated_final_state))
]
rc.success = np.allclose(expected_final_state, simulated_final_state, rtol=0, atol=1e-2)
return rc
system_model.py
# This file was autogenerated from the template: system_model.py.template (2022-10-10 15:55:37).
import sympy as sp
import numpy as np
import symbtools as st
import importlib
import sys, os
#from ipydex import IPS, activate_ips_on_exception
from ackrep_core.system_model_management import GenericModel, import_parameters
# Import parameter_file
params = import_parameters()
#link to documentation with examples: https://ackrep-doc.readthedocs.io/en/latest/devdoc/contributing_data.html
class Model(GenericModel):
def initialize(self):
"""
this function is called by the constructor of GenericModel
:return: None
"""
# Define number of inputs -- MODEL DEPENDENT
self.u_dim = 1
# Set "sys_dim" to constant value, if system dimension is constant
self.sys_dim = 20
# check existence of params file
self.has_params = True
self.params = params
# ----------- SET DEFAULT INPUT FUNCTION ---------- #
def uu_default_func(self):
"""
define input function
:return:(function with 2 args - t, xx_nv) default input function
"""
def uu_rhs(t, xx_nv):
"""
sequence of numerical input values
:param t:(scalar or vector) time
:param xx_nv:(vector or array of vectors) numeric state vector
:return:(list) numeric inputs
"""
u = np.zeros(self.u_dim)
return u
return uu_rhs
# ----------- SYMBOLIC RHS FUNCTION ---------- #
def get_rhs_symbolic(self):
"""
define symbolic rhs function
:return: matrix of symbolic rhs-functions
"""
if self.dxx_dt_symb is not None:
return self.dxx_dt_symb
x = self.xx_symb
A, B, B1, C1, C, D11, D12, D21 = self.pp_symb # parameters
w = np.zeros(1) # noise
u = self.uu_symb # inputs
# define symbolic rhs functions
self.dxx_dt_symb = np.matmul(A,x) + np.matmul(B1,w) + np.matmul(B,u)
return self.dxx_dt_symb
parameters.py
# This file was autogenerated from the template: parameters.py.template (2022-10-10 15:55:37).
import sys
import os
import numpy as np
import sympy as sp
import tabulate as tab
#link to documentation with examples: https://ackrep-doc.readthedocs.io/en/latest/devdoc/contributing_data.html
# set model name
model_name = 'Perturbetd linear cable mass problem of order 20'
# ---------- create symbolic parameters
A = sp.MatrixSymbol('A', 20, 20)
B = sp.MatrixSymbol('B', 20, 1)
B1 = sp.MatrixSymbol('B1', 20, 1)
C1 = sp.MatrixSymbol('C1', 3, 20)
C = sp.MatrixSymbol('C', 2, 20)
D11 = sp.MatrixSymbol('D11', 3, 1)
D12 = sp.MatrixSymbol('D12', 3, 1)
D21 = sp.MatrixSymbol('D21', 2, 1)
pp_symb = [A, B, B1, C1, C, D11, D12, D21]
# ---------- create auxiliary symbolic parameters
# set numerical values of auxiliary parameters
# trailing "_nv" stands for "numerical value"
A_nv = sp.Matrix(np.array([[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 1.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 1.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
1.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 1.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 1.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
1.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 1.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 1.00000000e+00,
0.00000000e+00, 0.00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
1.00000000e+00, 0.00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 1.00000000e+00],
[-9.11542732e+01, 6.46170927e+01, -1.73140977e+01,
4.63929794e+00, -1.24309410e+00, 3.33078454e-01,
-8.92197157e-02, 2.38004092e-02, -5.98192102e-03,
1.01824175e-03, 5.02478634e-03, 3.23085464e-03,
-8.65704883e-04, 2.31964897e-04, -6.21547049e-05,
1.66539227e-05, -4.46098578e-06, 1.19002046e-06,
-2.99096051e-07, 5.09099661e-08],
[ 6.46170927e+01, -1.08468371e+02, 6.92563907e+01,
-1.85571918e+01, 4.97237639e+00, -1.33231381e+00,
3.56878863e-01, -9.52016367e-02, 2.39276841e-02,
-4.07296699e-03, 3.23085464e-03, 4.15908146e-03,
3.46281953e-03, -9.27859588e-04, 2.48618820e-04,
-6.66156907e-05, 1.78439431e-05, -4.76008183e-06,
1.19638420e-06, -2.03639865e-07],
[-1.73140977e+01, 6.92563907e+01, -1.09711465e+02,
6.95894691e+01, -1.86464115e+01, 4.99617680e+00,
-1.33829574e+00, 3.57006138e-01, -8.97288153e-02,
1.52736262e-02, -8.65704883e-04, 3.46281953e-03,
4.09692675e-03, 3.47947346e-03, -9.32320574e-04,
2.49808840e-04, -6.69147868e-05, 1.78503069e-05,
-4.48644077e-06, 7.63649492e-07],
[ 4.63929794e+00, -1.85571918e+01, 6.95894691e+01,
-1.09800685e+02, 6.96132695e+01, -1.86523934e+01,
4.99630408e+00, -1.33282291e+00, 3.34987577e-01,
-5.70215379e-02, 2.31964897e-04, -9.27859588e-04,
3.47947346e-03, 4.09246577e-03, 3.48066348e-03,
-9.32619670e-04, 2.49815204e-04, -6.66411457e-05,
1.67493789e-05, -2.85095810e-06],
[-1.24309410e+00, 4.97237639e+00, -1.86464115e+01,
6.96132695e+01, -1.09806667e+02, 6.96133968e+01,
-1.86469206e+01, 4.97428552e+00, -1.25022149e+00,
2.12812525e-01, -6.21547049e-05, 2.48618820e-04,
-9.32320574e-04, 3.48066348e-03, 4.09216667e-03,
3.48066984e-03, -9.32346029e-04, 2.48714276e-04,
-6.25110747e-05, 1.06401829e-05],
[ 3.33078454e-01, -1.33231381e+00, 4.99617680e+00,
-1.86523934e+01, 6.96133968e+01, -1.09801194e+02,
6.95913782e+01, -1.85643192e+01, 4.66589840e+00,
-7.94228563e-01, 1.66539227e-05, -6.66156907e-05,
2.49808840e-04, -9.32619670e-04, 3.48066984e-03,
4.09244031e-03, 3.47956891e-03, -9.28215958e-04,
2.33294920e-04, -3.97097736e-05],
[-8.92197157e-02, 3.56878863e-01, -1.33829574e+00,
4.99630408e+00, -1.86469206e+01, 6.95913782e+01,
-1.09718592e+02, 6.92829911e+01, -1.74133721e+01,
2.96410173e+00, -4.46098578e-06, 1.78439431e-05,
-6.69147868e-05, 2.49815204e-04, -9.32346029e-04,
3.47956891e-03, 4.09657038e-03, 3.46414956e-03,
-8.70668605e-04, 1.48198911e-04],
[ 2.38004092e-02, -9.52016367e-02, 3.57006138e-01,
-1.33282291e+00, 4.97428552e+00, -1.85643192e+01,
6.92829911e+01, -1.08567645e+02, 6.49875900e+01,
-1.10621783e+01, 1.19002046e-06, -4.76008183e-06,
1.78503069e-05, -6.66411457e-05, 2.48714276e-04,
-9.28215958e-04, 3.46414956e-03, 4.15411774e-03,
3.24937950e-03, -5.53085872e-04],
[-5.98192102e-03, 2.39276841e-02, -8.97288153e-02,
3.34987577e-01, -1.25022149e+00, 4.66589840e+00,
-1.74133721e+01, 6.49875900e+01, -9.25369879e+01,
4.12846117e+01, -2.99096051e-07, 1.19638420e-06,
-4.48644077e-06, 1.67493789e-05, -6.25110747e-05,
2.33294920e-04, -8.70668605e-04, 3.24937950e-03,
4.95565061e-03, 2.06414458e-03],
[ 1.27274915e-04, -5.09099661e-04, 1.90912373e-03,
-7.12739526e-03, 2.66004573e-02, -9.92744340e-02,
3.70497279e-01, -1.38271468e+00, 5.16036144e+00,
-4.07626833e+00, 6.36374577e-09, -2.54549831e-08,
9.54561865e-08, -3.56369763e-07, 1.33002287e-06,
-4.96372170e-06, 1.85248639e-05, -6.91357340e-05,
2.58018072e-04, 9.37900756e-03]]))
B_nv = sp.Matrix(np.array([[ 0.00000000e+00],
[ 0.00000000e+00],
[ 0.00000000e+00],
[ 0.00000000e+00],
[ 0.00000000e+00],
[ 0.00000000e+00],
[ 0.00000000e+00],
[ 0.00000000e+00],
[ 0.00000000e+00],
[ 0.00000000e+00],
[-6.36374577e-06],
[ 2.54549831e-05],
[-9.54561865e-05],
[ 3.56369763e-04],
[-1.33002287e-03],
[ 4.96372170e-03],
[-1.85248639e-02],
[ 6.91357340e-02],
[-2.58018072e-01],
[ 9.62936555e-01]]))
B1_nv = sp.Matrix(np.array([[ 0.00000000e+00],
[ 0.00000000e+00],
[ 0.00000000e+00],
[ 0.00000000e+00],
[ 0.00000000e+00],
[ 0.00000000e+00],
[ 0.00000000e+00],
[ 0.00000000e+00],
[ 0.00000000e+00],
[ 0.00000000e+00],
[-6.36374577e-06],
[ 2.54549831e-05],
[-9.54561865e-05],
[ 3.56369763e-04],
[-1.33002287e-03],
[ 4.96372170e-03],
[-1.85248639e-02],
[ 6.91357340e-02],
[-2.58018072e-01],
[ 9.62936555e-01]]))
C1_nv = sp.Matrix(np.array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 1.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0.]]))
C_nv = sp.Matrix(np.array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 1.]]))
D11_nv = sp.Matrix(np.array([[0.],
[0.],
[0.]]))
D12_nv = sp.Matrix(np.array([[0. ],
[0. ],
[1.22474487]]))
D21_nv = sp.Matrix(np.array([[0.],
[1.]]))
# ---------- create symbolic parameter functions
# parameter values can be constant/fixed values OR set in relation to other parameters (for example: a = 2*b)
# list of symbolic parameter functions
# tailing "_sf" stands for "symbolic parameter function"
pp_sf = [A_nv, B_nv, B1_nv, C1_nv, C_nv, D11_nv, D12_nv, D21_nv]
# ---------- list for substitution
# -- entries are tuples like: (independent symbolic parameter, numerical value)
pp_subs_list = []
# OPTONAL: Dictionary which defines how certain variables shall be written
# in the table - key: Symbolic Variable, Value: LaTeX Representation/Code
# useful for example for complex variables: {Z: r"\underline{Z}"}
latex_names = {}
# ---------- Define LaTeX table
# Define table header
# DON'T CHANGE FOLLOWING ENTRIES: "Symbol", "Value"
tabular_header = ["Symbol", "Value"]
# Define column text alignments
col_alignment = ["center", "left"]
# Define Entries of all columns before the Symbol-Column
# --- Entries need to be latex code
col_1 = []
# contains all lists of the columns before the "Symbol" Column
# --- Empty list, if there are no columns before the "Symbol" Column
start_columns_list = []
# Define Entries of the columns after the Value-Column
# --- Entries need to be latex code
col_4 = []
# contains all lists of columns after the FIX ENTRIES
# --- Empty list, if there are no columns after the "Value" column
end_columns_list = []