Fix eigenvector calculation for subdim=2 case in SymmetricEigen

This commit is contained in:
Paul Jakob Schroeder 2023-02-20 12:46:27 -05:00
parent e2a32af5c3
commit 52917353fd
1 changed files with 15 additions and 4 deletions

View File

@ -199,10 +199,21 @@ where
diag[start + 1].clone(), diag[start + 1].clone(),
); );
let eigvals = m.eigenvalues().unwrap(); let eigvals = m.eigenvalues().unwrap();
let basis = Vector2::new(
eigvals.x.clone() - diag[start + 1].clone(), // Choose the basis least likely to experience cancellation
off_diag[start].clone(), let basis = if (eigvals.x.clone() - diag[start + 1].clone()).abs()
); > (eigvals.x.clone() - diag[start].clone()).abs()
{
Vector2::new(
eigvals.x.clone() - diag[start + 1].clone(),
off_diag[start].clone(),
)
} else {
Vector2::new(
off_diag[start].clone(),
eigvals.x.clone() - diag[start].clone(),
)
};
diag[start] = eigvals[0].clone(); diag[start] = eigvals[0].clone();
diag[start + 1] = eigvals[1].clone(); diag[start + 1] = eigvals[1].clone();