Math::GSL::Eigen(3pm)
β¨ Math::GSL::Eigen(3pm) β¨
okay bestie, so this one lives in the User Contributed Perl Documentation section of the manual, and it's about Math::GSL::Eigen β literally the vibe where Perl meets GSL and they become besties π
πΈ NAME πΈ
Math::GSL::Eigen β functions for computing eigenvalues and eigenvectors of matrices π
like. that's it. that's the whole thing. it does the eigen stuff. the eigenvalues AND the eigenvectors. for matrices. slay π
π¦ SYNOPSIS π¦
the whole entire setup is one line, no cap:
use Math::GSL::Eigen qw/:all/;
that's it, that's the ritual β¨ you pull in :all and every function in the module comes running like you called their name in the group chat π«Ά
π DESCRIPTION π
okay so here's the deal: this module is your plug for eigenvalues and eigenvectors of matrices π
and fr fr, here is a list of all the functions included in this module : π
(keep reading bestie, the list is coming in the next part π§)
gsl_eigen_symm_alloc($n)β bestie this hands you back a workspace for computing the eigenvalues of n-by-n real symmetric matrices π«Ά like it's literally just the lil scratchpad you gotta have.gsl_eigen_symm_free($w)β frees all the memory that was holding onto the workspace$wπ say bye, it's not coming back.gsl_eigen_symm($A, $eval, $w)β computes the eigenvalues of the real symmetric matrix$A. You must give it extra workspace of the right size in$w, no skipping that part. Heads up tho: the diagonal and lower triangular part of$Aget destroyed during the computation π but the strict upper triangular part? Not referenced at all, untouched, unbothered, living its life. The eigenvalues land in the vector$evaland ngl they come out unordered.gsl_eigen_symmv_alloc($n)β returns a workspace for computing eigenvalues and eigenvectors of n-by-n real symmetric matrices β¨ the glow-up version of the one above.gsl_eigen_symmv_free($w)β frees the memory associated with the workspace$wπgsl_eigen_symmv($A, $eval, $evec, $w)β computes both the eigenvalues and the eigenvectors of the real symmetric matrix$A. Extra workspace of the right size goes in$w, always. Same deal as before: the diagonal and lower triangular part of$Aget destroyed π and the strict upper triangular part is not referenced. Eigenvalues go in the vector$evaland they're unordered fr fr. The matching eigenvectors get stored in the columns of the matrix$evecπ
gsl_eigen_herm_alloc($n)β returns a workspace for computing eigenvalues of n-by-n complex hermitian matrices π (yes the complex ones, we're fancy now).gsl_eigen_herm_free($w)β frees the memory associated with the workspace$wπ¦gsl_eigen_herm($A, $eval, $w)β computes the eigenvalues of the complex hermitian matrix$A. Additional workspace of the appropriate size must be provided in$w. The diagonal and lower triangular part of$Aare destroyed during the computation π but the strict upper triangular part is not referenced. Also: the imaginary parts of the diagonal are assumed to be zero and are not referenced β so don't come crying if you put non-zero imaginaries there, bestie. Eigenvalues go in the vector$evaland are unordered.gsl_eigen_hermv_alloc($n)β returns a workspace for computing eigenvalues and eigenvectors of n-by-n complex hermitian matrices πΈgsl_eigen_hermv_free($w)β frees the memory associated with the workspace$wπgsl_eigen_hermv($A, $eval, $evec, $w)β computes the eigenvalues and eigenvectors of the complex hermitian matrix$A. Additional workspace of the appropriate size must be provided in$w. The diagonal and lower triangular part of$Aare destroyed during the computation, but the strict upper triangular part is not referenced. The imaginary parts of the diagonal are assumed to be zero and are not referenced. Eigenvalues land in$eval, unordered as always. The corresponding complex eigenvectors get stored in the columns of the matrix$evecπ₯
gsl_eigen_francis_alloc($n)β π (no description in the source, she's mysterious like that)gsl_eigen_francis_free($w)β frees the memory associated with the workspace$wπgsl_eigen_francis_Tβ π (no description given)gsl_eigen_francisβ β¨ (no description given)gsl_eigen_francis_Zβ π¦ (no description given)
gsl_eigen_nonsymm_alloc($n)β returns a workspace for computing eigenvalues of n-by-n real nonsymmetric matrices π€ not symmetric, not hermitian, just out here doing its own thing.gsl_eigen_nonsymm_free($w)β frees the memory associated with the workspace$wπgsl_eigen_nonsymm_params($compute_t, $balance, $w)β sets some parameters that determine how the eigenvalue problem gets solved in subsequent calls togsl_eigen_nonsymmπ- If
$compute_tis set to1, the full Schur formTwill be computed bygsl_eigen_nonsymm. - If it's set to
0,Twill not be computed β and that's the default setting, iykyk. - If
$balanceis set to1, a balancing transformation is applied to the matrix before computing eigenvalues. This transformation is designed to make the rows and columns of the matrix have comparable norms, and can result in more accurate eigenvalues for matrices whose entries vary widely in magnitude. Slay.
- If
gsl_eigen_nonsymm($A, $eval, $w)β computes the eigenvalues of the real nonsymmetric matrix$Aand stores them in the vector$eval. IfTis desired, it gets stored in the upper portion of$Aon output. Otherwise, on output, the diagonal of$Awill contain the 1-by-1 real eigenvalues and 2-by-2 complex conjugate eigenvalue systems, and the rest of$Ais destroyed π In rare cases, this function may fail to find all eigenvalues. If that happens, an error code is returned (1) and the number of converged eigenvalues is stored in$w->{n_evals}. The converged eigenvalues are stored in the beginning of$evalπ«Άgsl_eigen_nonsymm_Z($A, $eval, $Z, $w)β identical togsl_eigen_nonsymmexcept it also computes the Schur vectors and stores them into the$Zmatrix πgsl_eigen_nonsymmv_alloc($n)β allocates a workspace for computing eigenvalues and eigenvectors of n-by-n real nonsymmetric matrices β¨gsl_eigen_nonsymmv_free($w)β frees the memory associated with the workspace$wπgsl_eigen_nonsymmv($A, $eval, $evec, $w)β computes eigenvalues and right eigenvectors of the n-by-n real nonsymmetric matrix$A. The way it works: first it callsgsl_eigen_nonsymmto compute the eigenvalues, Schur formT, and Schur vectors. Then it finds eigenvectors ofTand backtransforms them using the Schur vectors. The Schur vectors get destroyed in the process π but you can save them by usinggsl_eigen_nonsymmv_Z. The computed eigenvectors are normalized to have unit magnitude π On output, the upper portion of$Acontains the Schur formT. Ifgsl_eigen_nonsymmfails, no eigenvectors are computed and an error code is returned (1). Important:$evalis a complex vector and$evecis a complex matrix πgsl_eigen_nonsymmv_Z($A, $eval, $evec, $Z, $w)β identical togsl_eigen_nonsymmvexcept it also saves the Schur vectors into the$Zmatrix π¦
gsl_eigen_gensymm_alloc($n)β allocates a workspace for computing eigenvalues of n-by-n real generalized symmetric-definite eigensystems πΈgsl_eigen_gensymm_free($w)β frees the memory associated with the workspace$wπgsl_eigen_gensymm($A, $B, $eval, $w)β computes the eigenvalues of the real generalized symmetric-definite matrix pair ($A,$B), and stores them in the vector$eval. On output,$Bcontains its Cholesky decomposition and$Ais destroyed πgsl_eigen_gensymm_standardizeβ π (no description given)gsl_eigen_gensymmv_alloc($n)β allocates a workspace for computing eigenvalues and eigenvectors of n-by-n real generalized symmetric-definite eigensystems β¨gsl_eigen_gensymmv_free($w)β frees the memory associated with the workspace$wπgsl_eigen_gensymmv($A, $B, $eval, $evec, $w)β computes the eigenvalues and eigenvectors of the real generalized symmetric-definite matrix pair ($A,$B), and stores them in the$evalvector and$evecmatrix respectively. The computed eigenvectors are normalized to have unit magnitude π On output,$Bcontains its Cholesky decomposition andAis destroyed. (Yes, the source saysAthere without the dollar sign β we're keeping it exactly as written, bestie, no editing the sacred text π)
gsl_eigen_genherm_alloc($n)β allocates a workspace for computing eigenvalues of n-by-n complex generalized hermitian-definite eigensystems πgsl_eigen_genherm_free($w)β frees the memory associated with the workspace$wπ«Άgsl_eigen_genherm($A, $B, $eval, $w)β computes the eigenvalues of the complex generalized hermitian-definite matrix pair ($A,$B), and stores them in the$evalvector. On output,$Bcontains its Cholesky decomposition and$Ais destroyed πgsl_eigen_genherm_standardizeβ π¦ (no description given)gsl_eigen_genhermv_alloc($n)β allocates a workspace for computing eigenvalues and eigenvectors of n-by-n complex generalized hermitian-definite eigensystems βgsl_eigen_genhermv_free($w)β frees the memory associated with the workspace$wπgsl_eigen_genhermv($A, $B, $eval, $evec, $w)β computes the eigenvalues and eigenvectors of the complex generalized hermitian-definite matrix pair ($A,$B), and stores them in the$evalvector and$evecmatrix respectively. The computed eigenvectors are normalized to have unit magnitude π On output,$Bcontains its Cholesky decomposition and$Ais destroyed π
gsl_eigen_gen_alloc($n)β allocates a workspace for computing eigenvalues of n-by-n real generalized nonsymmetric eigensystems πΈgsl_eigen_gen_free($w)β frees the memory associated with the workspace$wβ¨gsl_eigen_gen_params($compute_s, $compute_t, $balance, $w)β sets some parameters which determine how the eigenvalue problem is solved in subsequent calls togsl_eigen_genπ buckle up, this one has lore:- If
$compute_sis set to1, the full Schur formSwill be computed bygsl_eigen_gen. - If it's set to
0,Swill not be computed β and that's the default setting. Sis a quasi upper triangular matrix with 1-by-1 and 2-by-2 blocks on its diagonal. The 1-by-1 blocks correspond to real eigenvalues, and the 2-by-2 blocks correspond to complex eigenvalues π- If
$compute_tis set to1, the full Schur formTwill be computed bygsl_eigen_gen. - If it's set to
0,Twill not be computed β again, the default setting. Tis an upper triangular matrix with non-negative elements on its diagonal. Any 2-by-2 blocks inSwill correspond to a 2-by-2 diagonal block inTπ¦- The
$balanceparameter is currently ignored, since generalized balancing is not yet implemented π so don't @ her about it.
- If
gsl_eigen_gen($A, $B, $alpha, $beta, $w)β computes the eigenvalues of the real generalized nonsymmetric matrix pair ($A,$B), and stores them as pairs in ($alpha,$beta), where$alphais complex and$betais real, and both are vectors. The elements of$betaare normalized to be non-negative β¨ IfSis desired, it's stored in$Aon output. IfTis desired, it's stored in$Bon output. The ordering of eigenvalues in ($alpha,$beta) follows the ordering of the diagonal blocks in the Schur formsSandTπ In rare cases, this function may fail to find all eigenvalues. If that occurs, an error code is returned (1) πgsl_eigen_gen_QZ($A, $B, $alpha, $beta, $Q, $Z, $w)β identical togsl_eigen_genexcept it also computes the left and right Schur vectors and stores them into the$Qmatrix and$Zmatrix respectively πgsl_eigen_genv_alloc($n)β allocates a workspace for computing eigenvalues and eigenvectors of n-by-n real generalized nonsymmetric eigensystems πgsl_eigen_genv_free($w)β frees the memory associated with the workspace$wπ«Άgsl_eigen_genv($A, $B, $alpha, $beta, $evec, $w)β computes eigenvalues and right eigenvectors of the n-by-n real generalized nonsymmetric matrix pair ($A,$B). The eigenvalues are stored in ($alpha,$beta) where$alphais a complex vector and$betaa real vector, and the eigenvectors are stored in$eveccomplex matrix. It first callsgsl_eigen_gento compute the eigenvalues, Schur forms, andgsl_eigen_genv($A, $B, $alpha, $beta, $evec, $w)β okay bestie, so this one takes the matrix pair (A, B) and pulls the right eigenvectors out of the generalized eigenproblem, dropping them into the columns of$evec. Under the hood it does the whole routine β QZ it first to get the generalized Schur vectors, then it finds the eigenvectors of the Schur forms and backtransforms them using those Schur vectors. Heads up though: the Schur vectors get destroyed in the process π, but you can save them by usinggsl_eigen_genv_QZ. The eigenvectors it computes get normalized to have unit magnitude, as they should π . On output,($A, $B)contains the generalized Schur form(S, T). And ifgsl_eigen_genfails? No eigenvectors for you, and an error code of1gets returned. πgsl_eigen_genv_QZ($A, $B, $alpha, $beta, $evec, $Q, $Z, $w)β literally the same energy asgsl_eigen_genv, except it also computes the left and right Schur vectors and stores them into$Qand$Zmatrices respectively. Didn't destroy them this time, we're thriving β¨gsl_eigen_symmv_sort($eval, $evec, $sort_type)β this one simultaneously sorts the eigenvalues chillin' in the vector$evaland the corresponding real eigenvectors stored in the columns of the matrix$evec, according to whatever you passed as$sort_type, which is one of the constants included in this module. πgsl_eigen_hermv_sort($eval, $evec, $sort_type)β same deal, same glow-up: it simultaneously sorts the eigenvalues in$evaland the corresponding real eigenvectors in the columns of$evecbased on$sort_type, which is one of the constants included in this module. πgsl_eigen_nonsymmv_sort($eval, $evec, $sort_type)β this one simultaneously sorts the eigenvalues in$evaland the corresponding complex eigenvectors stored in the columns of the complex matrix$evecinto ascending or descending order according to$sort_type. Warning though bestie, only$GSL_EIGEN_SORT_ABS_ASCand$GSL_EIGEN_SORT_ABS_DESCare supported here β because the eigenvalues are complex, that's just how it is, no cap πgsl_eigen_gensymmv_sort($eval, $evec, $sort_type)β simultaneously sorts the eigenvalues in$evaland the corresponding real eigenvectors in the columns of$evecaccording to$sort_type, which is one of the constants included in this module. icon behavior fr fr π¦gsl_eigen_genhermv_sort($eval, $evec, $sort_type)β yep, you guessed the vibe: simultaneously sorts the eigenvalues in$evaland the corresponding real eigenvectors in the columns of$evecaccording to$sort_type, which is one of the constants included in this module. πΈgsl_eigen_genv_sort($eval, $evec, $sort_type)β simultaneously sorts the eigenvalues in$evaland the corresponding complex eigenvectors in the columns of the complex matrix$evecinto ascending or descending order according to$sort_type. And again: only$GSL_EIGEN_SORT_ABS_ASCand$GSL_EIGEN_SORT_ABS_DESCare supported, because those eigenvalues are complex. That's the rule, we don't make it. πgsl_schur_gen_eigvalsgsl_schur_solve_equationgsl_schur_solve_equation_zgsl_eigen_jacobigsl_eigen_invert_jacobi
This module also includes these constants, bestie, memorize the lore β¨ :
$GSL_EIGEN_SORT_VAL_ASCβ ascending order in numerical value$GSL_EIGEN_SORT_VAL_DESCβ descending order in numerical value$GSL_EIGEN_SORT_ABS_ASCβ ascending order in magnitude$GSL_EIGEN_SORT_ABS_DESCβ descending order in magnitude
For more information on the functions, we refer you to the GSL official documentation: <http://www.gnu.org/software/gsl/manual/html_node/> β go read it, iykyk π«Ά
π EXAMPLES π
This example shows how to use the gsl_eigen_symmv functions to find the eigenvalues and eigenvectors of a matrix. Main character energy, honestly π
use Math::GSL::Vector qw/:all/;
use Math::GSL::Matrix qw/:all/;
use Math::GSL::Eigen qw/:all/;
my $w = gsl_eigen_symmv_alloc(2);
my $m = gsl_matrix_alloc(2,2);
gsl_matrix_set($m, 0, 0, 2);
gsl_matrix_set($m, 0, 1, 1);
gsl_matrix_set($m, 1, 0, 1);
gsl_matrix_set($m, 1, 1, 2);
my $eval = gsl_vector_alloc(2);
my $evec = gsl_matrix_alloc(2,2);
gsl_eigen_symmv($m, $eval, $evec, $w);
gsl_eigen_gensymmv_sort($eval, $evec, $GSL_EIGEN_SORT_ABS_ASC);
print "The first eigenvalue is : " . gsl_vector_get($eval, 0) . "\n";
print "The second eigenvalue is : " . gsl_vector_get($eval, 1) . "\n";
my $x = gsl_matrix_get($evec, 0, 0);
my $y = gsl_matrix_get($evec, 0, 1);
print "The first eigenvector is [$x, $y] \n";
$x = gsl_matrix_get($evec, 1, 0);
$y = gsl_matrix_get($evec, 1, 1);
print "The second eigenvector is [$x, $y] \n";
π AUTHORS π
Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
π COPYRIGHT AND LICENSE π
Copyright (C) 2008-2024 Jonathan "Duke" Leto and Thierry Moisan
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
aaand that's the whole page bestie, you ate it up π this little masterpiece is perl v5.42.3, dated 2026-08-20, and it's the Math::GSL::Eigen(3pm) page β go forth and diagonalize πβ¨
π¦ where this page comes from
- ubuntu stonking: libmath-gsl-perl 0.49-1build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms