Difference between revisions of "FactoringAndExpanding"
Line 5: | Line 5: | ||
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> |
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> |
||
<em>This is the PG code to check answers that require students to factor an expression into two pieces that may have a constant factor that could be moved between the pieces.</em> |
<em>This is the PG code to check answers that require students to factor an expression into two pieces that may have a constant factor that could be moved between the pieces.</em> |
||
+ | <br /> |
||
+ | <br /> |
||
+ | This example uses adaptive parameters and a MultiAnswer answer evaluator. For more details on these, please see [http://webwork.maa.org/wiki/AdaptiveParameters AdaptiveParameters] and [http://webwork.maa.org/wiki/MultiAnswerProblems MultiAnswerProblems]. |
||
</p> |
</p> |
||
Revision as of 22:04, 10 April 2010
Factored Answers
This is the PG code to check answers that require students to factor an expression into two pieces that may have a constant factor that could be moved between the pieces.
This example uses adaptive parameters and a MultiAnswer answer evaluator. For more details on these, please see AdaptiveParameters and MultiAnswerProblems.
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "parserMultiAnswer.pl", ); TEXT(beginproblem()); |
Initialization:
We need to include the |
Context("Numeric"); $fac1 = Compute("(2 x + 3)"); $fac2 = Compute("(8 x + 12)"); $multians = MultiAnswer($fac1,$fac2)->with( singleResult => 0, allowBlankAnswers => 1, # singleResult => 1, # separator => " * ", # tex_separator => " \cdot ", checker => sub { my $correct = shift; my $student = shift; my $self = shift; my ($F,$G) = @{$correct}; my ($f,$g) = @{$student}; Value::Error('Neither factor can be constant') unless $f->isFormula && $g->isFormula; Value::Error('Your product does not equal the original (it is incomplete)') unless $F*$G == $f*$g; # return 0 unless $F*$G == $f*$g; # use an adaptive parameter 'a' my $context = Context()->copy; $context->flags->set(no_parameters=>0); $context->variables->add('a'=>'Parameter'); my $a = Formula($context,'a'); $f = Formula($context,$f); my $result = ($a*$F == $f || $a*$G == $f); Value::Error('Factor as the product of two linear functions') unless ($result == 1); return $result; } ); |
Setup:
This is a standard factoring problem for a non-monic polynomial (where the leading coefficient is not 1 or -1). The
The |
Context()->texStrings; BEGIN_TEXT Factor the following expression. $BR $BR \( 16 t^2 + 48 t + 36 = \big( \) \{$multians->ans_rule(10)\} \( \big) \big( \) \{$multians->ans_rule(10)\} \( \big) \) \{ AnswerFormatHelp("formulas") \} END_TEXT Context()->normalStrings; |
Main Text:
Each answer blank must be a method of the |
$showPartialCorrectAnswers = 1; ANS( $multians->cmp() ); ENDDOCUMENT(); |
Answer Evaluation: Everything is as expected. |
- POD documentation: parserMultiAnswer.pl.html
- PG macro: parserMultiAnswer.pl