From aeabed4144489551848afbe817223a394d8d58f1 Mon Sep 17 00:00:00 2001 From: Farbod Raeisi Date: Thu, 8 Aug 2024 23:27:11 +0330 Subject: [PATCH] Add files via upload --- Python Equivalent/Chapter 7/6_9.py | 57 ++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Python Equivalent/Chapter 7/6_9.py diff --git a/Python Equivalent/Chapter 7/6_9.py b/Python Equivalent/Chapter 7/6_9.py new file mode 100644 index 0000000..257e74b --- /dev/null +++ b/Python Equivalent/Chapter 7/6_9.py @@ -0,0 +1,57 @@ +import numpy as np +import control as ctrl + +# Define the system matrices +A = np.array([[-2, -1, 2], + [-1, -2, 2], + [-2, 0, 2]]) + +B = np.array([[0, 0], + [0, 1], + [1, 0]]) + +f = np.array([[1], + [1]]) + +# Calculate b = B*f +b = B @ f + +# Compute the controllability matrix +C = ctrl.ctrb(A, b) + +# Given matrices +Psi = np.array([[1, 2, -1], + [0, 1, 2], + [0, 0, 1]]) + +delta = np.array([4, 13, 10]) + +# Compute M matrix +M = delta @ np.linalg.inv(C @ Psi) + +# Compute K1 +K1 = f * M + +# Desired closed-loop poles +pd = np.array([-2, -2, -2]) + +# Compute the state feedback gain using pole placement +k = ctrl.acker(A, B, pd) + +# Compute K2 +K2 = f * k + +# Compute the closed-loop system matrix Ac +Ac = A - B @ K1 + +# Compute eigenvalues of Ac +eigvals_Ac = np.linalg.eigvals(Ac) + +print("State feedback gain K1:") +print(K1) +print("\nState feedback gain k (pd = [-2, -2, -2]):") +print(k) +print("\nState feedback gain K2:") +print(K2) +print("\nEigenvalues of Ac:") +print(eigvals_Ac)