/
Chronos
/
TU_laba
Обзор
Документация
Войти
/
Chronos
/
TU_laba
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
dump/isolated_problem.py
102 строки
4 KB
Chronos
Живо то, что ещё не умерло
28 мар 2025, 21:28
28 мар 2025, 21:28
0f60d9e
Код
Авторство
О чём код?
import numpy as np from full_unimod_lib import * import control as ct from scipy.linalg import solve_sylvester # Точность 10 знаков после запятой A = np.asarray([[ 0. , 0. , 1. , 0. , ], [ 0. , 0. , 0. , 1. ], [ 74.5742543526 , -38.2956276477 ,-11209.2347756249 , 17268.5734104684], [ -114.8868829432 , 101.4493400796 , 17268.6144129691 ,-45746.3549814179]]) B = np.asarray([[ 0. ], [ 0. ], [ 0.950540852 ], [-1.4643750252]]) # controllability_matrix = ct.ctrb(A, B) # cond_number = np.linalg.cond(controllability_matrix) # print("Число обусловленности: ",cond_number) theta = np.asarray([[-1.08489448e-04, 8.71837776e-05, 1.66174164e-02, -4.00990709e-02]]) print(np.linalg.eigvals(A+B@theta)) # import cvxpy as cp # # Define problem dimensions # n = A.shape[0] # Number of states # m = B.shape[1] # Number of inputs # alpha = 1.0 # Desired decay rate (Re(λ) ≤ -alpha) # # # Define convex variables # Q = cp.Variable((n, n), symmetric=True) # Q = P^{-1} # Y = cp.Variable((m, n)) # Y = K * Q (auxiliary variable) # # # Lyapunov LMI constraint (convex in Q and Y) # lyap_constraint = A @ Q + Q @ A.T + B @ Y + Y.T @ B.T + 2 * alpha * Q << 0 # # # Ensure Q is positive definite # Q_positive = Q >> np.eye(n) * 1e-6 # Small regularization for numerical stability # # # Define cost function (minimize control gains) # cost = cp.norm(Y, 'fro') + cp.norm(Q, 'fro') # # # Solve the problem # problem = cp.Problem(cp.Minimize(cost), [lyap_constraint, Q_positive]) # problem.solve(solver=cp.SCS, verbose=True) # # if problem.status == 'optimal': # Q_opt = Q.value # Y_opt = Y.value # K = Y_opt @ np.linalg.inv(Q_opt) # Recover K = Y * Q^{-1} # print("Optimal gain matrix:\n", K) # else: # print("No solution found!") # Исходный спектр матрицы A: # # [-52899.2535523251 -4056.3450752866 0.0066529206 0.0022176483] # Двигаем два неустойчивых корня в -1: # spectra = np.asarray([-1.0,-1.1,-52899.2535523251 , -4056.3450752866]) # theta,Ac = full_unimodal_control_FL(A,B,spectra) # print("Мой метод") # print(theta) # print("Полученный спектр: ",np.linalg.eigvals(Ac)) # print("Желаемый спектр: ",spectra) # НЕ РАБОТАЕТ!!! Видимо слишком большие числа и обратная матрица неправильно считается print("------------------------------------------") # # Аккерман # try: # K = ct.acker(A, B, spectra) # print("Аккерман") # print(K) # print("Полученный спектр: ",np.linalg.eigvals(A+B.dot(K))) # print("Желаемый спектр: ",spectra) # print("------------------------------------------") # except ValueError as err: # print(err) # print("Аккерман не работает!") # print("------------------------------------------") # # Алгоритм Кауцкого # try: # K = ct.place(A, B, spectra) # print("Алгоритм Кауцкого") # print(K) # print("Полученный спектр: ",np.linalg.eigvals(A+B.dot(K))) # print("Желаемый спектр: ",spectra) # print("------------------------------------------") # except ValueError as err: # print(err) # print("Алгоритм Кауцкого не работает!") # print("------------------------------------------") # # # Уравнение Сильвестра # try: # K = ct.place(A, B, spectra) # print("Уравнение Сильвестра") # print(K) # print("Полученный спектр: ",np.linalg.eigvals(A+B.dot(K))) # print("Желаемый спектр: ",spectra) # except ValueError as err: # print(err) # print("Уравнение Сильвестра не работает!")