{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Chapter 3" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "using ControlSystems" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 状態空間モデルの記述" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "状態空間モデルの記述は,ssを用います" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "StateSpace{Continuous, Int64}\n", "A = \n", " 0 1\n", " -1 -1\n", "B = \n", " 0\n", " 1\n", "C = \n", " 1 0\n", "D = \n", " 0\n", "\n", "Continuous-time state-space model" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A = [0 1; -1 -1]\n", "B = [0; 1]\n", "C = [1 0]\n", "D = 0\n", "P = ss(A, B, C, D)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 練習問題" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "StateSpace{Continuous, Int64}\n", "A = \n", " 1 1 2\n", " 2 1 1\n", " 3 4 5\n", "B = \n", " 2\n", " 0\n", " 1\n", "C = \n", " 1 1 0\n", "D = \n", " 0\n", "\n", "Continuous-time state-space model" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A = [1 1 2; 2 1 1; 3 4 5]\n", "B = [2; 0; 1]\n", "C = [1 1 0]\n", "D = 0\n", "P = ss(A, B, C, D)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### A,B,C,D行列の抽出" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "A=[1 1 2; 2 1 1; 3 4 5]\n", "B=[2; 0; 1;;]\n", "C=[1 1 0]\n", "D=[0;;]\n" ] } ], "source": [ "println(\"A=\", P.A)\n", "println(\"B=\", P.B)\n", "println(\"C=\", P.C)\n", "println(\"D=\", P.D)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 伝達関数モデルの記述" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "伝達関数モデルの記述は,tfを用います" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}\n", " 1\n", "------------\n", "s^2 + 2s + 3\n", "\n", "Continuous-time transfer function model" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Np = [0, 1] # 伝達関数の分子多項式の係数 (0*s + 1)\n", "Dp = [1, 2, 3] # 伝達関数の分母多項式の係数 (1*s^2 + 2*s + 3)\n", "P = tf(Np, Dp)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}\n", " 1\n", "------------\n", "s^2 + 2s + 3\n", "\n", "Continuous-time transfer function model" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "P = tf([0, 1], [1, 2, 3])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "ラプラス演算子を定義して記述することもできます" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}\n", " 1\n", "------------\n", "s^2 + 2s + 3\n", "\n", "Continuous-time transfer function model" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s = tf(\"s\")\n", "P = 1/(s^2+2s+3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 練習問題" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}\n", " s + 2\n", "-------------------\n", "s^3 + 5s^2 + 3s + 4\n", "\n", "Continuous-time transfer function model" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "P = tf([1, 2], [1, 5, 3, 4])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "分母多項式の展開" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$$ \\begin{equation}\n", "4 + 8 s + 5 s^{2} + s^{3}\n", "\\end{equation}\n", " $$" ], "text/plain": [ "4 + 8s + 5(s^2) + s^3" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "using Symbolics\n", "@variables s\n", "expand( (s+1)*(s+2)^2 )" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}\n", " s + 3\n", "-------------------\n", "s^3 + 5s^2 + 8s + 4\n", "\n", "Continuous-time transfer function model" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "P = tf([1, 3],[1, 5, 8, 4])" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}\n", " s + 3\n", "-------------------\n", "s^3 + 5s^2 + 8s + 4\n", "\n", "Continuous-time transfer function model" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "P1 = tf([1, 3], [0, 1])\n", "P2 = tf([0, 1], [1, 1])\n", "P3 = tf([0, 1], [1, 2])\n", "P = P1 * P2 * P3^2" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}\n", " 1\n", "-------------------\n", "s^3 + 5s^2 + 8s + 4\n", "\n", "Continuous-time transfer function model" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s = tf(\"s\")\n", "P = 1/(s+1)/(s+2)^2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 分母・分子多項式の係数の抽出" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1×1 Matrix{Vector{Int64}}:\n", " [1, 5, 8, 4]" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "den(P)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1×1 Matrix{Vector{Int64}}:\n", " [1]" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "num(P)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## モデルの変換" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "StateSpace{Continuous, Float64}\n", "A = \n", " 0.0 1.0\n", " -1.0 -1.0\n", "B = \n", " 0.0\n", " 1.0\n", "C = \n", " 1.0 0.0\n", "D = \n", " 0.0\n", "\n", "Continuous-time state-space model\n", "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Float64}}\n", " 1.0\n", "-------------------\n", "1.0s^2 + 1.0s + 1.0\n", "\n", "Continuous-time transfer function model\n" ] } ], "source": [ "P = tf([0, 1], [1, 1, 1])\n", "\n", "Pss = ss(P) # 伝達関数モデルから状態空間モデルへの変換\n", "println(Pss)\n", "Ptf = tf(Pss) # 状態空間モデルから伝達関数モデルへの変換\n", "println(Ptf)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## ブロック線図の結合" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}\n", " 1\n", "-----\n", "s + 1\n", "\n", "Continuous-time transfer function model" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S1 = tf( [0, 1], [1, 1])" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}\n", " s + 1\n", "-----------\n", "s^2 + s + 1\n", "\n", "Continuous-time transfer function model" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S2 = tf( [1, 1], [1, 1, 1])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 直列結合" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}\n", " s + 1\n", "-------------------\n", "s^3 + 2s^2 + 2s + 1\n", "\n", "Continuous-time transfer function model\n", "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}\n", " s + 1\n", "-------------------\n", "s^3 + 2s^2 + 2s + 1\n", "\n", "Continuous-time transfer function model\n" ] } ], "source": [ "S = S2 * S1;\n", "println(S)\n", "\n", "S = series(S1, S2);\n", "println(S)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "分母分子の共通因子 s+1 が約分されない\n", "この場合は,minreal を使う" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Float64}}\n", " 1.0\n", "-------------------------------------------------\n", "1.0s^2 + 1.0000000000000004s + 0.9999999999999992\n", "\n", "Continuous-time transfer function model" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "minreal(S)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 並列結合" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}\n", " 2s^2 + 3s + 2\n", "-------------------\n", "s^3 + 2s^2 + 2s + 1\n", "\n", "Continuous-time transfer function model\n", "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}\n", " 2s^2 + 3s + 2\n", "-------------------\n", "s^3 + 2s^2 + 2s + 1\n", "\n", "Continuous-time transfer function model\n" ] } ], "source": [ "S = S1 + S2;\n", "println(S)\n", "\n", "S = parallel(S1, S2)\n", "println(S)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### フィードバック結合" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}\n", " s^4 + 3s^3 + 4s^2 + 3s + 1\n", "------------------------------------------\n", "s^6 + 4s^5 + 9s^4 + 13s^3 + 12s^2 + 7s + 2\n", "\n", "Continuous-time transfer function model\n", "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}\n", " s + 1\n", "-------------------\n", "s^3 + 2s^2 + 3s + 2\n", "\n", "Continuous-time transfer function model\n" ] } ], "source": [ "S = S1*S2 / (1 + S1*S2)\n", "println(S)\n", "\n", "S = feedback(S1*S2, 1)\n", "println(S)" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Float64}}\n", " 1.0\n", "-------------------------------------------------\n", "1.0s^2 + 0.9999999999999993s + 2.0000000000000018\n", "\n", "Continuous-time transfer function model" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "minreal(S)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 練習問題" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}\n", " 3s^2 + 7s + 2\n", "-----------------\n", "7s^3 + 17s^2 + 7s\n", "\n", "Continuous-time transfer function model" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S1 = tf(1, [1, 1])\n", "S2 = tf(1, [1, 2])\n", "S3 = tf([3, 1], [1, 0])\n", "S4 = tf([2, 0], [0, 1])\n", "\n", "S12 = feedback(S1, S2)\n", "S123 = series(S12, S3)\n", "S = feedback(S123, S4)" ] }, { "cell_type": "markdown", "metadata": { "toc-hr-collapsed": true, "toc-nb-collapsed": true }, "source": [ "### プロパー性" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Float64}}\n", "1.0\n", "---\n", "1.0\n", "\n", "Continuous-time transfer function model" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S1 = tf([1, 1], [0, 1])\n", "S2 = tf([0, 1], [1, 1])\n", "\n", "S = series(S1, S2)\n", "minreal(S)" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}\n", " 1\n", "-----\n", "s + 1\n", "\n", "Continuous-time transfer function model" ] }, { "data": { "text/plain": [ "StateSpace{Continuous, Float64}\n", "A = \n", " -1.0\n", "B = \n", " 1.0\n", "C = \n", " 1.0\n", "D = \n", " 0.0\n", "\n", "Continuous-time state-space model" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "print(S2)\n", "ss(S2)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}\n", "s + 1\n", "-----\n", " 1\n", "\n", "Continuous-time transfer function model" ] }, { "ename": "LoadError", "evalue": "System is improper, a state-space representation is impossible", "output_type": "error", "traceback": [ "System is improper, a state-space representation is impossible", "", "Stacktrace:", " [1] error(s::String)", " @ Base ./error.jl:35", " [2] convert(::Type{StateSpace{Continuous, Float64}}, G::TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}}; balance::Bool)", " @ ControlSystemsBase ~/.julia/packages/ControlSystemsBase/4kZY4/src/types/conversion.jl:92", " [3] convert", " @ ControlSystemsBase ~/.julia/packages/ControlSystemsBase/4kZY4/src/types/conversion.jl:90 [inlined]", " [4] #convert#153", " @ ControlSystemsBase ~/.julia/packages/ControlSystemsBase/4kZY4/src/types/conversion.jl:86 [inlined]", " [5] convert", " @ ControlSystemsBase ~/.julia/packages/ControlSystemsBase/4kZY4/src/types/conversion.jl:84 [inlined]", " [6] StateSpace", " @ ControlSystemsBase ~/.julia/packages/ControlSystemsBase/4kZY4/src/types/StateSpace.jl:127 [inlined]", " [7] ss(args::TransferFunction{Continuous, ControlSystemsBase.SisoRational{Int64}})", " @ ControlSystemsBase ~/.julia/packages/ControlSystemsBase/4kZY4/src/types/StateSpace.jl:144", " [8] top-level scope", " @ In[26]:2" ] } ], "source": [ "print(S1)\n", "ss(S1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.10.0", "language": "julia", "name": "julia-1.10" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.10.0" } }, "nbformat": 4, "nbformat_minor": 4 }