Skip to content

Instantly share code, notes, and snippets.

@mookerji
Created May 6, 2021 03:44
Show Gist options
  • Save mookerji/b41dc3f796159ceb670bc1f7f81f779c to your computer and use it in GitHub Desktop.
Save mookerji/b41dc3f796159ceb670bc1f7f81f779c to your computer and use it in GitHub Desktop.
Endless eigenvalues
from numpy import linalg as alg
import numpy as np
arr = np.array([
0.0, 1., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.,
-6.24999997e+10, -1.263125e+12, -6.82847529e+12, -2.03857854e+12, -7.35980421e+11, -7.86214175e+10,
-1.05601812e+10, -154605568., -4472637., -33713.0078, -440.200012,
])
mat = arr.reshape(11,11)
for i in alg.eigvals(mat.astype('float64')):
print(i)
print('')
for i in alg.eigvals(mat.astype('float32')):
print(i)
use nalgebra::DMatrix;
fn finishes() {
#[rustfmt::skip]
let m: DMatrix<f64> = DMatrix::from_row_slice(
11,
11,
&[
0.0, 1., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.,
-6.24999997e+10, -1.263125e+12, -6.82847529e+12, -2.03857854e+12, -7.35980421e+11, -7.86214175e+10,
-1.05601812e+10, -154605568., -4472637., -33713.0078, -440.200012,
],
);
let p = m.complex_eigenvalues();
for v in p.into_iter() {
println!("{:?}", v);
}
}
fn doesnt() {
#[rustfmt::skip]
let m: DMatrix<f32> = DMatrix::from_row_slice(
11,
11,
&[
0.0, 1., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.,
-6.24999997e+10, -1.263125e+12, -6.82847529e+12, -2.03857854e+12, -7.35980421e+11, -7.86214175e+10,
-1.05601812e+10, -154605568., -4472637., -33713.0078, -440.200012,
],
);
let p = m.complex_eigenvalues();
for v in p.into_iter() {
println!("{:?}", v);
}
}
fn main() {
finishes();
doesnt();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment