fix: Canon modal Schur fallback for ill-conditioned systems#24
Merged
fix: Canon modal Schur fallback for ill-conditioned systems#24
Conversation
canonModal used eigendecomposition to build the transformation matrix T. When eigenvalues are nearly repeated (e.g. triple pole at ≈-0.01 from 1e6*s³+30000*s²+300*s+1), eigenvectors become nearly parallel, giving κ(T)≈8e13. Inverting T amplifies B entries to ~1e14, destroying the frequency response. Now checks κ(T)>1e12 (matching eigdecomp.go threshold) and falls back to ordered real Schur form (DGEES+DTREXC), which is numerically stable for near-repeated eigenvalues. Reported via python-control/python-control#1077 — the MIMO system there triggers the ill-conditioning. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Three defensive checks inspired by python-control edge cases: 1. StateSpace() rejects improper transfer functions (num deg > den deg) before conversion, preventing silent wrong results. (pc#235) 2. Kalman, Lqg, H2Syn, HinfSyn reject descriptor systems (E != nil) since standard CARE/DARE ignore E, producing wrong results. (pc#36) 3. Care/Dare validate Q is positive semi-definite via Cholesky on Q + ε‖Q‖nI. Negative/indefinite Q was silently accepted. (pc#252) R positive-definiteness was already caught by Cholesky. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Three fixes from auditing merged python-control PRs: 1. canon.go: Replace explicit Tinv computation with lu.SolveTo() in both canonModalEig and canonCompanion. Avoids forming the inverse matrix, reducing numerical error amplification. (pc PR#101) 2. convert.go: matchedGainFallback used cmplx.Abs ratio which discards sign, producing wrong gain for systems with negative DC gain. Now uses real(contVal/discVal) matching the non-fallback path. (pc PR#951) 3. ctrbobsv.go: IsStabilizable continuous-time check used zero tolerance (real(v) >= 0), so roundoff eigenvalue at Re=1e-16 was falsely classified as unstable. Now uses relative tolerance consistent with the discrete-time check. (pc PR#345) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Owner
Author
Benchmark Results (benchstat, 5 runs, Apple M1 Pro)Execution time (sec/op)
Memory (B/op)
Analysis
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Hardening fixes from auditing python-control issues and merged PRs for numerical edge cases.
Commit 1 — Canon modal Schur fallback:
canonModalproduced wrong frequency responses for near-repeated eigenvalues (κ(T)≈8e13)Commit 2 — Input validation hardening:
StateSpace()rejects improper TFs (num deg > den deg) — python-control#235Kalman/Lqg/H2Syn/HinfSynreject descriptor systems (E≠nil) — python-control#36Care/Darevalidate Q is PSD via shifted Cholesky — python-control#252Commit 3 — Numerical hardening from PR audit:
lu.SolveTo()— avoids forming inverse (pc PR#101)cmplx.Absratio →real(contVal/discVal)(pc PR#951)Test plan
🤖 Generated with Claude Code