WeBWorK Problems

Matrix Checker Difficulties

Matrix Checker Difficulties

by Murphy Waggoner -
Number of replies: 3
Hi, I'm trying to learn how to use the matrix checkers so I copied a problem someone else had written and was trying to change it.  I end up with two problems.

a)  I was confirming that the matrix checker for parametric solutions would allow any multiple of the basis element for the solution of the associated homogeneous system.  I entered the result one would get automatically from row reduction, but then tried another correct answer.  

The answer preview used the first component of the basis vector from my new answer, but the other three components were from my previous answer. See the attached image.

b)  I added a second part to the question that asks for the parametric solution to the homogeneous system associated with the nonhomogeneous system in the first part of the question.  I cannot seem to get the answer checker to work here and I am assuming it is because of a programming error.

The error I get when I enter the correct solution is "Coordinate of vector cannot be a matrix".

The code is below.

## DESCRIPTION
## Linear Algebra
## ENDDESCRIPTION

## Tagged by cmd6a 5/3/06

## DBsubject(Linear algebra)
## DBchapter(Systems of linear equations)
## DBsection(Systems with 4 or more variables)
## Date(July 2013)
## Institution(Rochester and Hope College)
## Author(Paul Pearson)
## MLT(AlmostRREFSolnWithParams)
## MLTleader(1)
## Level(2)
## MO(1)
## TitleText1('Linear Algebra with Applications')
## AuthorText1('Jeffrey Holt')
## EditionText1('1')
## Section1('2.1')
## Problem1('')

# Revised by MEWaggoner 2/10/2015

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserMultiAnswer.pl",
"MatrixCheckers.pl",
"PGcourse.pl",
);

TEXT(beginproblem());
$showPartialCorrectAnswers = 1;

Context('Matrix');

$a = non_zero_random(-5,5,1);
$c = non_zero_random(-5,5,1);
$b = non_zero_random(-5,5,1);
$d = $a - $b + $c;

$NO_SPACE = '@{}';

$displace = Matrix([$a - $b + $c, $b - $c, $c, 0])->transpose;
$basis1 = Matrix([- 1, 1, -1, 1])->transpose;

$multians1 = MultiAnswer($displace, $basis1)->with(
  singleResult => 1,
  separator => ', ',
  tex_separator => ', ',
  allowBlankAnswers=>0,
  checker => ~~&parametric_plane_checker_columns,
);

$multians2 = MultiAnswer($basis1)->with( 
     singleResult => 1, 
     separator => ', ',
     tex_separator => ', ', 
     allowBlankAnswers=>0, 
     checker => ~~&basis_checker_one_column, 
);



Context()->texStrings;
BEGIN_TEXT
Part 1:  Solve the nonhomogeneous system 
\[ \left\lbrace \begin{array}{r${NO_SPACE}r${NO_SPACE}r${NO_SPACE}r${NO_SPACE}r${NO_SPACE}r}
x_1 & + x_2 &       &       & = & $a \\
    &   x_2 & + x_3 &       & = & $b \\ 
    &       &   x_3 & + x_4 & = & $c \\
x_1 &       &       & + x_4 & = & $d 
\end{array} \right. \]
$BR
\(
\displaystyle
\left\lbrack
\begin{array}{c}
x_1 \\
x_2 \\
x_3 \\
x_4
\end{array}
\right\rbrack
= \)
\{ $multians1->ans_array \}
\( + s \)
\{ $multians1->ans_array \}.
$PAR
$PAR
Part 2:  Based on your results for the solution of the nonhomogeneous equation above, solve the associated homogeneous equation (you should be able to answer this without any further work.)
\[ \left\lbrace \begin{array}{r${NO_SPACE}r${NO_SPACE}r${NO_SPACE}r${NO_SPACE}r${NO_SPACE}r}
x_1 & + x_2 &       &       & = & 0 \\
    &   x_2 & + x_3 &       & = & 0 \\ 
    &       &   x_3 & + x_4 & = & 0 \\
x_1 &       &       & + x_4 & = & 0 
\end{array} \right. \]
$BR
\(
\displaystyle
\left\lbrack
\begin{array}{c}
x_1 \\
x_2 \\
x_3 \\
x_4
\end{array}
\right\rbrack
= s \)
\{ $multians2->ans_array \}.
END_TEXT
Context()->normalStrings;

ANS($multians1->cmp);
ANS($multians2->cmp);
COMMENT('MathObject version');
ENDDOCUMENT();
Attachment New_Picture.jpg
In reply to Murphy Waggoner

Re: Matrix Checker Difficulties

by Christopher Heckman -
Hi, I'm trying to learn how to use the matrix checkers so I copied a problem someone else had written and was trying to change it.

Commendable! However, this problem was written a long time ago, before MathObjects, so there are a few issues.

a)  I was confirming that the matrix checker for parametric solutions would allow any multiple of the basis element for the solution of the associated homogeneous system.  I entered the result one would get automatically from row reduction, but then tried another correct answer.  

Both should work.

The answer preview used the first component of the basis vector from my new answer, but the other three components were from my previous answer. See the attached image.

Yes, WeBWorK does not store the entire matrix. This is one of my pet peeves and something that I wish the WW people would fix.

b)  I added a second part to the question that asks for the parametric solution to the homogeneous system associated with the nonhomogeneous system in the first part of the question.  I cannot seem to get the answer checker to work here and I am assuming it is because of a programming error.

A few things here. First of all, you don't need a MultiAnswer function for part (b), since there is only one math object (a matrix) to check.

The error I get when I enter the correct solution is "Coordinate of vector cannot be a matrix".

I seem to recall seeing that error a lot, and it took a while for me to find the fix. You need to enter the following line after Context("Matrix"):

Context()->parens->set("[" => {formMatrix => 1});

I've also generalized this problem, and attached my new version to this reply. This has been tested as well, so it is "bug-free". (Rule #1 for programmers: No program is truly bug-free. 8-) ) Here's a list of what the functions do:

  • random_rref (m, n, r, M, L): Creates an mxn matrix with rank r, the size of whose entries are determined by M (the bigger M is, the larger the entries can be). L is a list of columns which MUST have pivots in them.
  • latex_mat (M): Produces LaTeX code for a matrix M of arbitrary dimensions.
  • rowop_multiplyrow (n, i, M)
  • rowop_swaprows (n, i, j)
  • rowop_addmultrow (n, i, j, M): These last three functions produce elementary matrices. This was before I knew they had been programmed into WeBWorK.
  • good_inverse (n, ops, M): Produce an nxn matrix with determinant ±1, the size of whose entries are determined by M, and which requires at most "ops" row operations to find the inverse for.
  • Mat2System (A, qw(x y z w), b): Print a system of linear equations.
  • too_many_zeros (A): returns true if there are "too many zeros" in A. Avoids trivial problems.
  • good_ns (A, R, r): Null space of A. The RREF of A is R, and the rank of A is r. (These parameters were chosen before A was created.)
In reply to Murphy Waggoner

Re: Matrix Checker Difficulties

by Paul Pearson -
Hi Murphy,

You did not need to use $multians2 at all.  For the second answer, just use 

\{ $basis1->ans_array \}

ANS($basis1->cmp( checker=>~~&basis_checker_one_column));

See below for a working example.

Best regards,

Paul

###############################################3

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserMultiAnswer.pl",
"MatrixCheckers.pl",
"PGcourse.pl",
);

TEXT(beginproblem());
$showPartialCorrectAnswers = 1;

Context('Matrix');

$a = non_zero_random(-5,5,1);
$c = non_zero_random(-5,5,1);
$b = non_zero_random(-5,5,1);
$d = $a - $b + $c;

$NO_SPACE = '@{}';

$displace = Matrix([$a - $b + $c, $b - $c, $c, 0])->transpose;
$basis1 = Matrix([- 1, 1, -1, 1])->transpose;

$multians1 = MultiAnswer($displace, $basis1)->with(
  singleResult => 1,
  separator => ', ',
  tex_separator => ', ',
  allowBlankAnswers=>0,
  checker => ~~&parametric_plane_checker_columns,
);

Context()->texStrings;
BEGIN_TEXT
Part 1:  Solve the nonhomogeneous system 
\[ \left\lbrace \begin{array}{r${NO_SPACE}r${NO_SPACE}r${NO_SPACE}r${NO_SPACE}r${NO_SPACE}r}
x_1 & + x_2 &       &       & = & $a \\
    &   x_2 & + x_3 &       & = & $b \\ 
    &       &   x_3 & + x_4 & = & $c \\
x_1 &       &       & + x_4 & = & $d 
\end{array} \right. \]
$BR
\(
\displaystyle
\left\lbrack
\begin{array}{c}
x_1 \\
x_2 \\
x_3 \\
x_4
\end{array}
\right\rbrack
= \)
\{ $multians1->ans_array \}
\( + s \)
\{ $multians1->ans_array \}.
$PAR
$PAR
Part 2:  Based on your results for the solution of the nonhomogeneous equation above, solve the associated homogeneous equation (you should be able to answer this without any further work.)
\[ \left\lbrace \begin{array}{r${NO_SPACE}r${NO_SPACE}r${NO_SPACE}r${NO_SPACE}r${NO_SPACE}r}
x_1 & + x_2 &       &       & = & 0 \\
    &   x_2 & + x_3 &       & = & 0 \\ 
    &       &   x_3 & + x_4 & = & 0 \\
x_1 &       &       & + x_4 & = & 0 
\end{array} \right. \]
$BR
\(
\displaystyle
\left\lbrack
\begin{array}{c}
x_1 \\
x_2 \\
x_3 \\
x_4
\end{array}
\right\rbrack
= s \)
\{ $basis1->ans_array \}.
END_TEXT
Context()->normalStrings;

ANS($multians1->cmp);
ANS($basis1->cmp( checker=>~~&basis_checker_one_column));

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