Math::...Matrix(3pm)
π Math::Cephes::Matrix β bestie edition π
okay so literally the whole vibe of this page is Math::Cephes::Matrix, a Perl interface to the cephes matrix routines, and it's giving "User Contributed Perl Documentation" energy, iykyk. come sit with me, we're doing linear algebra and we're gonna slay it π«Ά
β¨ NAME β¨
Math::Cephes::Matrix β no cap, it's the Perl interface to the cephes matrix routines. that's the whole name. that's her. π
πΈ SYNOPSIS πΈ
use Math::Cephes::Matrix qw(mat);
# 'mat' is a shortcut for Math::Cephes::Matrix->new
my $M = mat([ [1, 2, -1], [2, -3, 1], [1, 0, 3]]);
my $C = mat([ [1, 2, 4], [2, 9, 2], [6, 2, 7]]);
my $D = $M->add($C); # D = M + C
my $Dc = $D->coef;
for (my $i=0; $i<3; $i++) {
print "row $i:\n";
for (my $j=0; $j<3; $j++) {
print "\tcolumn $j: $Dc->[$i]->[$j]\n";
}
}
likeβ¦ mat is right there being a shortcut for Math::Cephes::Matrix->new, and yes the comment says exactly that because we keep the facts bestie, always. π
π¦ DESCRIPTION π¦
So this module is a layer on top of the basic routines in the cephes math library for operations on square matrices. periodt. in everything that follows, a Math::Cephes::Matrix object gets created like this:
my $M = Math::Cephes::Matrix->new($arr_ref);
where $arr_ref is a reference to an array of arrays, exactly like this lil cutie:
$arr_ref = [ [1, 2, -1], [2, -3, 1], [1, 0, 3] ]
which representsβ¦ drumrollβ¦ π«
/ 1 2 -1 \
| 2 -3 1 |
\ 1 0 3 /
look at her. iconic. π
And if you wanna copy a Math::Cephes::Matrix object? obsessed, easy:
my $M_copy = $M->new();
π§ Methods π§
π coef: get coefficients of the matrix
SYNOPSIS:
my $c = $M->coef;
DESCRIPTION:
this returns a reference to an array of arrays containing the coefficients of the matrix. (yes the original says "an reference", we love her, we're not fixing grammar, we're keeping the facts.) π
π clr: set all coefficients equal to a value.
SYNOPSIS:
$M->clr($n);
DESCRIPTION:
this sets all the coefficients of the matrix identically to $n. and if $n isn't given? a default of 0 is used. no thoughts, just zeros. π
β¨ add: add two matrices
SYNOPSIS:
$P = $M->add($N);
DESCRIPTION:
this sets $P equal to $M + $N. simple math, main character energy. π
πΈ sub: subtract two matrices
SYNOPSIS:
$P = $M->sub($N);
DESCRIPTION:
this sets $P equal to $M - $N. she takes away. respectfully. π
π₯ mul: multiply two matrices or a matrix and a vector
SYNOPSIS:
$P = $M->mul($N);
DESCRIPTION:
this sets $P equal to $M * $N. and bestie she is versatile β this method can handle matrix multiplication, when $N is a matrix, as well as matrix-vector multiplication, where $N is an array reference representing a column vector. range. π
π¦ div: divide two matrices
SYNOPSIS:
$P = $M->div($N);
DESCRIPTION:
this sets $P equal to $M * ($N)^(-1). not me reminding you it's multiplication by the inverse, not elemental division β that's just what it says, fr fr. π
π« inv: invert a matrix
SYNOPSIS:
$I = $M->inv();
DESCRIPTION:
this sets $I equal to ($M)^(-1). the inverse arc. she's thriving. β¨
π transp: transpose a matrix
SYNOPSIS:
$T = $M->transp();
DESCRIPTION:
this sets $T equal to the transpose of $M. flip her, she eats. π
π simq: solve simultaneous equations
SYNOPSIS:
my $M = Math::Cephes::Matrix->new([ [1, 2, -1], [2, -3, 1], [1, 0, 3]]);
my $B = [2, -1, 10];
my $X = $M->simq($B);
for (my $i=0; $i<3; $i++) {
print "X[$i] is $X->[$i]\n";
}
where $M is a Math::Cephes::Matrix object, $B is an input array reference, and $X is an output array reference. note who's input and who's output, bestie, that's important. π
DESCRIPTION:
a set of N simultaneous equations may be represented in matrix form as
M X = B
where M is an N x N square matrix and X and B are column vectors of length N. math said "let me make it a vibe" and here we are. π
π eigens: eigenvalues and eigenvectors of a real symmetric matrix
SYNOPSIS:
my $S = Math::Cephes::Matrix->new([ [1, 2, 3], [2, 2, 3], [3, 3, 4]]);
my ($E, $EV1) = $S->eigens();
my $EV = $EV1->coef;
for (my $i=0; $i<3; $i++) {
print "For i=$i, with eigenvalue $E->[$i]\n";
my $v = [];
for (my $j=0; $j<3; $j++) {
$v->[$j] = $EV->[$i]->[$j];
}
print "The eigenvector is @$v\n";
}
where $M is a Math::Cephes::Matrix object representing a real symmetric matrix. $E is an array reference containing the eigenvalues of $M, and $EV is a Math::Cephes::Matrix object representing the eigenvalues, the ith row corresponding to the ith eigenvalue. (yes it says eigenvalues both times up there β we're keeping every word, that's the deal.) π
DESCRIPTION:
if M is an N x N real symmetric matrix, and X is an N component column vector, the eigenvalue problem
M X = lambda X
will in general have N solutions, with X the eigenvectors and lambda the eigenvalues. not one solution, N solutions. she's multidimensional like that. πβ¨
π BUGS π
found a bug? please report any to Randy Kobes <randy@theoryx5.uwinnipeg.ca>. be nice, bestie, he's the one who made this. π«Ά
π COPYRIGHT π
the C code for the Cephes Math Library is Copyright 1984, 1987, 1989, 2002 by Stephen L. Moshier, and is available at http://www.netlib.org/cephes/. direct inquiries to 30 Frost Street, Cambridge, MA 02140. π
the perl interface is copyright 2000, 2002 by Randy Kobes. this library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. free! as in freedom! we love to see it. πΈ
ok that's the whole page, no cap, every flag and every fact is still in there. go do matrices. slay. π
perl v5.42.3 Β· 2026-08-19 Β· and that's the sign-off bestie, generated on that date by that perl, mwah ππ¦
π¦ where this page comes from
- ubuntu stonking: libmath-cephes-perl 0.5308-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