Difference between revisions of "AlgebraicFractions"
Line 130: | Line 130: | ||
<b>Setup:</b> |
<b>Setup:</b> |
||
We define a string <code>$fraction</code> that will be displayed in TeX mode. |
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, as well as some bogus answers <code>$numbogus</code> and <code>$denbogus</code> that result from not finding a common denominator. We use <code>MultiAnswer</code> to manipulate both student answers at the same time. In <code>$multians</code> we allow for answers to be left blank, which requires that we do type checking on the students input (to avoid cryptic error messages) by using <code>ref($f1) eq ref($f1stu)</code> to see if the correct numerator <code>$f1</code> and the student numerator <code>$f1stu</code> have the same type. We also allow for the student to enter the fraction as either <code>(6y-3)/(y-2)</code> or <code>(3-6y)/(2-y)</code>, since both are correct and it is not clear that one is preferable to the other, which requires that we check <code>$f1==$f1stu || -$f1==$f1stu</code>. Here <code>||</code> is perl's "or" operator. We provide some custom answer hints by testing for bogus numerators and denominators and displaying answer messages via <code>$ansHash->setMessage(1,"Simplify your answer further");</code> |
+ | We define MathObjects formulas <code>$num</code> and <code>$den</code> that are the correct numerator and denominator for the answer, as well as some bogus answers <code>$numbogus</code> and <code>$denbogus</code> that result from not finding a common denominator. We use <code>MultiAnswer</code> to manipulate both student answers at the same time. In <code>$multians</code> we allow for answers to be left blank, which requires that we do type checking on the students input (to avoid cryptic error messages) by using <code>ref($f1) eq ref($f1stu)</code> to see if the correct numerator <code>$f1</code> and the student numerator <code>$f1stu</code> have the same type. We also allow for the student to enter the fraction as either <code>(6y-3)/(y-2)</code> or <code>(3-6y)/(2-y)</code>, since both are correct and it is not clear that one is preferable to the other, which requires that we check <code>$f1==$f1stu || -$f1==$f1stu</code>. Here <code>||</code> is perl's "or" operator. We provide some custom answer hints by testing for bogus numerators and denominators and displaying answer messages via <code>$ansHash->setMessage(1,"Simplify your answer further");</code>, where the 1 stands for the first answer blank. |
</p> |
</p> |
||
<p> |
<p> |
Revision as of 03:03, 11 April 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.
- Example 1: (Recommended) Algebraic fractions using MultiAnswer
- Example 2: Algebraic fractions without using MultiAnswer
Example 1: (Recommended) Algebraic fractions using MultiAnswer
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "PGunion.pl", "parserMultiAnswer.pl", "PGcourse.pl", ); TEXT(beginproblem()); |
Initialization:
We include the macros file |
Context("Numeric")->variables->are(y=>"Real"); $a = random(2,8,2); $b = random(3,9,2); $c = random(1,9,1); while ($c == $b/$a) { $c = random(1,9,1); } $fraction = "\frac{$a y}{y-$c} + \frac{$b}{$c - y} "; $num = Formula("$a y - $b")->reduce; $den = Formula("y - $c")->reduce; $numbogus = Formula("$a*y+$b"); $denbogus = Formula("(y-$c)*($c-y)"); $multians = MultiAnswer($num, $den)->with( singleResult => 0, allowBlankAnswers => 1, checker => sub { my ( $correct, $student, $ansHash ) = @_; my ( $f1stu, $f2stu ) = @{$student}; my ( $f1, $f2 ) = @{$correct}; if ( ref($f1) eq ref($f1stu) && ( $f1==$f1stu && $f2==$f2stu) || ref($f2) eq ref($f2stu) && (-$f1==$f1stu && -$f2==$f2stu) ) { return [1,1]; } elsif (ref($f1) eq ref($f1stu) && (($f1==$f1stu) || (-$f1==$f1stu))) { return [1,0]; } elsif (( ref($f1) eq ref($f1stu) && ($numbogus==$f1stu || -$numbogus==$f1stu) ) || ( ref($f2) eq ref($f2stu) && ($denbogus==$f2stu || -$denbogus==$f2stu) )) { $ansHash->setMessage(1,"Find a common denominator first"); $ansHash->setMessage(2,"Find a common denominator first"); return [0,0]; } elsif (ref($f2) eq ref($f2stu) && (($f2==$f2stu) || (-$f2==$f2stu))) { return [0,1]; } elsif ( ref($f1) eq ref($f1stu) && ref($f2) eq ref($f2stu) && $f1*$f2stu==$f1stu*$f2 ) { $ansHash->setMessage(1,"Simplify your answer further"); $ansHash->setMessage(2,"Simplify your answer further"); return [0,0]; } else { return [0,0]; } } ); # # Display the fraction and answer blanks nicely # Context()->texStrings; if ($displayMode eq 'TeX') { $showfraction = "\[ $fraction = ".$multians->ans_rule(10).$multians->ans_rule(10)." \]"; } else { $showfraction = ColumnTable( "\( \displaystyle $fraction = \)", $multians->ans_rule(20).$BR.$HR.$multians->ans_rule(20), indent => 0, separation => 10, valign => "MIDDLE" ); } Context()->normalStrings; |
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 Perform the indicated operations. Express your answer in reduced form. $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( $multians->cmp() ); ENDDOCUMENT(); |
Answer Evaluation:
We want to give students feedback on whether their numerator and denominator are correct, so we set |
Example 2: Algebraic fractions without using MultiAnswer
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PGstandard.pl", "PGunion.pl", "MathObjects.pl", "answerHints.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 # Context()->texStrings; 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" ); } Context()->normalStrings; |
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() ->withPostFilter(AnswerHints( Formula("-2x(x^2-4)+4(x^2+4)(x^2-4)") => "Simplify your answer further.", )) ); ANS( $den->cmp() ->withPostFilter(AnswerHints( Formula("(x^2-4)^4") => "Simplify your answer further.", )) ); ENDDOCUMENT(); |
Answer Evaluation:
If you want to give students feedback on whether their numerator and denominator are correct, set
We added custom answer hints provided by |