{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Max-Plus Implicit and Explicit Linear System\n", "\n", "Just like the Scilab toolbox, a Max-Plus structure for Julia is proposed in order to manipulate implicit linear dynamical systems in the following form:\n", "\n", "$$\\left \\{ \\begin{array}{l}\n", "X(n) &= D X(n) \\oplus A X(n-1) \\oplus B U(n) \\\\\n", "Y(n) &= C X(n)\n", "\\end{array} \\right.$$\n", "\n", "With $x(0) = x_0$ known. The quintuplet $(A,B,C,D,x_0)$ is manipulated by the structure `MPSysLin`. The $\\otimes$ is implied for readability. This document follows the [introduction of the Julia toolbox for Max-Plus algebra](https://nbviewer.jupyter.org/github/Lecrapouille/MaxPlus.jl/blob/master/tutorial/core-fr.ipynb) and we will see how to manipulate this structure which will be used on a concrete problem in the [following document](https://nbviewer.jupyter.org/github/Lecrapouille/MaxPlus.jl/blob/master/tutorial/flowshop-fr.ipynb)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Prerequisites\n", "\n", "If not already, let's load the Max-Plus Toolbox. As a reminder, the previous document explains in more detail how to do this." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "scrolled": true }, "outputs": [], "source": [ "push!(LOAD_PATH, pwd())\n", "using MaxPlus, SparseArrays" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Still for function call concerns `Base.show` from a Jupyter document, we force the display in full mode:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "Base.show(io::IO, ::MIME\"text/latex\", x::MP) = show(io, MIME\"text/plain\", x)\n", "Base.show(io::IO, ::MIME\"text/latex\", A::MPAbstractVecOrMat) = show(io, MIME\"text/plain\", A)\n", "Base.show(io::IO, ::MIME\"text/latex\", S::MPSysLin) = show(io, MIME\"text/plain\", S)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Construction of an Implicit Max-Plus Linear System\n", "\n", "Let's create our first implicit Max-Plus linear system thanks to the constructors of the associated Julia structure `MPSysLin(A, B, C [,D, x0])` :\n", "\n", "$$S_1=\\left\\{\\begin{array}{lcl}\n", "x_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", "0 & . \\\\\n", ". & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " x_n \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "1 & 2 \\\\\n", "3 & 4 \\\\\n", "\\end{array}\n", "\\right]\n", " x_{n-1} \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "0 \\\\\n", "0 \\\\\n", "\\end{array}\n", "\\right]\n", " u_n\\\\y_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", "0 & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " x_n\\\\x_0 & = & \\left[\n", "\\begin{array}{*{20}c}\n", ". \\\\\n", ". \\\\\n", "\\end{array}\n", "\\right]\n", "\\end{array}\\right.$$\n", "\n", "The matrix $D$ and the vector $x_0$ are optional. If they are not given they will be automatically created and filled with $\\varepsilon$." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2×2 (max,+) sparse matrix with 2 stored entries:\n", " [1, 1] = 0\n", " [2, 2] = 0" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "speye(MP,2,2)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Implicit dynamic linear Max-Plus system:\n", " x(n) = D*x(n) + A*x(n-1) + B*u(n)\n", " y(n) = C*x(n)\n", " x(0) = x0\n", "\n", "with:\n", "D = 2×2 (max,+) dense matrix:\n", " 0 .\n", " . 0\n", "\n", "A = 2×2 (max,+) dense matrix:\n", " 1 2\n", " 3 4\n", "\n", "B = 2-element (max,+) vector:\n", " 0\n", " 0\n", "\n", "C = 1×2 (max,+) dense matrix:\n", " 0 0\n", "\n", "x0 = 2×1 (max,+) dense matrix:\n", " .\n", " .\n" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S1 = MPSysLin(MP([1 2; 3 4]), # A\n", " MP([0;0]), # B\n", " MP([0 0]), # C\n", " speye(MP,2,2), # D (optional)\n", " spzeros(MP,2,1)) # x0 (optional)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And the second implicit system:\n", "\n", "$$S_2=\\left\\{\\begin{array}{lcl}\n", "x_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", "0 & . & . \\\\\n", ". & 0 & . \\\\\n", ". & . & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " x_n \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "1 & 2 & 3 \\\\\n", "4 & 5 & 6 \\\\\n", "7 & 8 & 9 \\\\\n", "\\end{array}\n", "\\right]\n", " x_{n-1} \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "0 \\\\\n", "0 \\\\\n", "0 \\\\\n", "\\end{array}\n", "\\right]\n", " u_n\\\\y_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", "0 & 0 & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " x_n\\\\x_0 & = & \\left[\n", "\\begin{array}{*{20}c}\n", ". \\\\\n", ". \\\\\n", ". \\\\\n", "\\end{array}\n", "\\right]\n", "\\end{array}\\right.$$" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Implicit dynamic linear Max-Plus system:\n", " x(n) = D*x(n) + A*x(n-1) + B*u(n)\n", " y(n) = C*x(n)\n", " x(0) = x0\n", "\n", "with:\n", "D = 3×3 (max,+) dense matrix:\n", " 0 . .\n", " . 0 .\n", " . . 0\n", "\n", "A = 3×3 (max,+) dense matrix:\n", " 1 2 3\n", " 4 5 6\n", " 7 8 9\n", "\n", "B = 3-element (max,+) vector:\n", " 0\n", " 0\n", " 0\n", "\n", "C = 1×3 (max,+) dense matrix:\n", " 0 0 0\n", "\n", "x0 = 3×1 (max,+) dense matrix:\n", " .\n", " .\n", " .\n" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S2 = MPSysLin(MP([1 2 3; 4 5 6; 7 8 9]), # A\n", " MP([0;0;0]), # B\n", " MP([0 0 0]), # C\n", " eye(MP,3,3)) # D\n", " # x0 to zeros vector" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Access to matrices\n", "\n", "This is done directly by the fields `.D` or `.A` or `.B` or `.C` or `.x0`" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2×2 (max,+) sparse matrix with 2 stored entries:\n", " [1, 1] = 0\n", " [2, 2] = 0" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S1.D" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2×2 (max,+) dense matrix:\n", " 1 2\n", " 3 4\n" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S1.A" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2-element (max,+) vector:\n", " 0\n", " 0\n" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S1.B" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1×2 (max,+) dense matrix:\n", " 0 0\n" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S1.C" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2×1 (max,+) sparse matrix with 0 stored entries" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S1.x0" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2×1 (max,+) dense matrix:\n", " .\n", " .\n" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "full(S1.x0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Displaying Max-Plus Implicit Systems\n", "\n", "### Display standard output" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Implicit dynamic linear Max-Plus system:\n", " x(n) = D*x(n) + A*x(n-1) + B*u(n)\n", " y(n) = C*x(n)\n", " x(0) = x0\n", "\n", "with:\n", "D = 2×2 (max,+) dense matrix:\n", " 0 .\n", " . 0\n", "\n", "A = 2×2 (max,+) dense matrix:\n", " 1 2\n", " 3 4\n", "\n", "B = 2-element (max,+) vector:\n", " 0\n", " 0\n", "\n", "C = 1×2 (max,+) dense matrix:\n", " 0 0\n", "\n", "x0 = 2×1 (max,+) dense matrix:\n", " .\n", " .\n" ] } ], "source": [ "tropshow(stdout, S1)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Implicit dynamic linear Max-Plus system:\n", " x(n) = D*x(n) + A*x(n-1) + B*u(n)\n", " y(n) = C*x(n)\n", " x(0) = x0\n", "\n", "with:\n", "D = 2×2 (max,+) dense matrix:\n", " 0 .\n", " . 0\n", "\n", "A = 2×2 (max,+) dense matrix:\n", " 1 2\n", " 3 4\n", "\n", "B = 2-element (max,+) vector:\n", " 0\n", " 0\n", "\n", "C = 1×2 (max,+) dense matrix:\n", " 0 0\n", "\n", "x0 = 2×1 (max,+) dense matrix:\n", " .\n", " .\n" ] } ], "source": [ "show(stdout, \"text/plain\", S1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Display of Max-Plus implicit systems inIATTEX\n", "\n", "As the previous display is not the friendliest, we can improve this by generating some code $\\LaTeX$\n", "either with the function `LaTeX` (and if the argument is not passed `IO` then a character string will be returned) or via the function `Base.show` passing the argument `::MIME\"text/latex\"`:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\"\\\\left\\\\{\\\\begin{array}{lcl}\\nx_n & = & \\\\left[\\n\\\\begin{array}{*{20}c}\\n0 & . \\\\\\\\\\n. & 0 \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n x_n \\\\oplus \\\\left[\\n\\\\begin{array}{*{20}c}\\n1 & 2 \\\\\\\\\\n3 & 4 \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n x_{n-1} \\\\oplus \\\\left[\\n\\\\begin{array}{*{20}c}\\n0 \\\\\\\\\\n0 \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n u_n\\\\\\\\ y_n & = & \\\\left[\\n\\\\begin{array}{*{20}c}\\n0 & 0 \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n x_n\\\\\\\\ x_0 & = & \\\\left[\\n\\\\begin{array}{*{20}c}\\n. \\\\\\\\\\n. \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n\\\\end{array}\\\\right.\"" ] } ], "source": [ "LaTeX(stdout, S1) # show(stdout, \"text/latex\", S1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Which will give when compiled:\n", "\n", "$$\\left\\{\\begin{array}{lcl}\n", "x_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", "0 & . \\\\\n", ". & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " x_n \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "1 & 2 \\\\\n", "3 & 4 \\\\\n", "\\end{array}\n", "\\right]\n", " x_{n-1} \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "0 \\\\\n", "0 \\\\\n", "\\end{array}\n", "\\right]\n", " u_n\\\\y_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", "0 & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " x_n\\\\x_0 & = & \\left[\n", "\\begin{array}{*{20}c}\n", ". \\\\\n", ". \\\\\n", "\\end{array}\n", "\\right]\n", "\\end{array}\\right.$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For the rest of this Jupyter document, we will create a function that will force the LaTeX display:" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "latexify (generic function with 2 methods)" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "using LaTeXStrings\n", "\n", "latexify(S1, name=\"S\") = latexstring(name, \"=\", LaTeX(S1))" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$S=\\left\\{\\begin{array}{lcl}\n", "x_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", "0 & . \\\\\n", ". & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " x_n \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "1 & 2 \\\\\n", "3 & 4 \\\\\n", "\\end{array}\n", "\\right]\n", " x_{n-1} \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "0 \\\\\n", "0 \\\\\n", "\\end{array}\n", "\\right]\n", " u_n\\\\ y_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", "0 & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " x_n\\\\ x_0 & = & \\left[\n", "\\begin{array}{*{20}c}\n", ". \\\\\n", ". \\\\\n", "\\end{array}\n", "\\right]\n", "\\end{array}\\right.$" ], "text/plain": [ "L\"$S=\\left\\{\\begin{array}{lcl}\n", "x_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", "0 & . \\\\\n", ". & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " x_n \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "1 & 2 \\\\\n", "3 & 4 \\\\\n", "\\end{array}\n", "\\right]\n", " x_{n-1} \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "0 \\\\\n", "0 \\\\\n", "\\end{array}\n", "\\right]\n", " u_n\\\\ y_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", "0 & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " x_n\\\\ x_0 & = & \\left[\n", "\\begin{array}{*{20}c}\n", ". \\\\\n", ". \\\\\n", "\\end{array}\n", "\\right]\n", "\\end{array}\\right.$\"" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "latexify(S1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Composition of Max-Plus implicit systems\n", "\n", "Just like Scilab, Julia allows you to overload basic operators, which you will use to compose linear systems." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Parallel composition" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/latex": [ "$S=\\left\\{\\begin{array}{lcl}\n", "x_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", "0 & . & . & . & . \\\\\n", ". & 0 & . & . & . \\\\\n", ". & . & 0 & . & . \\\\\n", ". & . & . & 0 & . \\\\\n", ". & . & . & . & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " x_n \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "1 & 2 & . & . & . \\\\\n", "3 & 4 & . & . & . \\\\\n", ". & . & 1 & 2 & 3 \\\\\n", ". & . & 4 & 5 & 6 \\\\\n", ". & . & 7 & 8 & 9 \\\\\n", "\\end{array}\n", "\\right]\n", " x_{n-1} \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "0 \\\\\n", "0 \\\\\n", "0 \\\\\n", "0 \\\\\n", "0 \\\\\n", "\\end{array}\n", "\\right]\n", " u_n\\\\ y_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", "0 & 0 & 0 & 0 & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " x_n\\\\ x_0 & = & \\left[\n", "\\begin{array}{*{20}c}\n", ". \\\\\n", ". \\\\\n", ". \\\\\n", ". \\\\\n", ". \\\\\n", "\\end{array}\n", "\\right]\n", "\\end{array}\\right.$" ], "text/plain": [ "\"\\$S=\\\\left\\\\{\\\\begin{array}{lcl}\\nx_n & = & \\\\left[\\n\\\\begin{array}{*{20}c}\\n0 & . & . & . & . \\\\\\\\\\n. & 0 & . & . & . \\\\\\\\\\n. & . & 0 & . & . \\\\\\\\\\n. & . & . & 0 & . \\\\\\\\\\n. & . & . & . & 0 \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n x_n \\\\oplus \\\\left[\\n\\\\begin{array}{*{20}c}\\n1 & 2 & . & . & . \\\\\\\\\\n3 & 4 & . & . & \" ⋯ 105 bytes ⋯ \"left[\\n\\\\begin{array}{*{20}c}\\n0 \\\\\\\\\\n0 \\\\\\\\\\n0 \\\\\\\\\\n0 \\\\\\\\\\n0 \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n u_n\\\\\\\\ y_n & = & \\\\left[\\n\\\\begin{array}{*{20}c}\\n0 & 0 & 0 & 0 & 0 \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n x_n\\\\\\\\ x_0 & = & \\\\left[\\n\\\\begin{array}{*{20}c}\\n. \\\\\\\\\\n. \\\\\\\\\\n. \\\\\\\\\\n. \\\\\\\\\\n. \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n\\\\end{array}\\\\right.\\$\"" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S = S1 + S2; latexify(S)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Diagonal composition" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$S=\\left\\{\\begin{array}{lcl}\n", "x_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", "0 & . & . & . & . \\\\\n", ". & 0 & . & . & . \\\\\n", ". & . & 0 & . & . \\\\\n", ". & . & . & 0 & . \\\\\n", ". & . & . & . & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " x_n \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "1 & 2 & . & . & . \\\\\n", "3 & 4 & . & . & . \\\\\n", ". & . & 1 & 2 & 3 \\\\\n", ". & . & 4 & 5 & 6 \\\\\n", ". & . & 7 & 8 & 9 \\\\\n", "\\end{array}\n", "\\right]\n", " x_{n-1} \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "0 & . \\\\\n", "0 & . \\\\\n", ". & 0 \\\\\n", ". & 0 \\\\\n", ". & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " u_n\\\\ y_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", "0 & 0 & . & . & . \\\\\n", ". & . & 0 & 0 & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " x_n\\\\ x_0 & = & \\left[\n", "\\begin{array}{*{20}c}\n", ". \\\\\n", ". \\\\\n", ". \\\\\n", ". \\\\\n", ". \\\\\n", "\\end{array}\n", "\\right]\n", "\\end{array}\\right.$" ], "text/plain": [ "\"\\$S=\\\\left\\\\{\\\\begin{array}{lcl}\\nx_n & = & \\\\left[\\n\\\\begin{array}{*{20}c}\\n0 & . & . & . & . \\\\\\\\\\n. & 0 & . & . & . \\\\\\\\\\n. & . & 0 & . & . \\\\\\\\\\n. & . & . & 0 & . \\\\\\\\\\n. & . & . & . & 0 \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n x_n \\\\oplus \\\\left[\\n\\\\begin{array}{*{20}c}\\n1 & 2 & . & . & . \\\\\\\\\\n3 & 4 & . & . & \" ⋯ 146 bytes ⋯ \". \\\\\\\\\\n. & 0 \\\\\\\\\\n. & 0 \\\\\\\\\\n. & 0 \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n u_n\\\\\\\\ y_n & = & \\\\left[\\n\\\\begin{array}{*{20}c}\\n0 & 0 & . & . & . \\\\\\\\\\n. & . & 0 & 0 & 0 \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n x_n\\\\\\\\ x_0 & = & \\\\left[\\n\\\\begin{array}{*{20}c}\\n. \\\\\\\\\\n. \\\\\\\\\\n. \\\\\\\\\\n. \\\\\\\\\\n. \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n\\\\end{array}\\\\right.\\$\"" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S = S1 | S2; latexify(S)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Serial composition" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$S=\\left\\{\\begin{array}{lcl}\n", "x_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", "0 & . & . & . & . \\\\\n", ". & 0 & . & . & . \\\\\n", ". & . & 0 & . & . \\\\\n", "0 & 0 & 0 & 0 & . \\\\\n", "0 & 0 & 0 & . & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " x_n \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "1 & 2 & 3 & . & . \\\\\n", "4 & 5 & 6 & . & . \\\\\n", "7 & 8 & 9 & . & . \\\\\n", ". & . & . & 1 & 2 \\\\\n", ". & . & . & 3 & 4 \\\\\n", "\\end{array}\n", "\\right]\n", " x_{n-1} \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "0 \\\\\n", "0 \\\\\n", "0 \\\\\n", ". \\\\\n", ". \\\\\n", "\\end{array}\n", "\\right]\n", " u_n\\\\ y_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", ". & . & . & 0 & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " x_n\\\\ x_0 & = & \\left[\n", "\\begin{array}{*{20}c}\n", ". \\\\\n", ". \\\\\n", ". \\\\\n", ". \\\\\n", ". \\\\\n", "\\end{array}\n", "\\right]\n", "\\end{array}\\right.$" ], "text/plain": [ "\"\\$S=\\\\left\\\\{\\\\begin{array}{lcl}\\nx_n & = & \\\\left[\\n\\\\begin{array}{*{20}c}\\n0 & . & . & . & . \\\\\\\\\\n. & 0 & . & . & . \\\\\\\\\\n. & . & 0 & . & . \\\\\\\\\\n0 & 0 & 0 & 0 & . \\\\\\\\\\n0 & 0 & 0 & . & 0 \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n x_n \\\\oplus \\\\left[\\n\\\\begin{array}{*{20}c}\\n1 & 2 & 3 & . & . \\\\\\\\\\n4 & 5 & 6 & . & \" ⋯ 105 bytes ⋯ \"left[\\n\\\\begin{array}{*{20}c}\\n0 \\\\\\\\\\n0 \\\\\\\\\\n0 \\\\\\\\\\n. \\\\\\\\\\n. \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n u_n\\\\\\\\ y_n & = & \\\\left[\\n\\\\begin{array}{*{20}c}\\n. & . & . & 0 & 0 \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n x_n\\\\\\\\ x_0 & = & \\\\left[\\n\\\\begin{array}{*{20}c}\\n. \\\\\\\\\\n. \\\\\\\\\\n. \\\\\\\\\\n. \\\\\\\\\\n. \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n\\\\end{array}\\\\right.\\$\"" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S = S1 * S2; latexify(S)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Common entrances" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$S=\\left\\{\\begin{array}{lcl}\n", "x_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", "0 & . & . & . & . \\\\\n", ". & 0 & . & . & . \\\\\n", ". & . & 0 & . & . \\\\\n", ". & . & . & 0 & . \\\\\n", ". & . & . & . & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " x_n \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "1 & 2 & . & . & . \\\\\n", "3 & 4 & . & . & . \\\\\n", ". & . & 1 & 2 & 3 \\\\\n", ". & . & 4 & 5 & 6 \\\\\n", ". & . & 7 & 8 & 9 \\\\\n", "\\end{array}\n", "\\right]\n", " x_{n-1} \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "0 & . \\\\\n", "0 & . \\\\\n", ". & 0 \\\\\n", ". & 0 \\\\\n", ". & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " u_n\\\\ y_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", "0 & 0 & 0 & 0 & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " x_n\\\\ x_0 & = & \\left[\n", "\\begin{array}{*{20}c}\n", ". \\\\\n", ". \\\\\n", ". \\\\\n", ". \\\\\n", ". \\\\\n", "\\end{array}\n", "\\right]\n", "\\end{array}\\right.$" ], "text/plain": [ "\"\\$S=\\\\left\\\\{\\\\begin{array}{lcl}\\nx_n & = & \\\\left[\\n\\\\begin{array}{*{20}c}\\n0 & . & . & . & . \\\\\\\\\\n. & 0 & . & . & . \\\\\\\\\\n. & . & 0 & . & . \\\\\\\\\\n. & . & . & 0 & . \\\\\\\\\\n. & . & . & . & 0 \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n x_n \\\\oplus \\\\left[\\n\\\\begin{array}{*{20}c}\\n1 & 2 & . & . & . \\\\\\\\\\n3 & 4 & . & . & \" ⋯ 125 bytes ⋯ \"*{20}c}\\n0 & . \\\\\\\\\\n0 & . \\\\\\\\\\n. & 0 \\\\\\\\\\n. & 0 \\\\\\\\\\n. & 0 \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n u_n\\\\\\\\ y_n & = & \\\\left[\\n\\\\begin{array}{*{20}c}\\n0 & 0 & 0 & 0 & 0 \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n x_n\\\\\\\\ x_0 & = & \\\\left[\\n\\\\begin{array}{*{20}c}\\n. \\\\\\\\\\n. \\\\\\\\\\n. \\\\\\\\\\n. \\\\\\\\\\n. \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n\\\\end{array}\\\\right.\\$\"" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S = [S1 S2]; latexify(S)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Common outputs" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$S=\\left\\{\\begin{array}{lcl}\n", "x_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", "0 & . & . & . & . \\\\\n", ". & 0 & . & . & . \\\\\n", ". & . & 0 & . & . \\\\\n", ". & . & . & 0 & . \\\\\n", ". & . & . & . & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " x_n \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "1 & 2 & . & . & . \\\\\n", "3 & 4 & . & . & . \\\\\n", ". & . & 1 & 2 & 3 \\\\\n", ". & . & 4 & 5 & 6 \\\\\n", ". & . & 7 & 8 & 9 \\\\\n", "\\end{array}\n", "\\right]\n", " x_{n-1} \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "0 \\\\\n", "0 \\\\\n", "0 \\\\\n", "0 \\\\\n", "0 \\\\\n", "\\end{array}\n", "\\right]\n", " u_n\\\\ y_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", "0 & 0 & . & . & . \\\\\n", ". & . & 0 & 0 & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " x_n\\\\ x_0 & = & \\left[\n", "\\begin{array}{*{20}c}\n", ". \\\\\n", ". \\\\\n", ". \\\\\n", ". \\\\\n", ". \\\\\n", "\\end{array}\n", "\\right]\n", "\\end{array}\\right.$" ], "text/plain": [ "\"\\$S=\\\\left\\\\{\\\\begin{array}{lcl}\\nx_n & = & \\\\left[\\n\\\\begin{array}{*{20}c}\\n0 & . & . & . & . \\\\\\\\\\n. & 0 & . & . & . \\\\\\\\\\n. & . & 0 & . & . \\\\\\\\\\n. & . & . & 0 & . \\\\\\\\\\n. & . & . & . & 0 \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n x_n \\\\oplus \\\\left[\\n\\\\begin{array}{*{20}c}\\n1 & 2 & . & . & . \\\\\\\\\\n3 & 4 & . & . & \" ⋯ 126 bytes ⋯ \"{20}c}\\n0 \\\\\\\\\\n0 \\\\\\\\\\n0 \\\\\\\\\\n0 \\\\\\\\\\n0 \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n u_n\\\\\\\\ y_n & = & \\\\left[\\n\\\\begin{array}{*{20}c}\\n0 & 0 & . & . & . \\\\\\\\\\n. & . & 0 & 0 & 0 \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n x_n\\\\\\\\ x_0 & = & \\\\left[\\n\\\\begin{array}{*{20}c}\\n. \\\\\\\\\\n. \\\\\\\\\\n. \\\\\\\\\\n. \\\\\\\\\\n. \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n\\\\end{array}\\\\right.\\$\"" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S = [S1; S2]; latexify(S)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Composition with feedback" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$S=\\left\\{\\begin{array}{lcl}\n", "x_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", "0 & . & 0 & 0 & 0 \\\\\n", ". & 0 & 0 & 0 & 0 \\\\\n", "0 & 0 & 0 & . & . \\\\\n", "0 & 0 & . & 0 & . \\\\\n", "0 & 0 & . & . & 0 \\\\\n", "\\end{array}\n", "\\right]\n", " x_n \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "1 & 2 & . & . & . \\\\\n", "3 & 4 & . & . & . \\\\\n", ". & . & 1 & 2 & 3 \\\\\n", ". & . & 4 & 5 & 6 \\\\\n", ". & . & 7 & 8 & 9 \\\\\n", "\\end{array}\n", "\\right]\n", " x_{n-1} \\oplus \\left[\n", "\\begin{array}{*{20}c}\n", "0 \\\\\n", "0 \\\\\n", ". \\\\\n", ". \\\\\n", ". \\\\\n", "\\end{array}\n", "\\right]\n", " u_n\\\\ y_n & = & \\left[\n", "\\begin{array}{*{20}c}\n", "0 & 0 & . & . & . \\\\\n", "\\end{array}\n", "\\right]\n", " x_n\\\\ x_0 & = & \\left[\n", "\\begin{array}{*{20}c}\n", ". \\\\\n", ". \\\\\n", ". \\\\\n", ". \\\\\n", ". \\\\\n", "\\end{array}\n", "\\right]\n", "\\end{array}\\right.$" ], "text/plain": [ "\"\\$S=\\\\left\\\\{\\\\begin{array}{lcl}\\nx_n & = & \\\\left[\\n\\\\begin{array}{*{20}c}\\n0 & . & 0 & 0 & 0 \\\\\\\\\\n. & 0 & 0 & 0 & 0 \\\\\\\\\\n0 & 0 & 0 & . & . \\\\\\\\\\n0 & 0 & . & 0 & . \\\\\\\\\\n0 & 0 & . & . & 0 \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n x_n \\\\oplus \\\\left[\\n\\\\begin{array}{*{20}c}\\n1 & 2 & . & . & . \\\\\\\\\\n3 & 4 & . & . & \" ⋯ 105 bytes ⋯ \"left[\\n\\\\begin{array}{*{20}c}\\n0 \\\\\\\\\\n0 \\\\\\\\\\n. \\\\\\\\\\n. \\\\\\\\\\n. \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n u_n\\\\\\\\ y_n & = & \\\\left[\\n\\\\begin{array}{*{20}c}\\n0 & 0 & . & . & . \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n x_n\\\\\\\\ x_0 & = & \\\\left[\\n\\\\begin{array}{*{20}c}\\n. \\\\\\\\\\n. \\\\\\\\\\n. \\\\\\\\\\n. \\\\\\\\\\n. \\\\\\\\\\n\\\\end{array}\\n\\\\right]\\n\\\\end{array}\\\\right.\\$\"" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S = S1 / S2; latexify(S)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Conversion from Max-Plus implicit system to Max-Plus explicit system" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "# TODO S = mpexplicit(S1); latexify(S)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Max-Plus Linear System Simulation\n", "\n", "The function `mpsimul` returns the states $X(n)$ (or the last state) of a Max-Plus linear system by injecting data $U(n)$ Max-Plus as a vector." ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "9×1 (max,+) dense matrix:\n", " 1\n", " 5\n", " 9\n", " 13\n", " 17\n", " 21\n", " 25\n", " 29\n", " 33\n" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "u = Vector(MP(1:0.5:5))\n", "y = mpsimul(S, u, true) # Return the history of states" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1-element (max,+) vector:\n", " 33\n" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mpsimul(S, u, false) # Return the last computed state" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The result can be plotted directly from the Max-Plus numbers." ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "using Plots" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "scrolled": false }, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plot(u, y, label=[\"simulation\"], legend=:topleft)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Another example, system with common inputs:" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "9×1 (max,+) dense matrix:\n", " 1\n", " 10\n", " 19\n", " 28\n", " 37\n", " 46\n", " 55\n", " 64\n", " 73\n" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "u = [MP(1:0.5:5) MP(1:0.5:5)]\n", "y = mpsimul([S1 S2], u, true)" ] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.8.1", "language": "julia", "name": "julia-1.8" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.8.1" } }, "nbformat": 4, "nbformat_minor": 2 }