Skip to content

Commit

Permalink
Fix eigenvector calculation for subdim=2 case in SymmetricEigen
Browse files Browse the repository at this point in the history
  • Loading branch information
CattleProdigy committed Jul 21, 2023
1 parent e2a32af commit 5291735
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/linalg/symmetric_eigen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,21 @@ where
diag[start + 1].clone(),
);
let eigvals = m.eigenvalues().unwrap();
let basis = Vector2::new(
eigvals.x.clone() - diag[start + 1].clone(),
off_diag[start].clone(),
);

// Choose the basis least likely to experience cancellation
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 + 1] = eigvals[1].clone();
Expand Down

0 comments on commit 5291735

Please sign in to comment.