# MATLAB ## 概要 MATLABは数値計算環境であり、*Feedback Control of Computing Systems* では各章末の任意節(`*` 印の節)で、本文の解析的な議論を裏づける数値計算の例として使われる。序文では、本書を読み進めるのに MATLAB へのアクセスは必須ではないと明記されている。(Source: [[Feedback Control of Computing Systems]] 序文; [[@2004__Wiley__Feedback Control of Computing Systems - Chapter 3 Z-Transforms and Transfer Functions]] §3.6) ## wiki 内での位置づけ 第3章 §3.6「Z-Transforms and MATLAB」で最初にまとまった形で登場する。多項式をベクトルとして表現し(例: $z^2-z+0.5$ は `[1 -1 0.5]`)、`roots` で根を求め、`abs`・`angle`・`real`・`imag` で複素数の大きさ・角度・実部・虚部を求め、`conv` で多項式の積を計算し、`residue` で部分分数展開の係数を求める、という一連の使い方が示される。Control Systems Toolboxの `tf` コマンドを使えば伝達関数を分子多項式・分母多項式・サンプリング時間から直接構築できる。(Source: [[@2004__Wiley__Feedback Control of Computing Systems - Chapter 3 Z-Transforms and Transfer Functions]] §3.6) 第6章 §6.6「Analyzing Transient Response with MATLAB」(任意節)では、IBM Lotus Domino Server(伝達関数 $G(z)=0.47/(z-0.43)$、サンプリング時間60秒)と移動平均フィルタ(伝達関数 $0.05/(z-0.95)$)を`tf`コマンドでそれぞれ構築し、`*`演算子で直列接続した開ループ系のモデルを得る手順を示す。得られたモデルに対し`dcgain`で定常ゲインを、`impulse`・`step`でインパルス応答・ステップ応答を求められることが示される(Source: [[@2004__Wiley__Feedback Control of Computing Systems - Chapter 6 Higher-Order Systems]] §6.6)。 第7章 §7.9「Constructing State-Space Models in MATLAB」(任意節)では、Apache HTTP Serverの状態空間モデル(§7.6の $A,B,C$)を題材に、`A = [...]`・`B = [...]`・`C = [...]`で行列を入力し、`ss(A,B,C,D,-1)`(第4引数はDフィードスルー行列、第5引数の-1は離散時間モデルを示す)で状態空間モデルオブジェクトを構築する手順を示す。構築したオブジェクトに対し、`eig(A)`または`pole(sys)`で極(固有値)、`dcgain(sys)`で定常ゲイン行列、`step(sys,1:10)`でステップ応答を求められることが示される。(Source: [[@2004__Wiley__Feedback Control of Computing Systems - Chapter 7 State-Space Models]] §7.9) 第8章 §8.8「Designing P-Controllers in MATLAB」では、比例制御・一次系・移動平均フィルタからなる閉ループ系(式8.14)を題材に、`tf`で個々の伝達関数(対象システム・フィルタ)を構築し、`feedback`でコントローラゲインと対象システムをフィードフォワード、フィルタをフィードバックとする閉ループ伝達関数を合成する手順を示す。さらに`pole`・`zero`で閉ループ極・零点を、`dcgain`で定常ゲインを抽出でき、`rlocus`でループ伝達関数(コントローラを除いた開ループ部分)から根軌跡を、`step`で閉ループ系のステップ応答をプロットできることが示される。(Source: [[@2004__Wiley__Feedback Control of Computing Systems - Chapter 8 Proportional Control]] §8.8) 第9章 §9.7「Designing PI Controllers in MATLAB」(任意節)では、Apache HTTP ServerのPI制御(図9.27を再現する例)を題材に、複数の$K_P,K_I$の組を`tf`で伝達関数の行列として構築し、`feedback`で閉ループ伝達関数を合成する手順を示す。`poles`で閉ループ極を求め、最大の大きさを持つ支配極から`ks(i) = -4/log(r)`で整定時間を、極の角度`theta`から場合分けで最大オーバーシュートを推定し、`step`コマンドで実際のオーバーシュートも併せて計算する、という一連のループ処理が示される。(Source: [[@2004__Wiley__Feedback Control of Computing Systems - Chapter 9 PID Controllers]] §9.7) 第10章 §10.6「Designing State-Space Controllers Using MATLAB」(任意節)では、tandem queue の状態空間モデルを題材に、極配置設計とLQR設計それぞれのMATLABコマンドを示す。極配置設計はExample 10.9を再現し、`A`・`B`と目標極のベクトル`P`を`place(A,B,P)`に渡すことでゲイン`K`を得る。LQR設計はExample 10.11を再現し、`Q = diag([1 1 100])`・`R = 1`を`dlqr(A,B,Q,R)`に渡すことで、Table 10.3の反復アルゴリズムを手計算した結果とほぼ一致するゲイン`K`(11.5403, 11.9249, 6.2095)を得る。両コマンドとも、本文中の手計算による設計手順を裏づける役割を果たす。(Source: [[@2004__Wiley__Feedback Control of Computing Systems - Chapter 10 State-Space Feedback Control]] §10.6) ## 関連 - ソース: [[@2004__Wiley__Feedback Control of Computing Systems - Chapter 3 Z-Transforms and Transfer Functions]] / [[@2004__Wiley__Feedback Control of Computing Systems - Chapter 6 Higher-Order Systems]] / [[@2004__Wiley__Feedback Control of Computing Systems - Chapter 7 State-Space Models]] / [[@2004__Wiley__Feedback Control of Computing Systems - Chapter 8 Proportional Control]] / [[@2004__Wiley__Feedback Control of Computing Systems - Chapter 9 PID Controllers]] / [[@2004__Wiley__Feedback Control of Computing Systems - Chapter 10 State-Space Feedback Control]] - 書籍: [[Feedback Control of Computing Systems]] - 概念: [[Z変換と伝達関数]] / [[支配極と高次系の近似]] / [[極配置設計]] / [[状態空間モデル]] / [[PID制御]] ## 出典 - Hellerstein, Diao, Parekh, Tilbury, *Feedback Control of Computing Systems*, IEEE Press / John Wiley & Sons, 2004, Chapter 3, §3.6; Chapter 6, §6.6; Chapter 7, §7.9; Chapter 8, §8.8; Chapter 9, §9.7; Chapter 10, §10.6.