Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/Value/Matrix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ Usage:
generates the matrix

[ [ 1, 0, 0, 0 ],
[ 0, 4, 0, 0 ],
[ 0, 3, 0, 0 ],
[ 0, 0, 1, 0 ],
[ 0, 0, 0, 1 ] ]

Expand All @@ -1102,15 +1102,16 @@ Usage:
generates the matrix:

[ [ 1, 0, 0, 0 ],
[ 0, 1, 0, 0 ],
[ 0, -3, 1, 0 ],
[ 0, 1, -3, 0 ],
[ 0, 0, 1, 0 ],
[ 0, 0, 0, 1 ] ]

or if the matrix C<$A> exists then
or if the matrix C<$A> exists of size m by n then

$A->E([3, 4], -5);

will generate the elementary matrix of size number of rows of C<$A>, which multiplies row 3 by -5 and adds to row 4.
will generate the m by m elementary matrix which multiplies row 3 by -5 and adds to row 4.
If $A does not have at least 4 rows, an error is raised.

=back

Expand Down Expand Up @@ -1147,7 +1148,7 @@ sub E {
if (@ij == 1) {
$row[$i] = $k if ($i == $ij[0]);
} elsif (defined $k) {
$row[ $ij[1] ] = $k if ($i == $ij[0]);
$row[ $ij[0] ] = $k if ($i == $ij[1]);
} else {
($row[ $ij[0] ], $row[ $ij[1] ]) = ($row[ $ij[1] ], $row[ $ij[0] ]) if ($i == $ij[0] || $i == $ij[1]);
}
Expand Down
15 changes: 14 additions & 1 deletion t/math_objects/matrix.t
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,21 @@ subtest 'Construct an elementary matrix' => sub {
'Elementary Matrix with row multiple';

my $E3 = Value::Matrix->E(4, [ 3, 2 ], -3);
is $E3->TeX, Matrix([ [ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, -3, 1, 0 ], [ 0, 0, 0, 1 ] ])->TeX,
is $E3->TeX, Matrix([ [ 1, 0, 0, 0 ], [ 0, 1, -3, 0 ], [ 0, 0, 1, 0 ], [ 0, 0, 0, 1 ] ])->TeX,
'Elementary Matrix with row multiple and add';

my $A = Matrix([ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ], [ 9, 10, 11, 12 ], [ 13, 14, 15, 16 ] ]);
is $A->E([ 1, 4 ])->TeX,
Matrix([ [ 0, 0, 0, 1 ], [ 0, 1, 0, 0 ], [ 0, 0, 1, 0 ], [ 1, 0, 0, 0 ] ])->TeX,
'Elementary Matrix from syntax $A->E an existing matrix with a row swap';

is $A->E([2], 5)->TeX,
Matrix([ [ 1, 0, 0, 0 ], [ 0, 5, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 0, 0, 1 ] ])->TeX,
'Elementary Matrix from syntax $A->E an existing matrix with a row multiple';

is $A->E([ 2, 4 ], -4)->TeX,
Matrix([ [ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, -4, 0, 1 ] ])->TeX,
'Elementary Matrix from syntax $A->E an existing matrix with a row multiple and add';
};

subtest 'Extract a slice from a Matrix' => sub {
Expand Down