Files
ovf/core/utils.py

33 lines
1.4 KiB
Python
Raw Normal View History

2025-09-15 11:41:55 -04:00
import numpy as np
from dataclasses import dataclass
2025-09-17 02:45:10 -04:00
from typing import List, Dict, Tuple
2025-09-15 11:41:55 -04:00
def cond_row_inf(A, use_pinv=True):
"""行条件数 κ∞(A) = ||A||∞ * ||A^{-1}||∞;矩形阵用广义逆。"""
A = np.asarray(A)
Ainv = np.linalg.pinv(A) if (use_pinv or A.shape[0] != A.shape[1]) else np.linalg.inv(A)
return np.linalg.norm(A, ord=np.inf) * np.linalg.norm(Ainv, ord=np.inf)
def cond_col_one(A, use_pinv=True):
"""列条件数 κ1(A) = ||A||1 * ||A^{-1}||1矩形阵用广义逆。"""
A = np.asarray(A)
Ainv = np.linalg.pinv(A) if (use_pinv or A.shape[0] != A.shape[1]) else np.linalg.inv(A)
return np.linalg.norm(A, ord=1) * np.linalg.norm(Ainv, ord=1)
2025-09-17 02:45:10 -04:00
def generate_starting_poles(n_pairs: int, beta_min: float, beta_max: float, alpha_scale: float = 0.01):
2025-09-15 11:41:55 -04:00
"""
2025-09-17 02:45:10 -04:00
仅生成复共轭对: p = -alpha + j beta, p*
n_pairs: 复对数量 (总极点数 = 2*n_pairs)
beta_min,beta_max: 想要覆盖的虚部范围 (单位: rad/s)
alpha_scale: alpha = alpha_scale * beta (文中 {α_p}=0.01{β_p})
返回: list[complex] (正虚部先, 后跟共轭)
2025-09-15 11:41:55 -04:00
"""
2025-09-17 02:45:10 -04:00
betas = 2*np.pi*np.linspace(beta_min, beta_max, n_pairs)
poles = []
for b in betas:
alpha = alpha_scale * b
p = -alpha + 1j * b
poles += [p, np.conj(p)]
print(f"生成 {len(poles)} 个初始极点 (复对) {poles}]")
return poles