add lizfcm api doc entry for least dominant eigenvalue

This commit is contained in:
Elizabeth Hunt 2023-11-27 13:32:05 -07:00
parent 2a35f68ac4
commit 76e00682b2
Signed by: simponic
GPG Key ID: 52B3774857EB24B1
3 changed files with 60 additions and 0 deletions

View File

@ -1035,6 +1035,52 @@ double dominant_eigenvalue(Matrix_double *m, Array_double *v, double tolerance,
return lambda; return lambda;
} }
#+END_SRC #+END_SRC
*** ~least_dominant_eigenvalue~
+ Author: Elizabeth Hunt
+ Name: ~least_dominant_eigenvalue~
+ Location: ~src/eigen.c~
+ Input: a pointer to an invertible matrix ~m~, an initial eigenvector guess ~v~ (that is non
zero or orthogonal to an eigenvector with the dominant eigenvalue), a ~tolerance~ and
~max_iterations~ that act as stop conditions
+ Output: the least dominant eigenvalue with the lowest magnitude, approximated with the Inverse
Power Iteration Method
#+BEGIN_SRC c
double least_dominant_eigenvalue(Matrix_double *m, Array_double *v,
double tolerance, size_t max_iterations) {
assert(m->rows == m->cols);
assert(m->rows == v->size);
double shift = 0.0;
Matrix_double *m_c = copy_matrix(m);
for (size_t y = 0; y < m_c->rows; ++y)
m_c->data[y]->data[y] = m_c->data[y]->data[y] - shift;
double error = tolerance;
size_t iter = max_iterations;
double lambda = shift;
Array_double *eigenvector_1 = copy_vector(v);
while (error >= tolerance && (--iter) > 0) {
Array_double *eigenvector_2 = solve_matrix_lu_bsubst(m_c, 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 =
v_dot_v(mx, eigenvector_2) / v_dot_v(eigenvector_2, eigenvector_2);
error = fabs(new_lambda - lambda);
lambda = new_lambda;
free_vector(eigenvector_1);
eigenvector_1 = eigenvector_2;
}
return lambda;
}
#+END_SRC
*** ~leslie_matrix~ *** ~leslie_matrix~
+ Author: Elizabeth Hunt + Author: Elizabeth Hunt
+ Name: ~leslie_matrix~ + Name: ~leslie_matrix~

View File

@ -12,4 +12,16 @@ See ~UTEST(eigen, leslie_matrix_dominant_eigenvalue)~ in ~test/eigen.t.c~
and the entry ~Eigen-Adjacent -> leslie_matrix~ in the LIZFCM API and the entry ~Eigen-Adjacent -> leslie_matrix~ in the LIZFCM API
documentation. documentation.
* Question Three * Question Three
See ~UTEST(eigen, least_dominant_eigenvalue)~ in ~test/eigen.t.c~ which
finds the least dominant eigenvalue on the matrix:
\begin{bmatrix}
2 & 2 & 4 \\
1 & 4 & 7 \\
0 & 2 & 6
\end{bmatrix}
which has eigenvalues: $5 + \sqrt{17}, 2, 5 - \sqrt{17}$ and should produce $\sqrt{17}$.
See also the entry ~Eigen-Adjacent -> least_dominant_eigenvalue~ in the LIZFCM API
documentation.

View File

@ -14,5 +14,7 @@ x^{k + 1} \rightarrow Ax^k
} }
x_1[i] = sum / a[i][i]; x_1[i] = sum / a[i][i];
} }
err = 0.0;
} }
#+END_SRC #+END_SRC