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 $A get 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 $eval and 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 $A get destroyed 😭 and the strict upper triangular part is not referenced. Eigenvalues go in the vector $eval and 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 $A are 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 $eval and 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 $A are 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 to gsl_eigen_nonsymm 🌈
    • If $compute_t is set to 1, the full Schur form T will be computed by gsl_eigen_nonsymm.
    • If it's set to 0, T will not be computed β€” and that's the default setting, iykyk.
    • If $balance is set to 1, 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.
  • gsl_eigen_nonsymm($A, $eval, $w) β€” computes the eigenvalues of the real nonsymmetric matrix $A and stores them in the vector $eval. If T is desired, it gets stored in the upper portion of $A on output. Otherwise, on output, the diagonal of $A will contain the 1-by-1 real eigenvalues and 2-by-2 complex conjugate eigenvalue systems, and the rest of $A is 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 to gsl_eigen_nonsymm except it also computes the Schur vectors and stores them into the $Z matrix πŸŽ€
  • 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 calls gsl_eigen_nonsymm to compute the eigenvalues, Schur form T, and Schur vectors. Then it finds eigenvectors of T and backtransforms them using the Schur vectors. The Schur vectors get destroyed in the process 😭 but you can save them by using gsl_eigen_nonsymmv_Z. The computed eigenvectors are normalized to have unit magnitude πŸ‘‘ On output, the upper portion of $A contains the Schur form T. If gsl_eigen_nonsymm fails, no eigenvectors are computed and an error code is returned (1). Important: $eval is a complex vector and $evec is a complex matrix πŸ’œ
  • gsl_eigen_nonsymmv_Z($A, $eval, $evec, $Z, $w) β€” identical to gsl_eigen_nonsymmv except it also saves the Schur vectors into the $Z matrix πŸ¦‹

  • 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, $B contains its Cholesky decomposition and $A is 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 $eval vector and $evec matrix respectively. The computed eigenvectors are normalized to have unit magnitude πŸ‘‘ On output, $B contains its Cholesky decomposition and A is destroyed. (Yes, the source says A there 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 $eval vector. On output, $B contains its Cholesky decomposition and $A is 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 $eval vector and $evec matrix respectively. The computed eigenvectors are normalized to have unit magnitude πŸ‘‘ On output, $B contains its Cholesky decomposition and $A is 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 to gsl_eigen_gen πŸ’œ buckle up, this one has lore:
    • If $compute_s is set to 1, the full Schur form S will be computed by gsl_eigen_gen.
    • If it's set to 0, S will not be computed β€” and that's the default setting.
    • S is 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_t is set to 1, the full Schur form T will be computed by gsl_eigen_gen.
    • If it's set to 0, T will not be computed β€” again, the default setting.
    • T is an upper triangular matrix with non-negative elements on its diagonal. Any 2-by-2 blocks in S will correspond to a 2-by-2 diagonal block in T πŸ¦‹
    • The $balance parameter is currently ignored, since generalized balancing is not yet implemented πŸ‘€ so don't @ her about it.
  • 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 $alpha is complex and $beta is real, and both are vectors. The elements of $beta are normalized to be non-negative ✨ If S is desired, it's stored in $A on output. If T is desired, it's stored in $B on output. The ordering of eigenvalues in ($alpha, $beta) follows the ordering of the diagonal blocks in the Schur forms S and T πŸ‘‘ 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 to gsl_eigen_gen except it also computes the left and right Schur vectors and stores them into the $Q matrix and $Z matrix 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 $alpha is a complex vector and $beta a real vector, and the eigenvectors are stored in $evec complex matrix. It first calls gsl_eigen_gen to compute the eigenvalues, Schur forms, and
  • gsl_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 using gsl_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 if gsl_eigen_gen fails? No eigenvectors for you, and an error code of 1 gets returned. πŸ™ˆ
  • gsl_eigen_genv_QZ($A, $B, $alpha, $beta, $evec, $Q, $Z, $w) β€” literally the same energy as gsl_eigen_genv, except it also computes the left and right Schur vectors and stores them into $Q and $Z matrices 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 $eval and 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 $eval and the corresponding real eigenvectors in the columns of $evec based 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 $eval and the corresponding complex eigenvectors stored in the columns of the complex matrix $evec into ascending or descending order according to $sort_type. Warning though bestie, only $GSL_EIGEN_SORT_ABS_ASC and $GSL_EIGEN_SORT_ABS_DESC are 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 $eval and the corresponding real eigenvectors in the columns of $evec according 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 $eval and the corresponding real eigenvectors in the columns of $evec according 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 $eval and the corresponding complex eigenvectors in the columns of the complex matrix $evec into ascending or descending order according to $sort_type. And again: only $GSL_EIGEN_SORT_ABS_ASC and $GSL_EIGEN_SORT_ABS_DESC are supported, because those eigenvalues are complex. That's the rule, we don't make it. πŸ’€
  • gsl_schur_gen_eigvals
  • gsl_schur_solve_equation
  • gsl_schur_solve_equation_z
  • gsl_eigen_jacobi
  • gsl_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 (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