Difference between revisions of "IdentitiesAsAnswers"
Line 91: | Line 91: | ||
$BR |
$BR |
||
\( \tan(x) \cos(x) \) = \{ ans_rule(20) \} |
\( \tan(x) \cos(x) \) = \{ ans_rule(20) \} |
||
− | \{ AnswerFormatHelp("formulas") \} |
||
END_TEXT |
END_TEXT |
||
</pre> |
</pre> |
Revision as of 01:54, 21 March 2010
Trigonometric Identities
This code shows how to prevent students from receiving credit for entering exactly what they were given, while at the same time allowing the correct answer to be entered for credit, even when what the students were given and the correct answer are the same function.
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "PGcourse.pl", ); TEXT(beginproblem()); |
Initialization: Use MathObjects. |
Context("Numeric"); Context()->functions->remove("tan"); package NewFunc; # this next line makes the function a # function from reals to reals our @ISA = qw(Parser::Function::numeric); sub tan { shift; my $x = shift; return CORE::exp($x*3.1415926535); } package main; # Make it work on formulas as well as numbers sub tan {Parser::Function->call('tan',@_)} # Add the new functions to the Context Context()->functions->add( tan => {class => 'NewFunc', TeX => '\tan'}, ); |
Setup:
We internally redefine the tangent function to be |
BEGIN_TEXT Simplify the expression as much as possible. $BR $BR \( \tan(x) \cos(x) \) = \{ ans_rule(20) \} END_TEXT |
Main Text: The problem text section of the file is as we'd expect. |
$showPartialCorrectAnswers = 1; ANS( Formula("sin(x)")->cmp() ); COMMENT("Prevents students from entering trivial identities (entering what they were given)"); ENDDOCUMENT(); |
Answer Evaluation: As is the answer. |