{ "cells": [ { "cell_type": "markdown", "id": "639f45ae-0ee8-426e-9d52-a7b9bb95d45a", "metadata": {}, "source": [ "# System Representation Gallery\n", "\n", "This Jupyter notebook creates different types of systems and generates a variety of representations (`__repr__`, `__str__`) for those systems that can be used to compare different versions of python-control. It is mainly intended for uses by developers to make sure there are no unexpected changes in representation formats, but also has some interesting examples of different choices in system representation." ] }, { "cell_type": "code", "execution_count": 1, "id": "c4b80abe-59e4-4d76-a81c-6979a583e82d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0.10.1.dev324+g2fd3802a.d20241218'" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import numpy as np\n", "\n", "import control as ct\n", "import control.flatsys as fs\n", "\n", "ct.__version__" ] }, { "cell_type": "markdown", "id": "035ebae9-7a4b-4079-8111-31f6c493c77c", "metadata": {}, "source": [ "## Text representations\n", "\n", "The code below shows what the output in various formats will look like in a terminal window." ] }, { "cell_type": "code", "execution_count": 2, "id": "eab8cc0b-3e8a-4df8-acbd-258f006f44bb", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================================\n", " Default repr\n", "============================================================================\n", "\n", "StateSpace: sys_ss, dt=0:\n", "-------------------------\n", "StateSpace(\n", "array([[ 0., 1.],\n", " [-4., -5.]]),\n", "array([[0.],\n", " [1.]]),\n", "array([[-1., 1.]]),\n", "array([[0.]]),\n", "name='sys_ss', states=2, outputs=1, inputs=1)\n", "----\n", "\n", "StateSpace: sys_dss, dt=0.1:\n", "----------------------------\n", "StateSpace(\n", "array([[ 0.98300988, 0.07817246],\n", " [-0.31268983, 0.59214759]]),\n", "array([[0.00424753],\n", " [0.07817246]]),\n", "array([[-1., 1.]]),\n", "array([[0.]]),\n", "dt=0.1,\n", "name='sys_dss', states=2, outputs=1, inputs=1)\n", "----\n", "\n", "StateSpace: stateless, dt=None:\n", "-------------------------------\n", "StateSpace(\n", "array([], shape=(0, 0), dtype=float64),\n", "array([], shape=(0, 2), dtype=float64),\n", "array([], shape=(2, 0), dtype=float64),\n", "array([[1., 0.],\n", " [0., 1.]]),\n", "dt=None,\n", "name='stateless', states=0, outputs=2, inputs=['u0', 'u1'])\n", "----\n", "\n", "TransferFunction: sys_ss$converted, dt=0:\n", "-----------------------------------------\n", "TransferFunction(\n", "array([ 1., -1.]),\n", "array([1., 5., 4.]),\n", "name='sys_ss$converted', outputs=1, inputs=1)\n", "----\n", "\n", "TransferFunction: sys_dss_poly, dt=0.1:\n", "---------------------------------------\n", "TransferFunction(\n", "array([ 0.07392493, -0.08176823]),\n", "array([ 1. , -1.57515746, 0.60653066]),\n", "dt=0.1,\n", "name='sys_dss_poly', outputs=1, inputs=1)\n", "----\n", "\n", "TransferFunction: sys[3], dt=0:\n", "-------------------------------\n", "TransferFunction(\n", "array([1]),\n", "array([1, 0]),\n", "outputs=1, inputs=1)\n", "----\n", "\n", "TransferFunction: sys_mtf_zpk, dt=0:\n", "------------------------------------\n", "TransferFunction(\n", "[[array([ 1., -1.]), array([0.])],\n", " [array([1, 0]), array([1, 0])]],\n", "[[array([1., 5., 4.]), array([1.])],\n", " [array([1]), array([1, 2, 1])]],\n", "name='sys_mtf_zpk', outputs=2, inputs=2)\n", "----\n", "\n", "FrequencyResponseData: sys_ss$converted$sampled, dt=0:\n", "------------------------------------------------------\n", "FrequencyResponseData(\n", "array([[[-0.24365959+0.05559644j, -0.19198193+0.1589174j ,\n", " 0.05882353+0.23529412j, 0.1958042 -0.01105691j,\n", " 0.0508706 -0.07767156j]]]),\n", "array([ 0.1 , 0.31622777, 1. , 3.16227766, 10. ]),\n", "name='sys_ss$converted$sampled', outputs=1, inputs=1)\n", "----\n", "\n", "FrequencyResponseData: sys_dss_poly$sampled, dt=0.1:\n", "----------------------------------------------------\n", "FrequencyResponseData(\n", "array([[[-0.24337799+0.05673083j, -0.18944184+0.16166381j,\n", " 0.07043649+0.23113479j, 0.19038528-0.04416494j,\n", " 0.00286505-0.09595906j]]]),\n", "array([ 0.1 , 0.31622777, 1. , 3.16227766, 10. ])\n", "dt=0.1,\n", "name='sys_dss_poly$sampled', outputs=1, inputs=1)\n", "----\n", "\n", "FrequencyResponseData: sys_mtf_zpk$sampled, dt=0:\n", "-------------------------------------------------\n", "FrequencyResponseData(\n", "array([[[-0.24365959 +0.05559644j, -0.19198193 +0.1589174j ,\n", " 0.05882353 +0.23529412j, 0.1958042 -0.01105691j,\n", " 0.0508706 -0.07767156j],\n", " [ 0. +0.j , 0. +0.j ,\n", " 0. +0.j , 0. +0.j ,\n", " 0. +0.j ]],\n", "\n", " [[ 0. +0.1j , 0. +0.31622777j,\n", " 0. +1.j , 0. +3.16227766j,\n", " 0. +10.j ],\n", " [ 0.01960592 +0.09704931j, 0.16528926 +0.23521074j,\n", " 0.5 +0.j , 0.16528926 -0.23521074j,\n", " 0.01960592 -0.09704931j]]]),\n", "array([ 0.1 , 0.31622777, 1. , 3.16227766, 10. ]),\n", "name='sys_mtf_zpk$sampled', outputs=2, inputs=2)\n", "----\n", "\n", "NonlinearIOSystem: sys_nl, dt=0:\n", "--------------------------------\n", " ['y[0]']>\n", "----\n", "\n", "NonlinearIOSystem: sys_dnl, dt=0.1:\n", "-----------------------------------\n", " ['y[0]'], dt=0.1>\n", "----\n", "\n", "InterconnectedSystem: sys_ic, dt=0:\n", "-----------------------------------\n", " ['y[0]', 'y[1]']>\n", "----\n", "\n", "LinearICSystem: sys_ic, dt=0:\n", "-----------------------------\n", " ['y[0]', 'y[1]']>\n", "----\n", "\n", "FlatSystem: sys_fs, dt=0:\n", "-------------------------\n", " ['y[0]']>\n", "----\n", "\n", "FlatSystem: sys_fsnl, dt=0:\n", "---------------------------\n", " ['y[0]']>\n", "----\n", "\n", "============================================================================\n", " Default str (print)\n", "============================================================================\n", "\n", "StateSpace: sys_ss, dt=0:\n", "-------------------------\n", ": sys_ss\n", "Inputs (1): ['u[0]']\n", "Outputs (1): ['y[0]']\n", "States (2): ['x[0]', 'x[1]']\n", "\n", "A = [[ 0. 1.]\n", " [-4. -5.]]\n", "\n", "B = [[0.]\n", " [1.]]\n", "\n", "C = [[-1. 1.]]\n", "\n", "D = [[0.]]\n", "----\n", "\n", "StateSpace: sys_dss, dt=0.1:\n", "----------------------------\n", ": sys_dss\n", "Inputs (1): ['u[0]']\n", "Outputs (1): ['y[0]']\n", "States (2): ['x[0]', 'x[1]']\n", "dt = 0.1\n", "\n", "A = [[ 0.98300988 0.07817246]\n", " [-0.31268983 0.59214759]]\n", "\n", "B = [[0.00424753]\n", " [0.07817246]]\n", "\n", "C = [[-1. 1.]]\n", "\n", "D = [[0.]]\n", "----\n", "\n", "StateSpace: stateless, dt=None:\n", "-------------------------------\n", ": stateless\n", "Inputs (2): ['u0', 'u1']\n", "Outputs (2): ['y[0]', 'y[1]']\n", "States (0): []\n", "dt = None\n", "\n", "A = []\n", "\n", "B = []\n", "\n", "C = []\n", "\n", "D = [[1. 0.]\n", " [0. 1.]]\n", "----\n", "\n", "TransferFunction: sys_ss$converted, dt=0:\n", "-----------------------------------------\n", ": sys_ss$converted\n", "Inputs (1): ['u[0]']\n", "Outputs (1): ['y[0]']\n", "\n", " s - 1\n", " -------------\n", " s^2 + 5 s + 4\n", "----\n", "\n", "TransferFunction: sys_dss_poly, dt=0.1:\n", "---------------------------------------\n", ": sys_dss_poly\n", "Inputs (1): ['u[0]']\n", "Outputs (1): ['y[0]']\n", "dt = 0.1\n", "\n", " 0.07392 z - 0.08177\n", " ----------------------\n", " z^2 - 1.575 z + 0.6065\n", "----\n", "\n", "TransferFunction: sys[3], dt=0:\n", "-------------------------------\n", ": sys[3]\n", "Inputs (1): ['u[0]']\n", "Outputs (1): ['y[0]']\n", "\n", " 1\n", " -\n", " s\n", "----\n", "\n", "TransferFunction: sys_mtf_zpk, dt=0:\n", "------------------------------------\n", ": sys_mtf_zpk\n", "Inputs (2): ['u[0]', 'u[1]']\n", "Outputs (2): ['y[0]', 'y[1]']\n", "\n", "Input 1 to output 1:\n", "\n", " s - 1\n", " ---------------\n", " (s + 1) (s + 4)\n", "\n", "Input 1 to output 2:\n", "\n", " s\n", " -\n", " 1\n", "\n", "Input 2 to output 1:\n", "\n", " 0\n", " -\n", " 1\n", "\n", "Input 2 to output 2:\n", "\n", " s\n", " ---------------\n", " (s + 1) (s + 1)\n", "----\n", "\n", "FrequencyResponseData: sys_ss$converted$sampled, dt=0:\n", "------------------------------------------------------\n", ": sys_ss$converted$sampled\n", "Inputs (1): ['u[0]']\n", "Outputs (1): ['y[0]']\n", "\n", "Freq [rad/s] Response\n", "------------ ---------------------\n", " 0.100 -0.2437 +0.0556j\n", " 0.316 -0.192 +0.1589j\n", " 1.000 0.05882 +0.2353j\n", " 3.162 0.1958 -0.01106j\n", " 10.000 0.05087 -0.07767j\n", "----\n", "\n", "FrequencyResponseData: sys_dss_poly$sampled, dt=0.1:\n", "----------------------------------------------------\n", ": sys_dss_poly$sampled\n", "Inputs (1): ['u[0]']\n", "Outputs (1): ['y[0]']\n", "dt = 0.1\n", "\n", "Freq [rad/s] Response\n", "------------ ---------------------\n", " 0.100 -0.2434 +0.05673j\n", " 0.316 -0.1894 +0.1617j\n", " 1.000 0.07044 +0.2311j\n", " 3.162 0.1904 -0.04416j\n", " 10.000 0.002865 -0.09596j\n", "----\n", "\n", "FrequencyResponseData: sys_mtf_zpk$sampled, dt=0:\n", "-------------------------------------------------\n", ": sys_mtf_zpk$sampled\n", "Inputs (2): ['u[0]', 'u[1]']\n", "Outputs (2): ['y[0]', 'y[1]']\n", "\n", "Input 1 to output 1:\n", "\n", " Freq [rad/s] Response\n", " ------------ ---------------------\n", " 0.100 -0.2437 +0.0556j\n", " 0.316 -0.192 +0.1589j\n", " 1.000 0.05882 +0.2353j\n", " 3.162 0.1958 -0.01106j\n", " 10.000 0.05087 -0.07767j\n", "\n", "Input 1 to output 2:\n", "\n", " Freq [rad/s] Response\n", " ------------ ---------------------\n", " 0.100 0 +0.1j\n", " 0.316 0 +0.3162j\n", " 1.000 0 +1j\n", " 3.162 0 +3.162j\n", " 10.000 0 +10j\n", "\n", "Input 2 to output 1:\n", "\n", " Freq [rad/s] Response\n", " ------------ ---------------------\n", " 0.100 0 +0j\n", " 0.316 0 +0j\n", " 1.000 0 +0j\n", " 3.162 0 +0j\n", " 10.000 0 +0j\n", "\n", "Input 2 to output 2:\n", "\n", " Freq [rad/s] Response\n", " ------------ ---------------------\n", " 0.100 0.01961 +0.09705j\n", " 0.316 0.1653 +0.2352j\n", " 1.000 0.5 +0j\n", " 3.162 0.1653 -0.2352j\n", " 10.000 0.01961 -0.09705j\n", "----\n", "\n", "NonlinearIOSystem: sys_nl, dt=0:\n", "--------------------------------\n", ": sys_nl\n", "Inputs (1): ['u[0]']\n", "Outputs (1): ['y[0]']\n", "States (2): ['x[0]', 'x[1]']\n", "Parameters: ['a', 'b']\n", "\n", "Update: \n", "Output: \n", "----\n", "\n", "NonlinearIOSystem: sys_dnl, dt=0.1:\n", "-----------------------------------\n", ": sys_dnl\n", "Inputs (1): ['u[0]']\n", "Outputs (1): ['y[0]']\n", "States (2): ['x[0]', 'x[1]']\n", "dt = 0.1\n", "\n", "Update: \n", "Output: \n", "----\n", "\n", "InterconnectedSystem: sys_ic, dt=0:\n", "-----------------------------------\n", ": sys_ic\n", "Inputs (2): ['r[0]', 'r[1]']\n", "Outputs (2): ['y[0]', 'y[1]']\n", "States (2): ['proc_nl_x[0]', 'proc_nl_x[1]']\n", "\n", "Subsystems (2):\n", " * ['y[0]', 'y[1]']>\n", " * ['y[0]', 'y[1]']>\n", "\n", "Connections:\n", " * proc_nl.u[0] <- ctrl_nl.y[0]\n", " * proc_nl.u[1] <- ctrl_nl.y[1]\n", " * ctrl_nl.u[0] <- -proc_nl.y[0] + r[0]\n", " * ctrl_nl.u[1] <- -proc_nl.y[1] + r[1]\n", "\n", "Outputs:\n", " * y[0] <- proc_nl.y[0]\n", " * y[1] <- proc_nl.y[1]\n", "----\n", "\n", "LinearICSystem: sys_ic, dt=0:\n", "-----------------------------\n", ": sys_ic\n", "Inputs (2): ['r[0]', 'r[1]']\n", "Outputs (2): ['y[0]', 'y[1]']\n", "States (2): ['proc_x[0]', 'proc_x[1]']\n", "\n", "Subsystems (2):\n", " * ['y[0]', 'y[1]']>\n", " * ['y[0]', 'y[1]'], dt=None>\n", "\n", "Connections:\n", " * proc.u[0] <- ctrl.y[0]\n", " * proc.u[1] <- ctrl.y[1]\n", " * ctrl.u[0] <- -proc.y[0] + r[0]\n", " * ctrl.u[1] <- -proc.y[1] + r[1]\n", "\n", "Outputs:\n", " * y[0] <- proc.y[0]\n", " * y[1] <- proc.y[1]\n", "\n", "A = [[-2. 3.]\n", " [-1. -5.]]\n", "\n", "B = [[-2. 0.]\n", " [ 0. -3.]]\n", "\n", "C = [[-1. 1.]\n", " [ 1. 0.]]\n", "\n", "D = [[0. 0.]\n", " [0. 0.]]\n", "----\n", "\n", "FlatSystem: sys_fs, dt=0:\n", "-------------------------\n", ": sys_fs\n", "Inputs (1): ['u[0]']\n", "Outputs (1): ['y[0]']\n", "States (2): ['x[0]', 'x[1]']\n", "\n", "Update: ['y[0]']>>\n", "Output: ['y[0]']>>\n", "\n", "Forward: \n", "Reverse: \n", "----\n", "\n", "FlatSystem: sys_fsnl, dt=0:\n", "---------------------------\n", ": sys_fsnl\n", "Inputs (1): ['u[0]']\n", "Outputs (1): ['y[0]']\n", "States (2): ['x[0]', 'x[1]']\n", "\n", "Update: \n", "Output: \n", "\n", "Forward: \n", "Reverse: \n", "----\n", "\n", "============================================================================\n", " repr_format='info'\n", "============================================================================\n", "\n", "StateSpace: sys_ss, dt=0:\n", "-------------------------\n", " ['y[0]']>\n", "----\n", "\n", "StateSpace: sys_dss, dt=0.1:\n", "----------------------------\n", " ['y[0]'], dt=0.1>\n", "----\n", "\n", "StateSpace: stateless, dt=None:\n", "-------------------------------\n", " ['y[0]', 'y[1]'], dt=None>\n", "----\n", "\n", "TransferFunction: sys_ss$converted, dt=0:\n", "-----------------------------------------\n", " ['y[0]']>\n", "----\n", "\n", "TransferFunction: sys_dss_poly, dt=0.1:\n", "---------------------------------------\n", " ['y[0]'], dt=0.1>\n", "----\n", "\n", "TransferFunction: sys[3], dt=0:\n", "-------------------------------\n", " ['y[0]']>\n", "----\n", "\n", "TransferFunction: sys_mtf_zpk, dt=0:\n", "------------------------------------\n", " ['y[0]', 'y[1]']>\n", "----\n", "\n", "FrequencyResponseData: sys_ss$converted$sampled, dt=0:\n", "------------------------------------------------------\n", " ['y[0]']>\n", "----\n", "\n", "FrequencyResponseData: sys_dss_poly$sampled, dt=0.1:\n", "----------------------------------------------------\n", " ['y[0]'], dt=0.1>\n", "----\n", "\n", "FrequencyResponseData: sys_mtf_zpk$sampled, dt=0:\n", "-------------------------------------------------\n", " ['y[0]', 'y[1]']>\n", "----\n", "\n", "NonlinearIOSystem: sys_nl, dt=0:\n", "--------------------------------\n", " ['y[0]']>\n", "----\n", "\n", "NonlinearIOSystem: sys_dnl, dt=0.1:\n", "-----------------------------------\n", " ['y[0]'], dt=0.1>\n", "----\n", "\n", "InterconnectedSystem: sys_ic, dt=0:\n", "-----------------------------------\n", " ['y[0]', 'y[1]']>\n", "----\n", "\n", "LinearICSystem: sys_ic, dt=0:\n", "-----------------------------\n", " ['y[0]', 'y[1]']>\n", "----\n", "\n", "FlatSystem: sys_fs, dt=0:\n", "-------------------------\n", " ['y[0]']>\n", "----\n", "\n", "FlatSystem: sys_fsnl, dt=0:\n", "---------------------------\n", " ['y[0]']>\n", "----\n", "\n", "============================================================================\n", " iosys.repr_show_count=False\n", "============================================================================\n", "\n", "StateSpace: sys_ss, dt=0:\n", "-------------------------\n", "StateSpace(\n", "array([[ 0., 1.],\n", " [-4., -5.]]),\n", "array([[0.],\n", " [1.]]),\n", "array([[-1., 1.]]),\n", "array([[0.]]),\n", "name='sys_ss')\n", "----\n", "\n", "StateSpace: sys_dss, dt=0.1:\n", "----------------------------\n", "StateSpace(\n", "array([[ 0.98300988, 0.07817246],\n", " [-0.31268983, 0.59214759]]),\n", "array([[0.00424753],\n", " [0.07817246]]),\n", "array([[-1., 1.]]),\n", "array([[0.]]),\n", "dt=0.1,\n", "name='sys_dss')\n", "----\n", "\n", "StateSpace: stateless, dt=None:\n", "-------------------------------\n", "StateSpace(\n", "array([], shape=(0, 0), dtype=float64),\n", "array([], shape=(0, 2), dtype=float64),\n", "array([], shape=(2, 0), dtype=float64),\n", "array([[1., 0.],\n", " [0., 1.]]),\n", "dt=None,\n", "name='stateless', inputs=['u0', 'u1'])\n", "----\n", "\n", "LinearICSystem: sys_ic, dt=0:\n", "-----------------------------\n", " ['y[0]', 'y[1]']>\n", "----\n", "\n", "============================================================================\n", " xferfcn.display_format=zpk, str (print)\n", "============================================================================\n", "\n", "TransferFunction: sys_ss$converted, dt=0:\n", "-----------------------------------------\n", ": sys_ss$converted\n", "Inputs (1): ['u[0]']\n", "Outputs (1): ['y[0]']\n", "\n", " s - 1\n", " ---------------\n", " (s + 1) (s + 4)\n", "----\n", "\n", "TransferFunction: sys_dss_poly, dt=0.1:\n", "---------------------------------------\n", ": sys_dss_poly\n", "Inputs (1): ['u[0]']\n", "Outputs (1): ['y[0]']\n", "dt = 0.1\n", "\n", " 0.07392 z - 0.08177\n", " ----------------------\n", " z^2 - 1.575 z + 0.6065\n", "----\n", "\n", "TransferFunction: sys[3], dt=0:\n", "-------------------------------\n", ": sys[3]\n", "Inputs (1): ['u[0]']\n", "Outputs (1): ['y[0]']\n", "\n", " 1\n", " -\n", " s\n", "----\n", "\n", "TransferFunction: sys_mtf_zpk, dt=0:\n", "------------------------------------\n", ": sys_mtf_zpk\n", "Inputs (2): ['u[0]', 'u[1]']\n", "Outputs (2): ['y[0]', 'y[1]']\n", "\n", "Input 1 to output 1:\n", "\n", " s - 1\n", " ---------------\n", " (s + 1) (s + 4)\n", "\n", "Input 1 to output 2:\n", "\n", " s\n", " -\n", " 1\n", "\n", "Input 2 to output 1:\n", "\n", " 0\n", " -\n", " 1\n", "\n", "Input 2 to output 2:\n", "\n", " s\n", " ---------------\n", " (s + 1) (s + 1)\n", "----\n", "\n" ] } ], "source": [ "# Grab system definitions (and generate various representations as text)\n", "from repr_gallery import *" ] }, { "cell_type": "markdown", "id": "19f146a3-c036-4ff6-8425-c201fba14ec7", "metadata": {}, "source": [ "## Jupyter notebook (HTML/LaTeX) representations\n", "\n", "The following representations are generated using the `_html_repr_` method in selected types of systems. Only those systems that have unique displays are shown." ] }, { "cell_type": "markdown", "id": "16ff8d11-e793-456a-bf27-ae4cc0dd1e3b", "metadata": {}, "source": [ "### Continuous time state space systems" ] }, { "cell_type": "code", "execution_count": 3, "id": "c1ca661d-10f3-45be-8619-c3e143bb4b4c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "<StateSpace sys_ss: ['u[0]'] -> ['y[0]']>\n", "$$\n", "\\left[\\begin{array}{rllrll|rll}\n", "0\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&1\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&0\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "-4\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&-5\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&1\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "\\hline\n", "-1\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&1\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&0\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "\\end{array}\\right]\n", "$$" ], "text/plain": [ "StateSpace(\n", "array([[ 0., 1.],\n", " [-4., -5.]]),\n", "array([[0.],\n", " [1.]]),\n", "array([[-1., 1.]]),\n", "array([[0.]]),\n", "name='sys_ss', states=2, outputs=1, inputs=1)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sys_ss" ] }, { "cell_type": "code", "execution_count": 4, "id": "b10b4db3-a8c0-4a2c-a19d-a09fef3dc25f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "<StateSpace sys_ss: ['u[0]'] -> ['y[0]']>\n", "$$\n", "\\begin{array}{ll}\n", "A = \\left[\\begin{array}{rllrll}\n", "0\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&1\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "-4\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&-5\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "\\end{array}\\right]\n", "&\n", "B = \\left[\\begin{array}{rll}\n", "0\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "1\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "\\end{array}\\right]\n", "\\\\\n", "C = \\left[\\begin{array}{rllrll}\n", "-1\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&1\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "\\end{array}\\right]\n", "&\n", "D = \\left[\\begin{array}{rll}\n", "0\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "\\end{array}\\right]\n", "\\end{array}\n", "$$" ], "text/plain": [ "StateSpace(\n", "array([[ 0., 1.],\n", " [-4., -5.]]),\n", "array([[0.],\n", " [1.]]),\n", "array([[-1., 1.]]),\n", "array([[0.]]),\n", "name='sys_ss', states=2, outputs=1, inputs=1)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "with ct.config.defaults({'statesp.latex_repr_type': 'separate'}):\n", " display(sys_ss)" ] }, { "cell_type": "code", "execution_count": 5, "id": "0537f6fe-a155-4c49-be7c-413608a03887", "metadata": {}, "outputs": [ { "data": { "text/html": [ "<StateSpace sys_ss: ['u[0]'] -> ['y[0]']>\n", "$$\n", "\\begin{array}{ll}\n", "A = \\left[\\begin{array}{rllrll}\n", " 0.&\\hspace{-1em}0000&\\hspace{-1em}\\phantom{\\cdot}& 1.&\\hspace{-1em}0000&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", " -4.&\\hspace{-1em}0000&\\hspace{-1em}\\phantom{\\cdot}& -5.&\\hspace{-1em}0000&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "\\end{array}\\right]\n", "&\n", "B = \\left[\\begin{array}{rll}\n", " 0.&\\hspace{-1em}0000&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", " 1.&\\hspace{-1em}0000&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "\\end{array}\\right]\n", "\\\\\n", "C = \\left[\\begin{array}{rllrll}\n", " -1.&\\hspace{-1em}0000&\\hspace{-1em}\\phantom{\\cdot}& 1.&\\hspace{-1em}0000&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "\\end{array}\\right]\n", "&\n", "D = \\left[\\begin{array}{rll}\n", " 0.&\\hspace{-1em}0000&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "\\end{array}\\right]\n", "\\end{array}\n", "$$" ], "text/plain": [ "StateSpace(\n", "array([[ 0., 1.],\n", " [-4., -5.]]),\n", "array([[0.],\n", " [1.]]),\n", "array([[-1., 1.]]),\n", "array([[0.]]),\n", "name='sys_ss', states=2, outputs=1, inputs=1)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "with ct.config.defaults({\n", " 'statesp.latex_repr_type': 'separate',\n", " 'statesp.latex_num_format': '8.4f'}):\n", " display(sys_ss)" ] }, { "cell_type": "markdown", "id": "fa75f040-633d-401c-ba96-e688713d5a2d", "metadata": {}, "source": [ "### Stateless state space system" ] }, { "cell_type": "code", "execution_count": 6, "id": "5a71e38c-9880-4af7-82e0-49f074653e94", "metadata": {}, "outputs": [ { "data": { "text/html": [ "<StateSpace stateless: ['u0', 'u1'] -> ['y[0]', 'y[1]'], dt=None>\n", "$$\n", "\\left[\\begin{array}{rllrll}\n", "1\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&0\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "0\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&1\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "\\end{array}\\right]\n", "$$" ], "text/plain": [ "StateSpace(\n", "array([], shape=(0, 0), dtype=float64),\n", "array([], shape=(0, 2), dtype=float64),\n", "array([], shape=(2, 0), dtype=float64),\n", "array([[1., 0.],\n", " [0., 1.]]),\n", "dt=None,\n", "name='stateless', states=0, outputs=2, inputs=['u0', 'u1'])" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sys_ss0" ] }, { "cell_type": "code", "execution_count": 7, "id": "7ddbd638-9338-4204-99bc-792f35e14874", "metadata": {}, "outputs": [ { "data": { "text/html": [ "<StateSpace stateless: ['u0', 'u1'] -> ['y[0]', 'y[1]'], dt=None>\n", "$$\n", "\\begin{array}{ll}\n", "D = \\left[\\begin{array}{rllrll}\n", "1\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&0\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "0\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&1\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "\\end{array}\\right]\n", "\\end{array}\n", "$$" ], "text/plain": [ "StateSpace(\n", "array([], shape=(0, 0), dtype=float64),\n", "array([], shape=(0, 2), dtype=float64),\n", "array([], shape=(2, 0), dtype=float64),\n", "array([[1., 0.],\n", " [0., 1.]]),\n", "dt=None,\n", "name='stateless', states=0, outputs=2, inputs=['u0', 'u1'])" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "with ct.config.defaults({'statesp.latex_repr_type': 'separate'}):\n", " display(sys_ss0)" ] }, { "cell_type": "markdown", "id": "06c5d470-0768-4628-b2ea-d2387525ed80", "metadata": {}, "source": [ "### Discrete time state space system" ] }, { "cell_type": "code", "execution_count": 8, "id": "e7b9b438-28e3-453e-9860-06ff75b7af10", "metadata": {}, "outputs": [ { "data": { "text/html": [ "<StateSpace sys_dss: ['u[0]'] -> ['y[0]'], dt=0.1>\n", "$$\n", "\\left[\\begin{array}{rllrll|rll}\n", "0.&\\hspace{-1em}983&\\hspace{-1em}\\phantom{\\cdot}&0.&\\hspace{-1em}0782&\\hspace{-1em}\\phantom{\\cdot}&0.&\\hspace{-1em}00425&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "-0.&\\hspace{-1em}313&\\hspace{-1em}\\phantom{\\cdot}&0.&\\hspace{-1em}592&\\hspace{-1em}\\phantom{\\cdot}&0.&\\hspace{-1em}0782&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "\\hline\n", "-1\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&1\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&0\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "\\end{array}\\right]\n", "$$" ], "text/plain": [ "StateSpace(\n", "array([[ 0.98300988, 0.07817246],\n", " [-0.31268983, 0.59214759]]),\n", "array([[0.00424753],\n", " [0.07817246]]),\n", "array([[-1., 1.]]),\n", "array([[0.]]),\n", "dt=0.1,\n", "name='sys_dss', states=2, outputs=1, inputs=1)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sys_dss" ] }, { "cell_type": "markdown", "id": "7719e725-9d38-4f2a-a142-0ebc090e74e4", "metadata": {}, "source": [ "### \"Stateless\" state space system" ] }, { "cell_type": "code", "execution_count": 9, "id": "938fd795-f402-4491-b2c9-eb42c458e1e1", "metadata": {}, "outputs": [ { "data": { "text/html": [ "<StateSpace stateless: ['u0', 'u1'] -> ['y[0]', 'y[1]'], dt=None>\n", "$$\n", "\\left[\\begin{array}{rllrll}\n", "1\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&0\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "0\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&1\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "\\end{array}\\right]\n", "$$" ], "text/plain": [ "StateSpace(\n", "array([], shape=(0, 0), dtype=float64),\n", "array([], shape=(0, 2), dtype=float64),\n", "array([], shape=(2, 0), dtype=float64),\n", "array([[1., 0.],\n", " [0., 1.]]),\n", "dt=None,\n", "name='stateless', states=0, outputs=2, inputs=['u0', 'u1'])" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sys_ss0" ] }, { "cell_type": "markdown", "id": "c620f1a1-40ff-4320-9f62-21bff9ab308e", "metadata": {}, "source": [ "### Continuous time transfer function" ] }, { "cell_type": "code", "execution_count": 10, "id": "e364e6eb-0cfa-486a-8b95-ff9c6c41a091", "metadata": {}, "outputs": [ { "data": { "text/html": [ "<TransferFunction sys_ss\\$converted: ['u[0]'] -> ['y[0]']>\n", "$$\\dfrac{s - 1}{s^2 + 5 s + 4}$$" ], "text/plain": [ "TransferFunction(\n", "array([ 1., -1.]),\n", "array([1., 5., 4.]),\n", "name='sys_ss$converted', outputs=1, inputs=1)" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sys_tf" ] }, { "cell_type": "code", "execution_count": 11, "id": "af9959fd-90eb-4287-93ee-416cd13fde50", "metadata": {}, "outputs": [ { "data": { "text/html": [ "<TransferFunction sys_ss\\$converted: ['u[0]'] -> ['y[0]']>\n", "$$\\dfrac{s - 1}{(s + 1) (s + 4)}$$" ], "text/plain": [ "TransferFunction(\n", "array([ 1., -1.]),\n", "array([1., 5., 4.]),\n", "name='sys_ss$converted', outputs=1, inputs=1)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "with ct.config.defaults({'xferfcn.display_format': 'zpk'}):\n", " display(sys_tf)" ] }, { "cell_type": "markdown", "id": "7bf40707-f84c-4e19-b310-5ec9811faf42", "metadata": {}, "source": [ "### MIMO transfer function" ] }, { "cell_type": "code", "execution_count": 12, "id": "b2db2d1c-893b-43a1-aab0-a5f6d059f3f9", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/murray/miniconda3/envs/python3.13-slycot/lib/python3.13/site-packages/scipy/signal/_filter_design.py:1112: BadCoefficients: Badly conditioned filter coefficients (numerator): the results may be meaningless\n", " b, a = normalize(b, a)\n", "/Users/murray/miniconda3/envs/python3.13-slycot/lib/python3.13/site-packages/scipy/signal/_filter_design.py:1116: RuntimeWarning: invalid value encountered in divide\n", " b /= b[0]\n" ] }, { "data": { "text/html": [ "<TransferFunction sys_mtf_zpk: ['u[0]', 'u[1]'] -> ['y[0]', 'y[1]']>\n", "$$\\begin{bmatrix}\\dfrac{s - 1}{(s + 1) (s + 4)}&\\dfrac{0}{1}\\\\\\dfrac{s}{1}&\\dfrac{s}{(s + 1) (s + 1)}\\\\ \\end{bmatrix}$$" ], "text/plain": [ "TransferFunction(\n", "[[array([ 1., -1.]), array([0.])],\n", " [array([1, 0]), array([1, 0])]],\n", "[[array([1., 5., 4.]), array([1.])],\n", " [array([1]), array([1, 2, 1])]],\n", "name='sys_mtf_zpk', outputs=2, inputs=2)" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sys_mtf # SciPy generates a warning due to 0 numerator in 1, 2 entry" ] }, { "cell_type": "markdown", "id": "ef78a05e-9a63-4e22-afae-66ac8ec457c2", "metadata": {}, "source": [ "### Discrete time transfer function" ] }, { "cell_type": "code", "execution_count": 13, "id": "365c9b4a-2af3-42e5-ae5d-f2d7d989104b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "<TransferFunction sys_dss_poly: ['u[0]'] -> ['y[0]'], dt=0.1>\n", "$$\\dfrac{0.07392 z - 0.08177}{z^2 - 1.575 z + 0.6065}$$" ], "text/plain": [ "TransferFunction(\n", "array([ 0.07392493, -0.08176823]),\n", "array([ 1. , -1.57515746, 0.60653066]),\n", "dt=0.1,\n", "name='sys_dss_poly', outputs=1, inputs=1)" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sys_dtf" ] }, { "cell_type": "markdown", "id": "b49fa8ab-c3af-48d1-b160-790c9f4d3c6e", "metadata": {}, "source": [ "### Linear interconnected system" ] }, { "cell_type": "code", "execution_count": 14, "id": "78d21969-4615-4a47-b449-7a08138dc319", "metadata": {}, "outputs": [ { "data": { "text/html": [ "<LinearICSystem sys_ic: ['r[0]', 'r[1]'] -> ['y[0]', 'y[1]']>\n", "$$\n", "\\left[\\begin{array}{rllrll|rllrll}\n", "-2\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&3\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&-2\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&0\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "-1\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&-5\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&0\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&-3\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "\\hline\n", "-1\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&1\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&0\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&0\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "1\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&0\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&0\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}&0\\phantom{.}&\\hspace{-1em}&\\hspace{-1em}\\phantom{\\cdot}\\\\\n", "\\end{array}\\right]\n", "$$" ], "text/plain": [ " ['y[0]', 'y[1]']>" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sys_lic" ] }, { "cell_type": "markdown", "id": "bee65cd5-d9b5-46af-aee5-26a6a4679939", "metadata": {}, "source": [ "### Non-HTML capable system representations" ] }, { "cell_type": "code", "execution_count": 15, "id": "e5486349-2bd3-4015-ad17-a5b8e8ec0447", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "FrequencyResponseData(\n", "array([[[-0.24365959+0.05559644j, -0.19198193+0.1589174j ,\n", " 0.05882353+0.23529412j, 0.1958042 -0.01105691j,\n", " 0.0508706 -0.07767156j]]]),\n", "array([ 0.1 , 0.31622777, 1. , 3.16227766, 10. ]),\n", "name='sys_ss$converted$sampled', outputs=1, inputs=1)" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ " ['y[0]']>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ " ['y[0]', 'y[1]']>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ " ['y[0]']>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "for sys in [sys_frd, sys_nl, sys_ic, sys_fs]:\n", " display(sys)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.1" } }, "nbformat": 4, "nbformat_minor": 5 }