Here is a snippet from my code:
$LRP = $P->decompose_LR;
($dim, $C, $base_matrix) = $LRP->solve_LR( Vector( -1,1 ) );
Is this the correct usage?
When I do this, I get the error message:
I'm not sure how to proceed
ColumnVector(-1,1)
to convert to a column vector, or Vector(-1,1)->transpose
. If the latter, then you will not be able to use a Vector object, since the traditional matrix class doesn't know about MathObjects. In that case, you would need to create the vector using the traditional matrix classes.## DESCRIPTION ## Linear Algebra: Matrices (Math 1410) ## ENDDESCRIPTION ## DBsubject(Linear Algebra) ## DBchapter(Matrices) ## DBsection() ## Date(2017-06-15) ## Institution(University of Lethbridge) ## Authors(Olivia Henders & Nicole Wilson) ## MO(1) ## KEYWORDS('linear algebra', 'matrices') ############################## # Initialization DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "AnswerFormatHelp.pl", "PGML.pl", "parserRadioButtons.pl" ); TEXT(beginproblem()); ############################# # Setup $showPartialCorrectAnswers = 1; $showDimensionHints => 1; Context("Vector"); # Column vector that will be used for vector-matrix operations. $v = ColumnVector(0,3,-2); Context("Matrix")->variables->are(t=>"Real"); # Matrix setup. $A is statically defined 2x3, # $B is 3x3 with randomly determined entries, # $C is 2x3 with randomly determined entries and two variables, # and $I is the 3x3 identity matrix $A = Matrix([[1,2,3],[4,5,6]]); $B = Matrix([ [random(-5,5,1),random(-5,5,1),random(-5,5,1)], [random(-5,5,1),random(-5,5,1),random(-5,5,1)], [random(-5,5,1),random(-5,5,1),random(-5,5,1)] ]); # Have to generate the coefficients here so they can be used separately. $C1_2 = Compute("3"); $C2_2 = non_zero_random(-5,5); $C = Matrix([ [random(-5,5,1),"$C1_2 t",random(-5,5,1)], [random(-5,5,1),"$C2_2 t",random(-5,5,1)] ]); $D = Matrix([[3,5],[1,2]]); $E = Matrix([[5],[7],[3]]); $I = Value::Matrix->I(3); # Generate the matrix pieces that include variables here so that they can be # turned into variable objects when in the matrix. $answerA1_2 = $A->element(1,2) - Formula("$C1_2 t"); $answerA2_2 = $A->element(2,2) - Formula("$C2_2 t"); $answerA = Matrix([ [($A->element(1,1) - $C->eval(t=>1)->element(1,1)), Formula($answerA1_2)->reduce, ($A->element(1,3) - $C->eval(t=>1)->element(1,3))], [($A->element(2,1) - $C->eval(t=>1)->element(2,1)), Formula($answerA2_2)->reduce, ($A->element(2,3) - $C->eval(t=>1)->element(2,3))] ]); $answerB = Compute("DNE"); $answerC = Matrix($A * $B); # Generate the matrix pieces that include variables here so that they can be # turned into variable objects when in the matrix. $answerD1_1 = ($C->eval(t=>1)->element(1,1) * $B->element(1,1)) + (Formula("$C1_2 t") * $B->element(2,1)) + ($C->eval(t=>1)->element(1,3) * $B->element(3,1)); $answerD1_2 = ($C->eval(t=>1)->element(1,1) * $B->element(1,2)) + (Formula("$C1_2 t") * $B->element(2,2)) + ($C->eval(t=>1)->element(1,3) * $B->element(3,2)); $answerD1_3 = ($C->eval(t=>1)->element(1,1) * $B->element(1,3)) + (Formula("$C1_2 t") * $B->element(2,3)) + ($C->eval(t=>1)->element(1,3) * $B->element(3,3)); $answerD2_1 = ($C->eval(t=>1)->element(2,1) * $B->element(1,1)) + (Formula("$C2_2 t") * $B->element(2,1)) + ($C->eval(t=>1)->element(2,3) * $B->element(3,1)); $answerD2_2 = ($C->eval(t=>1)->element(2,1) * $B->element(1,2)) + (Formula("$C2_2 t") * $B->element(2,2)) + ($C->eval(t=>1)->element(2,3) * $B->element(3,2)); $answerD2_3 = ($C->eval(t=>1)->element(2,1) * $B->element(1,3)) + (Formula("$C2_2 t") * $B->element(2,3)) + ($C->eval(t=>1)->element(2,3) * $B->element(3,3)); $answerD = Matrix([ [Formula($answerD1_1)->reduce, Formula($answerD1_2)->reduce, Formula($answerD1_3)->reduce], [Formula($answerD2_1)->reduce, Formula($answerD2_2)->reduce, Formula($answerD2_3)->reduce] ]); $answerE = Matrix($I + $B); $answerF = Matrix($B**2); $answerG = $B * $I; $answerH = $A->transpose; $answerI = $D->inverse; $answerJ = $B->det; $answerK = $A->row(2); $answerL = $A->column(1); $answerM = $A->element(1,3); $answerN = List($C->eval(t=>1)->dimensions); $answerO = $A * ColumnVector($v); $answerP = Vector($B->row(1)); $answerQ = Vector($B->column(1)); $answerR = $B->proj($E); if ($B->isZero) { $answerS = RadioButtons([True, False], True); } else { $answerS = RadioButtons([True, False], False); } if ($B->isOne) { $answerT = RadioButtons([True, False], True); } else { $answerT = RadioButtons([True, False], False); } if ($D->isSquare) { $answerU = RadioButtons([True, False], True); } else { $answerU = RadioButtons([True, False], False); } if ($D->isRow) { $answerV = RadioButtons([True, False], True); } else { $answerV = RadioButtons([True, False], False); } if ($B->is_symmetric) { $answerW = RadioButtons([True, False], True); } else { $answerW = RadioButtons([True, False], False); } $answerX = $B->norm_one; $answerY = $B->norm_max; $answerZ = $B->kleene; $answerAi = $B->normalize($v); $answerBi = $D->decompose_LR; $answerCi = $A->L; $answerDi = $A->R; $answerEi = $B->PL; $answerFi = $B->PR; $answerGi = $D->solve_LR($v); $answerHi = $B->condition($B->inverse); $answerIi = $D->order_LR; $answerJi = $B->solve_GSM(); $answerKi = $B->solve_SSM(); $answerLi = $B->solve_RM(); ############################## # Problem Text...
$answerAi = $B->normalize(Matrix($v)->transpose);to avoid the error message. You will need to do the same for
$answerGi = $D->solve_LR($v);making it
$answerGi = $D->solve_LR(Matrix($v)->transpose);but there is a problem here, since
$D
is 2 x 2, while $v
is three-dimensional. So something needs to be adjusted there.