normalize eigenvector for numerical running purposes
This commit is contained in:
parent
aa77d733b0
commit
09dd5c5eb2
@ -31,6 +31,10 @@ double dominant_eigenvalue(Matrix_double *m, Array_double *v, double tolerance,
|
|||||||
|
|
||||||
while (error >= tolerance && (--iter) > 0) {
|
while (error >= tolerance && (--iter) > 0) {
|
||||||
Array_double *eigenvector_2 = m_dot_v(m, eigenvector_1);
|
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);
|
Array_double *mx = m_dot_v(m, eigenvector_2);
|
||||||
double new_lambda =
|
double new_lambda =
|
||||||
|
@ -25,7 +25,7 @@ UTEST(eigen, leslie_matrix_dominant_eigenvalue) {
|
|||||||
Array_double *felicity = InitArray(double, {0.0, 1.5, 0.8});
|
Array_double *felicity = InitArray(double, {0.0, 1.5, 0.8});
|
||||||
Array_double *survivor_ratios = InitArray(double, {0.8, 0.55});
|
Array_double *survivor_ratios = InitArray(double, {0.8, 0.55});
|
||||||
Matrix_double *leslie = leslie_matrix(survivor_ratios, felicity);
|
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;
|
double tolerance = 0.0001;
|
||||||
uint64_t max_iterations = 64;
|
uint64_t max_iterations = 64;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user