Difference between revisions of "AlgebraicFractions"

From WeBWorK_wiki
Jump to navigation Jump to search
Line 1: Line 1:
<h2>Algebraic Fractions for Student Answers</h2>
<h2>Algebraic Fractions in Student Answers</h2>
<!-- Header for these sections -- no modification needed -->
<!-- Header for these sections -- no modification needed -->

Revision as of 13:16, 11 January 2010

Algebraic Fractions in 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. This is useful for fractional answers that you want students to simplify as much as possible.

Problem Techniques Index

PG problem file Explanation



Initialization: We include the macros file PGunion.pl to be able to display the answer boxes on top of each other (as a fraction).


$frac = "\frac{d}{dx} \left( \frac{-(x^2+4)}{(x^2-4)^2} \right)";

$num = Formula("2 * x * (x**2 + 12)")->reduce;
$den = Formula("(x**2 - 4)**3")->reduce;

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

Setup: We define a string $frac that will be displayed in TeX mode. We define MathObjects formulas $num and $den that are the correct numerator and denominator for the answer.

We define a mode-dependent string $displayfrac that will be the nicely formatted fraction and answer blanks. To display the fraction nicely in TeX mode, we use displaystyle math \[ ... \] and append two concatenated answer blanks to the string $frac. In other modes (such as html), we use a ColumnTable from PGunion.pl macros to display the answer blanks as a fraction.

For fractions over fractions, to keep the font size large use the display fraction \dfrac{}{} option in TeX. For example, \( \dfrac{ \dfrac{a}{b} }{ \dfrac{c}{d} } \).


Calculate the indicated derivative.
Simplify your answer as much as possible.


Main Text: Everything is as usual. Insert the fraction and answer blanks using $displayfrac.

$showPartialCorrectAnswers = 1;




Answer Evaluation: If you want to give students feedback on whether their numerator and denominator are correct, set $showPartialCorrectAnswers = 1;, otherwise set it to 0 to withhold feedback. If you want to withhold credit until both answer blanks are correct, use the standard problem grader, otherwise omit it to use the default (average problem grader).

Problem Techniques Index