Difference between revisions of "AlgebraicFractionAnswer1"
Paultpearson (talk | contribs) m |
Paultpearson (talk | contribs) |
||
Line 5: | Line 5: | ||
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. |
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. |
||
</p> |
</p> |
||
− | * Download file: [[File:AlgebraicFractionAnswer1.txt]] (change the file extension from txt to pg when you save it) |
||
+ | * File location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Algebra/AlgebraicFractionAnswer1.pg FortLewis/Authoring/Templates/Algebra/AlgebraicFractionAnswer1.pg] |
||
− | * File location in NPL: <code>FortLewis/Authoring/Templates/Algebra/AlgebraicFractionAnswer1.pg</code> |
||
<br clear="all" /> |
<br clear="all" /> |
Revision as of 23:15, 15 June 2013
Answers that are Algebraic Fractions that Require Simplification
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.
- File location in OPL: FortLewis/Authoring/Templates/Algebra/AlgebraicFractionAnswer1.pg
PG problem file | Explanation |
---|---|
Problem tagging: |
|
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"); Context()->{error}{msg}{"Operands of '*' can't be words"} = " "; $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"); $den = Formula("y - $c"); $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, $self ) = @_; my ( $f1stu, $f2stu ) = @{$student}; my ( $f1, $f2 ) = @{$correct}; if ( ( $f1==$f1stu && $f2==$f2stu) || (-$f1==$f1stu && -$f2==$f2stu) ) { return [1,1]; } elsif ( $f1==$f1stu || -$f1==$f1stu) { return [1,0]; } elsif ( ($numbogus==$f1stu || -$numbogus==$f1stu) || ($denbogus==$f2stu || -$denbogus==$f2stu) ) { $self->setMessage(1,"Find a common denominator first"); $self->setMessage(2,"Find a common denominator first"); return [0,0]; } elsif ( $f2==$f2stu || -$f2==$f2stu ) { return [0,1]; } elsif ( $f1*$f2stu==$f1stu*$f2 ) { $self->setMessage(1,"Simplify your answer further"); $self->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 \[ ... \]and append two concatenated answer blanks to the string $fraction . In other modes (such as html), we use a ColumnTable from PGunion.pl macros to display the answer blanks as a fraction.
To get fractions that have a large font size, be sure to use the LaTeX command \( \displaystyle \frac{a}{b} \) For fractions over fractions (a/b) / (c/d), to keep the font size large use the LaTeX commands \( \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() ); |
Answer Evaluation:
We want to give students feedback on whether their numerator and denominator are correct, so we set |
Context()->texStrings; BEGIN_SOLUTION ${PAR}SOLUTION:${PAR} Solution explanation goes here. END_SOLUTION Context()->normalStrings; COMMENT('MathObject version.'); ENDDOCUMENT(); |
Solution: |