This function derives a linear time invariant difference equation system in state space form:
xd(Ts*(k+1)) = Ad * xd(Ts*k) + Bd * ud(Ts*k) yd(Ts*k) = Cd * xd(Ts*k) + Dd * ud(Ts*k) x_continuous(Ts*k) = xd(Ts*k) + B2 * ud(Ts*k)
from the matrices A, B, C, D of the corresponding continuous system
der(x(t)) = A * x(t) + B * u(t) y(t) = C * x(t) + D * u(t)
The function is similar to fromStateSpace but the inputs are restricted to the matrices, the sample time and the discretization method.
import dss=Modelica_LinearSystems2.DiscreteStateSpace; Real A[1,1] = [1]; Real B[1,1] = [1]; Real C[1,1] = [1]; Real D[1,1] = [0]; public DiscreteStateSpace dss; algorithm dss := dss.'constructor'.fromMatrices2(A, B, C, D); //or just: //dss := dss(A, B, C, D, Ts=0.1, method=Modelica_LinearSystems2.Types.Method.Trapezoidal); // dss.A = [1.1053], // dss.B = [0.11080], // dss.C = [1], // dss.D = [0.0526], // dss.Ts = 0.1, // dss.B2 = [0.0526], // dss.method = Modelica_LinearSystems2.Types.Method.Trapezoidal
encapsulated function fromMatrices2 import Modelica; import MatricesMSL = Modelica.Math.Matrices; import Modelica_LinearSystems2; import Modelica_LinearSystems2.Utilities.Types.Method; input Real A[:, size(A, 1)] "Matrix A of continuous state space system" annotation( Dialog(group = "der(x) = A*x + B*u; y = C*x + D*u")); input Real B[size(A, 1), :] "Matrix B of continuous state space system" annotation( Dialog(group = "der(x) = A*x + B*u; y = C*x + D*u")); input Real C[:, size(A, 1)] "Matrix C of continuous state space system" annotation( Dialog(group = "der(x) = A*x + B*u; y = C*x + D*u")); input Real D[size(C, 1), size(B, 2)] "Matrix D of continuous state space system" annotation( Dialog(group = "der(x) = A*x + B*u; y = C*x + D*u")); input Modelica.Units.SI.Time Ts "Sample time"; input Method method = Method.Trapezoidal "Discretization method"; output Modelica_LinearSystems2.DiscreteStateSpace dss(redeclare Real A[size(A, 1), size(A, 2)], redeclare Real B[size(B, 1), size(B, 2)], redeclare Real C[size(C, 1), size(C, 2)], redeclare Real D[size(D, 1), size(D, 2)], redeclare Real B2[size(B, 1), size(B, 2)]) "Discrete state space system"; end fromMatrices2;