## WeBWorK Problems

### Using matrices as variables (constants) in matrices ### Using matrices as variables (constants) in matrices

by Murphy Waggoner -
Number of replies: 3
Hi,
I have written several problems that require the students to multiply two partitioned matrices, and then solve a matrix equation for the matrix components. The material is in Lay/Lay/McDonald in section 2.4.

I am struggling to make the problem "natural". That is to make the way the problem is coded, the problem is presented, the solutions are entered by students, and the answers are checked in ways that are not contrived. Maybe it is too much for me to want all of that.

The key issue for me is that the answer checker allows answers that are commutations of the correct answer.

At the bottom is my current code, which has the students enter their solutions in a contrived way. That is, they enter something like AinvB for A^(-1)B, where AinvB is a variable name.

Here are the various problems I have run into and the solutions I have tried.

1) Following the problem Library/WHFreeman/Holt_linear_algebra/Chaps_1-4/3.3.51.pg and webpage http://webwork.maa.org/wiki/Matrix_(MathObject_Class)#.WdUXFVtSzIU
I tried making the matrices A, B, C, X, Y, Z and I matrix constants instead of real variables. But then I cannot create the matrices $M,$N and $Q because WeBWorK expects real numbers for matrices. 2) There is no variable type Matrix in the contexts, and so I can't make A, B, C, ... Matrix variables (such as Context()->variables->add(A => "Matrix",...). 3) Some of the issue could be resolved if I didn't use variables for displaying the matrix multiplication. And so I tried the code here for displaying the matrices, but that makes changing the problem with different$M, $N,$Q cumbersome and doesn't resolve the problem of asking for the answer of the multiplication as a matrix. I want that intermediate step of students entering the product so that they have a halfway point to know if they are right or not and to help them learn how to do the problem.
$$\begin{bmatrix} A & B\\ C & 0 \end{bmatrix} \begin{bmatrix} I & 0\\ X & Y \end{bmatrix} = \begin{bmatrix} 0 & I\\ Z & 0 \end{bmatrix}$$
$BR$HR

4) The other thing I could do, but haven't tried, its to use TeX code to display all matrices and to ask for the product matrix components one-by-one instead of giving the student a matrix to fill in. I will do that if I have to, but I am hoping for a different solution.

Thanks, Murphy

DOCUMENT(); # This should be the first executable line in the problem.

"PGstandard.pl",
"MathObjects.pl", #"PGmatrixmacros.pl"
);

TEXT(beginproblem());

Context("Matrix");

B => "Real",
C => "Real",
X => "Real",
Y => "Real",
Z => "Real",
I => "Real",
BX => "Real",
BY => "Real",
Binv =>"Real",
BinvA =>"Real");

$M = Matrix( [[A,B],[C,0]]);$N = Matrix( [[I,0],[X,Y]]);
$Q = Matrix( [[0,I],[Z,0]]);$LHS = Matrix( [["A + BX","BY"],[C,0]]);

$Xans = Compute("-BinvA");$Yans = Compute("Binv");
$Zans = Compute("C");$showPartialCorrectAnswers = 1;

############################################
Context()->texStrings;
BEGIN_TEXT
Perform the following matrix operation:
$PAR 1) Assume the matrices $$A,\ B,\ C,\ X,\ Y,$$ and $$Z$$ are sized in such a way as to make the block matrix product below make sense.$BR
Consider the equation $$M N = Q$$.

$BR$HR

$BBOLD Note:$EBOLD Enter matrix multiplication without parentheses, without *, and without spaces. For example, to enter the multiplication of $$M$$ and $$N$$, write "MN" instead of "M*N" or "M N" or "(M)(N)", without the quote marks, of course.

$BR$BR
$BBOLD Note:$EBOLD Enter matrix inverses by putting "inv" after the name. For example, to enter $$M^{-1}$$ write "Minv", and to enter $$M^{-1}N$$ write "MinvN", without the quote marks.$BR$HR

$BR$BR
Compute the product on the left-hand side to get this equation.
$BR \{$LHS->ans_array\} $$= C$$

$HR Now, solve for each matrix below in terms of $$A,\ B,$$ and $$C$$, making the necessary assumptions about invertibility.$BR
$$X\ =\$$ \{ans_rule(20)\} $BR $$Y\ =\$$ \{ans_rule(20)\}$BR
$$Z\ =\$$ \{ans_rule(20)\} $BR END_TEXT Context()->normalStrings; ANS($LHS->cmp);
ANS($Xans->cmp); ANS($Yans->cmp);
ANS(\$Zans->cmp);

ENDDOCUMENT(); ### Re: Using matrices as variables (constants) in matrices

by Murphy Waggoner -
I'm just replying to move the question up in the list. Does anyone have recommendations? ### Re: Using matrices as variables (constants) in matrices

by Michael Gage -
I haven't looked deeply at the problem yet -- there may well be some clever trick that will work entirely within WeBWorK. On the other hand this seems to be the kind of problem that SageMath handles routinely so perhaps you could use the AskSage() routines. There is a slightly greater risk of complications because you are getting two different programs to work together but once you get it to work you will probably be able to ask even more complicated matrix algebra questions and ship them over to Sage to get solutions to check the students' answers. 