AlgebraicFractions

From WeBWorK_wiki
Revision as of 11:44, 11 January 2010 by Pearson (talk | contribs) (New page: <h2>Algebraic Fractions for Student Answers</h2> <!-- Header for these sections -- no modification needed --> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Algebraic Fractions for Student Answers


This code shows how to format questions in which the answer is an algebraic fraction that has separate answer blanks for the numerator and denominator.

Problem Techniques Index

PG problem file Explanation
DOCUMENT();

loadMacros(
"PGstandard.pl",
"PGunion.pl",
"MathObjects.pl",
"PGcourse.pl",
);

TEXT(beginproblem());

Initialization: To do ..(what you are doing)........., we don't have to change the tagging and documentation section of the problem file. In the initialization section, we need to include the macros file -------.pl.

Context("Numeric");

$a = random(3,7,1);
$b = random(3,7,1);
while ($a == $b) { $b = random(3,7,1); }

$apb = $a + $b;

$frac = "\frac{$a}{x} + \frac{$b}{x-1}";

$num = Formula("$apb * x - $a")->reduce;
$den = Formula("x*(x-1)")->reduce;

# 
#  Display the fraction and answer blanks nicely
#
if ($displayMode eq 'TeX') {
  $displayfrac =
  "\[ $frac = ".ans_rule(10).ans_rule(10)." \]";
} else {
  $displayfrac =
  ColumnTable(
  "\( \displaystyle $frac = \)",
  ans_rule(20).$BR.$HR.ans_rule(20),
  indent => 0, separation => 10, valign => "MIDDLE"
  );
}

Setup: We specify that the Context should be ......, and define the answer to be a formula.

Notes: on using this and related Contexts.

Context()->texStrings;
BEGIN_TEXT

Write the expression as a single fraction.  Simplify your answer.
$BR
$BR
$BCENTER
$displayfrac
$ECENTER

END_TEXT
Context()->normalStrings;

Main Text: The problem text section of the file is as we'd expect.

$showPartialCorrectAnswers = 1;

install_problem_grader(~~&std_problem_grader);

ANS($num->cmp);
ANS($den->cmp);

ENDDOCUMENT();

Answer Evaluation: As is the answer.

Problem Techniques Index