Improvements of Givens rotations
- Dominant language
- Rust
- Stars
- 4.8k
- Forks
- 565
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
while investigating issue #655 ([comment](https://github.com/rustsim/nalgebra/issues/655#issuecomment-546641755)) i have found that the construction of Givens rotation gives slightly different results than other software, regarding precision.
Nalgebra:
```rust
println!("nalgebra: {:?}", GivensRotation::new(5., 3.));
// (GivensRotation { c: 0.8574929257125441, s: 0.5144957554275265 }, 5.830951894845301)
```
Scilab:
```scilab
-->format(20); givens(5,3)
ans =
0.85749292571254432 0.51449575542752657
- 0.51449575542752657 0.85749292571254432
```
Eigen (c++):
```cpp
#include
#include
#include
#include
#include
typedef std::numeric_limits dbl;
int main()
{
std::cout.precision(dbl::max_digits10);
Eigen::JacobiRotation G;
G.makeGivens(5.0, 3.0);
Eigen::Matrix2d i;
i << 1, 0, 0, 1;
i.applyOnTheRight(0, 1, G);
std::cout << "Givens rotation:\n" << i << std::endl;
}
// Output
// Givens rotation:
// 0.85749292571254432 -0.51449575542752657
// 0.51449575542752657 0.85749292571254432
```
[Eigen](https://bitbucket.org/eigen/eigen/src/default/Eigen/src/Jacobi/Jacobi.h) implementation suggests the algorithms written in the [paper](http://www.netlib.org/lapack/lawnspdf/lawn150.pdf) Anderson (2000), Discontinuous Plane Rotations and the Symmetric Eigenvalue Problem. They implement algorithm 4 and 5, while nalgebra seems to implement algorithm 3 in `try_new`, `cancel_y` and `cancel_y` ([code](https://github.com/rustsim/nalgebra/blob/dev/src/linalg/givens.rs#L45)).
I start by saying that the above example does not represent all cases, but maybe it is worthwhile to evaluate if a different algorithm is needed or the current one fits the purpose.
Demo code for both `RealField` and `ComplexField` is at the following [playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f67a0910126949a0e95a99db1e9558ed).
Thank you.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.