Difference between revisions of "AlgebraicFractions"
m (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;"> ...) |
m |
||
Line 4: | Line 4: | ||
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> |
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> |
||
− | <em>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.</em> |
+ | <em>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.</em> |
</p> |
</p> |
||
Line 38: | Line 38: | ||
<p> |
<p> |
||
<b>Initialization:</b> |
<b>Initialization:</b> |
||
− | To do ..(what you are doing)........., we don't have to change the |
||
+ | We include the macros file <code>PGunion.pl</code> to be able to display the answer boxes on top of each other (as a fraction). |
||
− | tagging and documentation section of the problem file. |
||
− | In the initialization section, we need to include the macros file <code>-------.pl</code>. |
||
</p> |
</p> |
||
</td> |
</td> |
||
Line 52: | Line 50: | ||
Context("Numeric"); |
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{d}{dx} \left( \frac{-(x^2+4)}{(x^2-4)^2} \right)"; |
||
− | $frac = "\frac{$a}{x} + \frac{$b}{x-1}"; |
||
+ | $num = Formula("2 * x * (x**2 + 12)")->reduce; |
||
− | |||
+ | $den = Formula("(x**2 - 4)**3")->reduce; |
||
− | $num = Formula("$apb * x - $a")->reduce; |
||
− | $den = Formula("x*(x-1)")->reduce; |
||
# |
# |
||
Line 83: | Line 76: | ||
<p> |
<p> |
||
<b>Setup:</b> |
<b>Setup:</b> |
||
− | We specify that the Context should be <code>......</code>, and define the answer to be a formula. |
||
+ | We define a string <code>$frac</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> |
||
− | Notes: on using this and related Contexts. |
||
+ | We define a mode-dependent string <code>$displayfrac</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>$frac</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> |
||
+ | For fractions over fractions, to keep the font size large use the display fraction <code>\dfrac{}{}</code> option in TeX. For example, <code>\( \dfrac{ \dfrac{a}{b} }{ \dfrac{c}{d} } \)</code>. |
||
</p> |
</p> |
||
− | |||
</td> |
</td> |
||
</tr> |
</tr> |
||
Line 100: | Line 95: | ||
BEGIN_TEXT |
BEGIN_TEXT |
||
− | Write the expression as a single fraction. Simplify your answer. |
||
+ | Calculate the indicated derivative. |
||
+ | Simplify your answer as much as possible. |
||
$BR |
$BR |
||
$BR |
$BR |
||
Line 113: | Line 109: | ||
<p> |
<p> |
||
<b>Main Text:</b> |
<b>Main Text:</b> |
||
− | The problem text section of the file is as we'd expect. |
||
+ | Everything is as usual. Insert the fraction and answer blanks using <code>$displayfrac</code>. |
||
</p> |
</p> |
||
</td> |
</td> |
||
Line 135: | Line 131: | ||
<p> |
<p> |
||
<b>Answer Evaluation:</b> |
<b>Answer Evaluation:</b> |
||
− | As is the answer. |
||
+ | If you want to give students feedback on whether their numerator and denominator are correct, set <code>$showPartialCorrectAnswers = 1;</code>, 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). |
||
</p> |
</p> |
||
</td> |
</td> |
Revision as of 12:08, 11 January 2010
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. This is useful for fractional answers that you want students to simplify 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"); $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 = ColumnTable( "\( \displaystyle $frac = \)", 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
For fractions over fractions, to keep the font size large use the display fraction |
Context()->texStrings; BEGIN_TEXT Calculate the indicated derivative. Simplify your answer as much as possible. $BR $BR $BCENTER $displayfrac $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 |