Difference between revisions of "AlgebraicFractions"
m |
m |
||
Line 51: | Line 51: | ||
− | $ |
+ | $fraction = "\frac{d}{dx} \left( \frac{-(x^2+4)}{(x^2-4)^2} \right)"; |
$num = Formula("2 * x * (x**2 + 12)")->reduce; |
$num = Formula("2 * x * (x**2 + 12)")->reduce; |
||
Line 60: | Line 60: | ||
# |
# |
||
if ($displayMode eq 'TeX') { |
if ($displayMode eq 'TeX') { |
||
− | $ |
+ | $showfraction = |
− | "\[ $ |
+ | "\[ $fraction = ".ans_rule(10).ans_rule(10)." \]"; |
} else { |
} else { |
||
− | $ |
+ | $showfraction = |
ColumnTable( |
ColumnTable( |
||
− | "\( \displaystyle $ |
+ | "\( \displaystyle $fraction = \)", |
ans_rule(20).$BR.$HR.ans_rule(20), |
ans_rule(20).$BR.$HR.ans_rule(20), |
||
indent => 0, separation => 10, valign => "MIDDLE" |
indent => 0, separation => 10, valign => "MIDDLE" |
||
Line 76: | Line 76: | ||
<p> |
<p> |
||
<b>Setup:</b> |
<b>Setup:</b> |
||
− | We define a string <code>$ |
+ | We define a string <code>$fraction</code> that will be displayed in TeX mode. We define MathObjects formulas <code>$num</code> and <code>$den</code> that are the correct numerator and denominator for the answer. |
</p> |
</p> |
||
<p> |
<p> |
||
− | We define a mode-dependent string <code>$ |
+ | We define a mode-dependent string <code>$showfraction</code> that will be the nicely formatted fraction and answer blanks. To display the fraction nicely in TeX mode, we use displaystyle math <code>\[ ... \]</code> and append two concatenated answer blanks to the string <code>$fraction</code>. In other modes (such as html), we use a <code>ColumnTable</code> from <code>PGunion.pl</code> macros to display the answer blanks as a fraction. |
</p> |
</p> |
||
<p> |
<p> |
||
+ | To get fractions that have a large font size, be sure to use the LaTeX command <code>\( \displaystyle \frac{a}{b} \)</code>. |
||
For fractions over fractions, to keep the font size large use the LaTeX commands |
For fractions over fractions, to keep the font size large use the LaTeX commands |
||
<pre> |
<pre> |
||
Line 109: | Line 110: | ||
$BR |
$BR |
||
$BCENTER |
$BCENTER |
||
− | $displayfrac |
||
+ | $showfraction |
||
$ECENTER |
$ECENTER |
||
Revision as of 22:12, 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 that are stacked on top of each other like a fraction. Stacking the answer blanks is nice formatting that simplifies how to ask students for the parts of a fraction separately. In addition, having two separate answer blanks is useful for requiring students to simplify their answer as much as possible.
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PGstandard.pl", "PGunion.pl", "MathObjects.pl", "PGcourse.pl", ); TEXT(beginproblem()); |
Initialization:
We include the macros file |
Context("Numeric"); $fraction = "\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') { $showfraction = "\[ $fraction = ".ans_rule(10).ans_rule(10)." \]"; } else { $showfraction = ColumnTable( "\( \displaystyle $fraction = \)", ans_rule(20).$BR.$HR.ans_rule(20), indent => 0, separation => 10, valign => "MIDDLE" ); } |
Setup:
We define a string
We define a mode-dependent string
To get fractions that have a large font size, be sure to use the LaTeX command \( \displaystyle\frac{ \displaystyle\frac{a}{b} }{ \displaystyle\frac{c}{d} } \) |
Context()->texStrings; BEGIN_TEXT Calculate the indicated derivative. Simplify your answer as much as possible. $BR $BR $BCENTER $showfraction $ECENTER END_TEXT Context()->normalStrings; |
Main Text:
Everything is as usual. Insert the fraction and answer blanks using |
$showPartialCorrectAnswers = 1; install_problem_grader(~~&std_problem_grader); ANS($num->cmp); ANS($den->cmp); ENDDOCUMENT(); |
Answer Evaluation:
If you want to give students feedback on whether their numerator and denominator are correct, set |