normalize eigenvector for numerical running purposes

This commit is contained in:
Elizabeth Hunt 2023-11-27 10:16:47 -07:00
parent aa77d733b0
commit 09dd5c5eb2
Signed by: simponic
GPG Key ID: 52B3774857EB24B1
2 changed files with 5 additions and 1 deletions

View File

@ -31,6 +31,10 @@ double dominant_eigenvalue(Matrix_double *m, Array_double *v, double tolerance,
while (error >= tolerance && (--iter) > 0) {
Array_double *eigenvector_2 = m_dot_v(m, eigenvector_1);
Array_double *normalized_eigenvector_2 =
scale_v(eigenvector_2, 1.0 / linf_norm(eigenvector_2));
free_vector(eigenvector_2);
eigenvector_2 = normalized_eigenvector_2;
Array_double *mx = m_dot_v(m, eigenvector_2);
double new_lambda =

View File

@ -25,7 +25,7 @@ UTEST(eigen, leslie_matrix_dominant_eigenvalue) {
Array_double *felicity = InitArray(double, {0.0, 1.5, 0.8});
Array_double *survivor_ratios = InitArray(double, {0.8, 0.55});
Matrix_double *leslie = leslie_matrix(survivor_ratios, felicity);
Array_double *v_guess = InitArrayWithSize(double, 3, 1.0);
Array_double *v_guess = InitArrayWithSize(double, 3, 2.0);
double tolerance = 0.0001;
uint64_t max_iterations = 64;