{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"toc-hr-collapsed": false
},
"source": [
"# Chapter 4"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"using ControlSystems\n",
"using Plots; gr()\n",
"using LinearAlgebra"
]
},
{
"cell_type": "markdown",
"metadata": {
"toc-hr-collapsed": false
},
"source": [
"## 伝達関数モデルのステップ応答"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1次遅れ系"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plt = plot()\n",
"\n",
"K = 1\n",
"T = (1, 0.5, 0.1)\n",
"\n",
"for i in 1:1:length(T)\n",
" P = tf([0, K], [T[i], 1])\n",
" y, t = step( P, 0:0.01:5 )\n",
" plot!(plt, t, y',\n",
" xlabel=\"t\", #X軸のラベル\n",
" ylabel=\"y\", #Y軸のラベル\n",
" lw=2, #線幅\n",
" ls=:solid, #線種\n",
" label=\"T=$(T[i])\",\n",
" legend=:bottomright,\n",
" size=(300,230) #プロットのサイズ \n",
" )\n",
"end\n",
"\n",
"plot(plt)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"T, K = -1, 1\n",
"y, t = step(tf([0, K], [T, 1]), 0:0.01:5 )\n",
"\n",
"plot(t, y',\n",
" xlabel=\"t\", #X軸のラベル\n",
" ylabel=\"y\", #Y軸のラベル\n",
" lw=2, #線幅\n",
" ls=:solid, #線種\n",
" legend=false,\n",
" size=(300,230) #プロットのサイズ \n",
")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plt = plot()\n",
"\n",
"T = 0.5\n",
"K = [1, 2, 3]\n",
"\n",
"for i in 1:1:length(K)\n",
" y, t = step( tf([0, K[i]], [T, 1]), 0:0.01:5) \n",
" plot!(plt, t, y',\n",
" xlabel=\"t\", #X軸のラベル\n",
" ylabel=\"y\", #Y軸のラベル\n",
" lw=2, #線幅\n",
" ls=:solid, #線種\n",
" label=\"K=$(K[i])\",\n",
" legend=:bottomright,\n",
" size=(300,230) #プロットのサイズ \n",
" )\n",
"end\n",
"\n",
"plot(plt)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2次遅れ系"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plt = plot()\n",
"\n",
"ζ = [1, 0.7, 0.4]\n",
"ωₙ = 5\n",
"\n",
"for i in 1:1:length(ζ)\n",
" P = tf([0, ωₙ^2], [1, 2*ζ[i]*ωₙ, ωₙ^2])\n",
" y, t = step(P, 0:0.01:5)\n",
" \n",
" plot!(plt, t, y',\n",
" xlabel=\"t\", #X軸のラベル\n",
" ylabel=\"y\", #Y軸のラベル\n",
" lw=2, #線幅\n",
" ls=:solid, #線種\n",
" label=\"ζ=$(ζ[i])\",\n",
" legend=:bottomright,\n",
" size=(300,230) #プロットのサイズ \n",
" )\n",
"end\n",
"\n",
"plot(plt)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plt = plot()\n",
"\n",
"ζ = [0.1, 0, -0.05]\n",
"ωₙ = 5\n",
"\n",
"for i in 1:1:length(ζ)\n",
" P = tf([0, ωₙ^2], [1, 2*ζ[i]*ωₙ, ωₙ^2])\n",
" y, t = step(P, 0:0.01:5)\n",
" \n",
" plot!(plt, t, y',\n",
" xlabel=\"t\", #X軸のラベル\n",
" ylabel=\"y\", #Y軸のラベル\n",
" lw=2, #線幅\n",
" ls=:solid, #線種\n",
" label=\"ζ=$(ζ[i])\",\n",
" legend=:bottomright,\n",
" size=(300,230) #プロットのサイズ \n",
" )\n",
"end\n",
"\n",
"plot(plt)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plt = plot()\n",
"\n",
"ζ = 0.7\n",
"ωₙ = [1, 5, 10]\n",
"\n",
"for i in 1:1:length(ωₙ)\n",
" P = tf([0, ωₙ[i]^2], [1, 2*ζ*ωₙ[i], ωₙ[i]^2])\n",
" y, t = step(P, 0:0.01:5)\n",
" \n",
" plot!(plt, t, y',\n",
" xlabel=\"t\", #X軸のラベル\n",
" ylabel=\"y\", #Y軸のラベル\n",
" lw=2, #線幅\n",
" ls=:solid, #線種\n",
" label=\"ωₙ=$(ωₙ[i])\",\n",
" legend=:bottomright,\n",
" size=(300,230) #プロットのサイズ \n",
" )\n",
"end\n",
"\n",
"plot(plt)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 練習問題"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TransferFunction{Continuous, ControlSystems.SisoRational{Int64}}\n",
" s + 3\n",
"------------\n",
"s^2 + 3s + 2\n",
"\n",
"Continuous-time transfer function model\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"P1 = tf([1, 3], [1, 3, 2])\n",
"println(P1)\n",
"\n",
"y, t = step(P1, 0:0.01:8 )\n",
"plot(t, y',\n",
" xlabel=\"t\", #X軸のラベル\n",
" ylabel=\"y\", #Y軸のラベル\n",
" lw=2, #線幅\n",
" ls=:solid, #線種\n",
" legend=false,\n",
" size=(300,230) #プロットのサイズ \n",
")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TransferFunction{Continuous, ControlSystems.SisoRational{Int64}}\n",
" 1\n",
"-------------------\n",
"s^3 + 2s^2 + 2s + 1\n",
"\n",
"Continuous-time transfer function model\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"P2 = tf([0, 1], [1, 2, 2, 1])\n",
"println(P2)\n",
"\n",
"y, t = step(P2, 0:0.01:15 )\n",
"plot(t, y',\n",
" xlabel=\"t\", #X軸のラベル\n",
" ylabel=\"y\", #Y軸のラベル\n",
" lw=2, #線幅\n",
" ls=:solid, #線種\n",
" legend=false,\n",
" size=(300,230) #プロットのサイズ \n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 状態空間モデルの時間応答"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"StateSpace{Continuous, Int64}\n",
"A = \n",
" 0 1\n",
" -4 -5\n",
"B = \n",
" 0\n",
" 1\n",
"C = \n",
" 1 0\n",
" 0 1\n",
"D = \n",
" 0\n",
" 0\n",
"\n",
"Continuous-time state-space model"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A = [0 1; -4 -5]\n",
"B = [0; 1]\n",
"C = [1 0; 0 1]\n",
"D = [0; 0]\n",
"P = ss(A, B, C, D)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2-element Vector{Float64}:\n",
" -4.0\n",
" -1.0"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"eigvals(A)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 零入力応答"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Td = 0:0.01:5\n",
"X0 = [-0.3, 0.4]\n",
"u(x,t) = 0 \n",
"_, t, x, _ = lsim(P, u, Td, x0=X0); #ゼロ入力応答\n",
"\n",
"plot(t, x',\n",
" xlabel=\"t\", #X軸のラベル\n",
" ylabel=\"x\", #Y軸のラベル\n",
" lw=2, #線幅\n",
" ls=:solid, #線種\n",
" label=[\"x₁\" \"x₂\"],\n",
" legend=:best,\n",
" size=(300,230) #プロットのサイズ \n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 零状態応答"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Td = 0:0.01:5\n",
"x, t = step(P, Td) #ゼロ状態応答\n",
"\n",
"plot(t, x',\n",
" xlabel=\"t\", #X軸のラベル\n",
" ylabel=\"x\", #Y軸のラベル\n",
" lw=2, #線幅\n",
" ls=:solid, #線種\n",
" label=[\"x₁\" \"x₂\"],\n",
" legend=:best,\n",
" size=(300,230) #プロットのサイズ \n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 完全応答"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Td = 0:0.01:5\n",
"X0 = [-0.3, 0.4]\n",
"u(x,t) = 0\n",
"ustep(x,t) = 1\n",
"\n",
"_, t, x, _ = lsim(P, ustep, Td, x0=X0); #完全応答\n",
"_, t, xin, _ = lsim(P, u, Td, x0=X0); #ゼロ入力応答\n",
"xst, t = step(P, Td) #ゼロ状態応答\n",
"\n",
"p = [ plot(), plot()]\n",
"\n",
"for i = 1:2\n",
"plot!(p[i], t, x[i,:],\n",
" xlabel=\"t\", #X軸のラベル\n",
" ylabel=\"x\", #Y軸のラベル\n",
" lw=2, #線幅\n",
" ls=:solid, #線種\n",
" label=\"response\",\n",
" size=(300,230) #プロットのサイズ \n",
")\n",
" \n",
"plot!(p[i], t, xin[i,:],\n",
" xlabel=\"t\", #X軸のラベル\n",
" ylabel=\"x\", #Y軸のラベル\n",
" lw=2, #線幅\n",
" ls=:dot, #線種\n",
" label=\"zero input\",\n",
" size=(300,230) #プロットのサイズ \n",
")\n",
" \n",
"plot!(p[i], t, xst[i,:],\n",
" xlabel=\"t\", #X軸のラベル\n",
" ylabel=\"x\", #Y軸のラベル\n",
" lw=2, #線幅\n",
" ls=:dash, #線種\n",
" label=\"zero state\",\n",
" legend=:best,\n",
" size=(300,230) #プロットのサイズ \n",
")\n",
"end\n",
"\n",
"plot( p[1], p[2], layout=(1,2), size=(600,230) )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 練習問題"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Td = 0:0.01:5\n",
"X0 = [0.5, 1]\n",
"u(x,t) = 0\n",
"ud(x,t) = 3sin(5t)\n",
"\n",
"y, t, x, uout = lsim(P, ud, Td, x0=X0); #完全応答\n",
"y, t, xin, uout = lsim(P, u, Td, x0=X0); #ゼロ入力応答\n",
"y, t, xst, uout = lsim(P, ud, Td); #ゼロ状態応答\n",
"\n",
"p = [ plot(), plot()]\n",
"\n",
"for i = 1:2\n",
"plot!(p[i], t, x[i,:],\n",
" xlabel=\"t\", #X軸のラベル\n",
" ylabel=\"x\", #Y軸のラベル\n",
" lw=2, #線幅\n",
" ls=:solid, #線種\n",
" label=\"response\",\n",
" size=(300,230) #プロットのサイズ \n",
")\n",
" \n",
"plot!(p[i], t, xin[i,:],\n",
" xlabel=\"t\", #X軸のラベル\n",
" ylabel=\"x\", #Y軸のラベル\n",
" lw=2, #線幅\n",
" ls=:dot, #線種\n",
" label=\"zero input\",\n",
" size=(300,230) #プロットのサイズ \n",
")\n",
" \n",
"plot!(p[i], t, xst[i,:],\n",
" xlabel=\"t\", #X軸のラベル\n",
" ylabel=\"x\", #Y軸のラベル\n",
" lw=2, #線幅\n",
" ls=:dash, #線種\n",
" label=\"zero state\",\n",
" legend=:best,\n",
" size=(300,230) #プロットのサイズ \n",
")\n",
"end\n",
"\n",
"plot( p[1], p[2], layout=(1,2), size=(600,230) )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 安定性"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 極"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"P1:ComplexF64[-1.0 + 0.0im]\n",
"P2:ComplexF64[1.0 + 0.0im]\n",
"P3:ComplexF64[-0.025000000000000015 + 0.9996874511566101im, -0.025000000000000015 - 0.9996874511566101im]\n",
"P4:ComplexF64[0.025000000000000015 + 0.9996874511566101im, 0.025000000000000015 - 0.9996874511566101im]\n"
]
}
],
"source": [
"P1 = tf([0,1],[1, 1])\n",
"println(\"P1:\", pole(P1))\n",
"\n",
"P2 = tf([0,1],[-1, 1])\n",
"println(\"P2:\", pole(P2))\n",
"\n",
"P3 = tf([0,1],[1, 0.05, 1])\n",
"println(\"P3:\", pole(P3))\n",
"\n",
"P4 = tf([0,1],[1, -0.05, 1])\n",
"println(\"P4:\", pole(P4))"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pzmap(P1, markersize=5, markerstrokewidth=10, marker=:xcross, markeralpha=1, label=\"P₁\")\n",
"pzmap!(P2,markersize=5, marker=:diamond, markeralpha=1, label=\"P₂\")\n",
"pzmap!(P3, markersize=5, marker=:star, markeralpha=1, label=\"P₃\")\n",
"pzmap!(P4, markersize=5, marker=:circle, markeralpha=1, label=\"P₄\")\n",
"\n",
"plot!(size=(300,300), legend=:best)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 位相面図"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"using ControlSystems\n",
"using Plots; gr()\n",
"using LinearAlgebra"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"meshgrid (generic function with 1 method)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function vectorfield2d(field, points, t, v, arrowlength=0.02)\n",
" # More input pattern parsing is solved by the Plots package, but I don't know how.\n",
" errormessage = \"Incorrect formatting of points. Please format them as [x1 y1; x2, y2;...]\"\n",
" \n",
" if typeof(points) <: Array{<:Number, 2} && size(points)[1] === 2\n",
" vectors = similar(points)\n",
" for i in 1:size(points)[2]\n",
" vectors[:, i] .= collect(field(points[:, i]...))\n",
" end\n",
" else\n",
" error(errormessage)\n",
" end\n",
" vectors .*= arrowlength\n",
" quiver(points[1, :],points[2, :],quiver=(vectors[1, :], vectors[2, :]))\n",
" plot!(t, v[2,1]/v[1,1]*t)\n",
" plot!(t, v[2,2]/v[1,2]*t)\n",
" display(plot!(size=(300,300), xlim=(-1.5,1.5), ylim=(-1.5,1.5), legend=false))\n",
"end\n",
"\n",
"function meshgrid(n)\n",
" xs = ones(n) .* (1:n)'\n",
" ys = xs'\n",
" xys = permutedims(cat(xs, ys; dims = 3), [3, 1, 2])\n",
" return reshape(xys, 2, n^2)\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"A = [0 1; -4 -5]\n",
"s,v = eigen(A)\n",
"\n",
"vf(x, y) = (A[1,1]*x + A[1,2]*y, A[2,1]*x + A[2,2]*y) # circular vectorfield\n",
"\n",
"t = -1.5:0.01:1.5;\n",
"grid = meshgrid(20) ./5 .- [1.5; 1.5]\n",
"vectorfield2d(vf, grid, t, v)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"A = [0 1; -4 5]\n",
"s,v = eigen(A)\n",
"\n",
"vf(x, y) = (A[1,1]*x + A[1,2]*y, A[2,1]*x + A[2,2]*y) # circular vectorfield\n",
"\n",
"t = -1.5:0.01:1.5;\n",
"grid = meshgrid(20) ./5 .- [1.5; 1.5]\n",
"vectorfield2d(vf, grid, t, v)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"A = [0 1; 4 5]\n",
"s,v = eigen(A)\n",
"\n",
"vf(x, y) = (A[1,1]*x + A[1,2]*y, A[2,1]*x + A[2,2]*y) # circular vectorfield\n",
"\n",
"t = -1.5:0.01:1.5;\n",
"grid = meshgrid(20) ./5 .- [1.5; 1.5]\n",
"vectorfield2d(vf, grid, t, v)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 零点の影響"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Td = 0:0.01:5\n",
"Ud(t, x) = 1\n",
"\n",
"ζ = .4\n",
"ωₙ = 3\n",
"\n",
"P1 = tf([ 0, ωₙ^2],[1, 2*ζ*ωₙ, ωₙ^2])\n",
"Pss = ss(P1)\n",
"y, t, x, uout = lsim(Pss, Ud, Td)\n",
"\n",
"plot(t, y',\n",
" xlabel=\"t\", #X軸のラベル\n",
" ylabel=\"y\", #Y軸のラベル\n",
" lw=2, #線幅\n",
" ls=:solid, #線種\n",
" label=\"P₁\",\n",
" size=(300,230) #プロットのサイズ \n",
")\n",
"\n",
"P2 = tf([ 3, ωₙ^2],[1, 2*ζ*ωₙ, ωₙ^2])\n",
"Pss = ss(P2)\n",
"y, t, x, uout = lsim(Pss, Ud, Td)\n",
"\n",
"plot!(t, y',\n",
" xlabel=\"t\", #X軸のラベル\n",
" ylabel=\"y\", #Y軸のラベル\n",
" lw=2, #線幅\n",
" ls=:solid, #線種\n",
" label=\"P₂\",\n",
" size=(300,230) #プロットのサイズ \n",
")\n",
"\n",
"\n",
"P3 = tf([ -3, ωₙ^2],[1, 2*ζ*ωₙ, ωₙ^2])\n",
"Pss = ss(P3)\n",
"y, t, x, uout = lsim(Pss, Ud, Td)\n",
"\n",
"plot!(t, y',\n",
" xlabel=\"t\", #X軸のラベル\n",
" ylabel=\"y\", #Y軸のラベル\n",
" lw=2, #線幅\n",
" ls=:solid, #線種\n",
" label=\"P₃\",\n",
" legend=:bottomright,\n",
" size=(300,230) #プロットのサイズ \n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 周波数応答"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### インパルスは余弦波の重ね合わせ"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t = 0:0.01:3;\n",
"\n",
"uimp = 0 * t\n",
"for i in range(0,10)\n",
" uimp = uimp + (0.1/2π)*cos.(t * (i+1))\n",
"end\n",
"\n",
"p1 = plot(t, uimp,\n",
" xlabel=\"t\", #X軸のラベル\n",
" ylabel=\"x\", #Y軸のラベル\n",
" lw=2, #線幅\n",
" ls=:solid, #線種\n",
" legend=false,\n",
" size=(300,230) #プロットのサイズ \n",
")\n",
"\n",
"uimp = 0 * t\n",
"for i in range(0,13000)\n",
" uimp = uimp + (0.1/2π)*cos.(t * (i+1))\n",
"end\n",
"\n",
"p2 = plot(t, uimp,\n",
" xlabel=\"t\", #X軸のラベル\n",
" ylabel=\"x\", #Y軸のラベル\n",
" lw=2, #線幅\n",
" ls=:solid, #線種\n",
" legend=false,\n",
" size=(300,230) #プロットのサイズ \n",
")\n",
"\n",
"plot(p1, p2, layout=(1,2), size=(600,230))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ζ = 0.7\n",
"ωₙ = 5\n",
"P = tf([0,ωₙ^2],[1, 2*ζ*ωₙ, ωₙ^2])\n",
"\n",
"freq = [2, 5, 10, 20]\n",
"Td = 0:0.01:5\n",
"\n",
"p = [ plot() plot(); plot() plot() ];\n",
"\n",
"for i in [1,2]\n",
" for j in [1,2]\n",
" u(x,t) = sin(freq[2*(i-1)+j]*t)\n",
" y, t, x, uout = lsim(P, u, Td)\n",
" \n",
" plot!(p[i,j], t, y', lw=2, label=\"y\")\n",
" plot!(p[i,j], t, uout', lw=1, label=\"u\")\n",
" end\n",
"end\n",
"\n",
"plot(p[1,1],p[1,2],p[2,1],p[2,2], layout=(2,2))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1次遅れ系のボード線図"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"K = 1\n",
"T = [1, 0.5, 0.1]\n",
"\n",
"P1 = tf([0, K],[T[1], 1])\n",
"P2 = tf([0, K],[T[2], 1])\n",
"P3 = tf([0, K],[T[3], 1])\n",
"\n",
"setPlotScale(\"dB\")\n",
"bodeplot([P1,P2,P3], lw=2, size=(450,400), \n",
" label = [\"T=$(T[1])\" \"T=$(T[1])\" \"T=$(T[2])\" \"T=$(T[2])\" \"T=$(T[3])\" \"T=$(T[3])\"], \n",
" legend=:bottomleft, title=\"\" )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2次遅れ系のボード線図"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ζ = [1, 0.7, 0.4]\n",
"ωₙ = 1\n",
"\n",
"P1 = tf([0, ωₙ^2], [1, 2*ζ[1]*ωₙ, ωₙ^2])\n",
"P2 = tf([0, ωₙ^2], [1, 2*ζ[2]*ωₙ, ωₙ^2])\n",
"P3 = tf([0, ωₙ^2], [1, 2*ζ[3]*ωₙ, ωₙ^2])\n",
"\n",
"setPlotScale(\"dB\")\n",
"bodeplot([P1,P2,P3], lw=2, size=(450,400),\n",
" label = [\"ζ=$(ζ[1])\" \"ζ=$(ζ[1])\" \"ζ=$(ζ[2])\" \"ζ=$(ζ[2])\" \"ζ=$(ζ[3])\" \"ζ=$(ζ[3])\"], \n",
" legend=:bottomleft, title=\"\" )"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ζ = 0.7\n",
"ωₙ = (1, 5, 10)\n",
"\n",
"P1 = tf([0, ωₙ[1]^2], [1, 2*ζ*ωₙ[1], ωₙ[1]^2])\n",
"P2 = tf([0, ωₙ[2]^2], [1, 2*ζ*ωₙ[2], ωₙ[2]^2])\n",
"P3 = tf([0, ωₙ[3]^2], [1, 2*ζ*ωₙ[3], ωₙ[3]^2])\n",
"\n",
"setPlotScale(\"dB\")\n",
"bodeplot([P1,P2,P3], lw=2, size=(450,400), \n",
" label = [\"ωₙ=$(ωₙ[1])\" \"ωₙ=$(ωₙ[1])\" \"ωₙ=$(ωₙ[2])\" \"ωₙ=$(ωₙ[2])\" \"ωₙ=$(ωₙ[3])\" \"ωₙ=$(ωₙ[3])\"], \n",
" legend=:bottomleft, title=\"\" )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 練習問題"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TransferFunction{Continuous, ControlSystems.SisoRational{Int64}}\n",
" s + 3\n",
"------------\n",
"s^2 + 3s + 2\n",
"\n",
"Continuous-time transfer function model\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"P1 = tf([1, 3], [1, 3, 2])\n",
"println(P1)\n",
"\n",
"setPlotScale(\"dB\")\n",
"bodeplot(P1, lw=2, size=(450,400), legend=false, title=\"\" )"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TransferFunction{Continuous, ControlSystems.SisoRational{Int64}}\n",
" 1\n",
"-------------------\n",
"s^3 + 2s^2 + 2s + 1\n",
"\n",
"Continuous-time transfer function model"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"P2 = tf([0, 1], [1, 2, 2, 1])\n",
"print(P2)\n",
"\n",
"setPlotScale(\"dB\")\n",
"bodeplot(P2, lw=2, size=(450,400), legend=false, title=\"\" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.7.0",
"language": "julia",
"name": "julia-1.7"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.7.0"
},
"toc-autonumbering": false,
"toc-showcode": false,
"toc-showmarkdowntxt": false,
"toc-showtags": false
},
"nbformat": 4,
"nbformat_minor": 4
}