Difference between revisions of "MatrixCustomAnswerChecker1"

From WeBWorK_wiki
Jump to navigation Jump to search
(PGML example link)
(add historical tag and give links to newer problems.)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
  +
{{historical}}
  +
  +
<p style="font-size: 120%;font-weight:bold">This problem has been replaced with [https://openwebwork.github.io/pg-docs/sample-problems/LinearAlgebra/MatrixCustomAnswerChecker.html a newer version of this problem]</p>
  +
 
<h2>Matrices and Custom Answer Checkers</h2>
 
<h2>Matrices and Custom Answer Checkers</h2>
   
Line 6: Line 10:
 
</p>
 
</p>
 
* File location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/LinAlg/MatrixCustomAnswerChecker1.pg FortLewis/Authoring/Templates/LinAlg/MatrixCustomAnswerChecker1.pg]
 
* File location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/LinAlg/MatrixCustomAnswerChecker1.pg FortLewis/Authoring/Templates/LinAlg/MatrixCustomAnswerChecker1.pg]
* PGML location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/LinAlg/MatrixCustomAnswerChecker1_PGML.pg Authoring/Templates/LinAlg/MatrixCustomAnswerChecker1_PGML.pg]
+
* PGML location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/LinAlg/MatrixCustomAnswerChecker1_PGML.pg FortLewis/Authoring/Templates/LinAlg/MatrixCustomAnswerChecker1_PGML.pg]
   
 
<br clear="all" />
 
<br clear="all" />

Latest revision as of 05:25, 18 July 2023

This article has been retained as a historical document. It is not up-to-date and the formatting may be lacking. Use the information herein with caution.

This problem has been replaced with a newer version of this problem

Matrices and Custom Answer Checkers

Click to enlarge

This PG code shows how to use a multianswer answer checker to evaluate an open-ended question about matrices.


Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserMultiAnswer.pl",
"AnswerFormatHelp.pl",
"PGcourse.pl",
);
$showPartialCorrectAnswers = 0;
TEXT(beginproblem()); 

Initialization:

Context('Matrix');

$A = Matrix([[1,1],[0,1]]);
$B = Matrix([[1,0],[1,1]]);

$multians = MultiAnswer($A, $B)->with(
  singleResult => 1,
  checker => sub {
      my ( $correct, $student, $answerHash ) = @_;
      my @s = @{$student};
      $s0 = Matrix($s[0]); 
      $s1 = Matrix($s[1]);
      return $s0 * $s1 != $s1 * $s0;
  }
);

Setup: Construct two matrices $A and $B that do not commute and therefore serve as a correct answer. Use a $multians object with a custom answer checker subroutine. The answer checker uses my ( $correct, $student, $answerHash ) = @_; to grab the inputs (the correct answer, the student answer, and the answer hash table info). Then, put the student's two answers into an array @s using my @s = @{$student};. Make sure the student's first matrix $s[0] is converted to a MathObject matrix $s0 using $s0 = Matrix($s[0]); and similarly for the student's second matrix. The return value, which is boolean, is the truth value of the statement $s0 * $s1 != $s1 * $s0.

Context()->texStrings;
BEGIN_TEXT
Give an example of two \( 2 \times 2 \) matrices \( A \) and \( B \)
such that \( AB \ne BA \).
$BR
$BR
\( A = \)
\{ $multians->ans_array(5) \}
$BR
$BR
\( B = \)
\{ $multians->ans_array(5) \}
END_TEXT
Context()->normalStrings;

Main Text: Make sure that both answer arrays are called as methods on the $multians object (i.e., $multians->ans_array(5) should be called for each answer array. Note that ans_array(w) produces an answer array of boxes each w characters wide.

install_problem_grader(~~&std_problem_grader);

ANS( $multians->cmp() );

COMMENT('MathObject version.');

ENDDOCUMENT();

Answer Evaluation:

Templates by Subject Area