NAME

MatrixReduce.pl - Provides subroutines for elementary matrix computations using MathObjects matrices.

DESCRIPTION

Provides subroutines for elementary matrix computations using MathObjects matrices, such as finding the reduced row echelon form, performing row operations, and constructing elementary matrices.

Get the reduced row echelon form: $Areduced = rref($A);

Should be used in the fraction context with all entries of $A made into fractions.

Make matrix entries do fraction arithmetic (rather than decimal arithmetic):

After selecting the Fraction context using Context('Fraction')-parens->set("[" => {formMatrix => 1})>, $A = apply_fraction_to_matrix_entries($A); applies Fraction() to all of the entries of $A, which makes subsequent matrix algebra computations with $A use fraction arithmetic.

Get the reduced column echelon form: $Areduced = rcef($A);
Change the value of a matrix entry: change_matrix_entry($A,[2,3],50);

changes the [2,3] entry to the value 50.

Construct an n x n identity matrix: $E = identity_matrix(5);

(This is an alias for Value::Matrix->I(5);)

Construct an n x n elementary matrix that will permute rows i and j:

$E = elem_matrix_row_switch(5,2,4); creates a 5 x 5 identity matrix and swaps rows 2 and 4.

Construct an n x n elementary matrix that will multiply row i by s:

$E = elem_matrix_row_mult(5,2,4); creates a 5 x 5 identity matrix and swaps puts 4 in the second spot on the diagonal.

Construct an n x n elementary matrix that will multiply row i by s:

$E = elem_matrix_row_mult(5,2,4); creates a 5 x 5 identity matrix and puts 4 in the second spot on the diagonal.

Construct an n x n elementary matrix that will add s times row j to row i:

$E3 = elem_matrix_row_add(5,3,1,35); creates a 5 x 5 identity matrix and puts 35 in the (3,1) position.

Perform the row switch transform that swaps (row i) with (row j):

$Areduced = row_switch($A,2,4); swaps rows 2 and 4 in matrix $A.

Perform the row multiplication transform s * (row i) placed into (row i):

$Areduced = row_mult(A,2,10); multiplies every entry in row 2 of $A by 10.

Perform the row addition transform (row i) + s * (row j) placed into (row i):

$Areduced = row_add($A,2,1,10); adds 10 times row 1 to row 2 and places the result in row 2. (Same as constructing $E to be the identity with 10 placed in entry (2,1), then multiplying $E * $A.)

SYNOPSIS

Usage:

DOCUMENT();
loadMacros(
    "PGstandard.pl",
    "MathObjects.pl",
    "MatrixReduce.pl", # automatically loads contextFraction.pl and MathObjects.pl
    "PGcourse.pl",
);
$showPartialCorrectAnswers = 0;
TEXT(beginproblem());

# Context('Matrix'); # for decimal arithmetic
Context('Fraction'); # for fraction arithmetic

$A = Matrix([
    [random(-5,5,1),random(-5,5,1),random(-5,5,1),3],
    [random(-5,5,1),random(-5,5,1),random(-5,5,1),0.75],
    [random(-5,5,1),random(-5,5,1),random(-5,5,1),9/4],
]);

$A = apply_fraction_to_matrix_entries($A); # try commenting this line out for different results

$Arref = rref($A);

$Aswitch = row_switch($A, 2, 3);

$Amult = row_mult($A, 2, 4);

$Aadd = row_add($A, 2, 1, 10);

$E = elem_matrix_row_add(3,2,1,10);
$EA = $E * $A;

$E1 = elem_matrix_row_switch(5,2,4);
$E2 = elem_matrix_row_mult(5,4,Fraction(1/10));
$E3 = elem_matrix_row_add(5,3,1,35);
$E4 = identity_matrix(4);
change_matrix_entry($E4,[3,2],10);

Context()->texStrings;
BEGIN_TEXT
The original matrix and its row reduced echelon form:
\[ $A \sim $Arref. \]
$BR
The original matrix with rows switched, multiplied, or added together:
\[ $Aswitch, $Amult, $Aadd. \]
$BR
Some elementary matrices.
\[$E1, $E2, $E3, $E4\]
END_TEXT
Context()->normalStrings;

COMMENT('MathObject version.');
ENDDOCUMENT();

AUTHORS

Paul Pearson, Hope College, Department of Mathematics

with help from

Davide Cervone, Union College, Department of Mathematics

Michael Doob, University of Manitoba, Department of Mathematics