Difference between revisions of "IdentitiesAsAnswers"

From WeBWorK_wiki
Jump to navigation Jump to search
(New page: <h2>Trigonometric Identities</h2> <!-- Header for these sections -- no modification needed --> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> <em>This code s...)
 
m (11 revisions: import all default namespace pages from old wiki)
 
(10 intermediate revisions by one other user not shown)
Line 1: Line 1:
<h2>Trigonometric Identities</h2>
 
  +
<h2>Identities As Answers (Trig Identities, Laws of Logarithms and Exponents, etc.)</h2>
   
 
<!-- Header for these sections -- no modification needed -->
 
<!-- Header for these sections -- no modification needed -->
   
 
<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 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.</em>
+
<em>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 identical functions written in different ways (such as trig identities, laws of logarithms, laws of exponents, etc).</em>
 
</p>
 
</p>
   
Line 29: Line 29:
 
"MathObjects.pl",
 
"MathObjects.pl",
 
"PGcourse.pl",
 
"PGcourse.pl",
  +
"answerHints.pl",
 
);
 
);
   
Line 76: Line 77:
 
it will still appear as the tangent function. (The student will have no clue
 
it will still appear as the tangent function. (The student will have no clue
 
that the tangent function has been redefined.) Of course, we have to choose
 
that the tangent function has been redefined.) Of course, we have to choose
carefully which functions we would like to redefine.
+
carefully which functions we would like to redefine, and also redefine them as a
  +
function that a student is unlikely to type in (such as exchanging a trig function
  +
for an exponential function).
 
</p>
 
</p>
 
</td>
 
</td>
Line 91: Line 92:
 
$BR
 
$BR
 
\( \tan(x) \cos(x) \) = \{ ans_rule(20) \}
 
\( \tan(x) \cos(x) \) = \{ ans_rule(20) \}
\{ AnswerFormatHelp("formulas") \}
 
 
END_TEXT
 
END_TEXT
 
</pre>
 
</pre>
Line 109: Line 109:
 
$showPartialCorrectAnswers = 1;
 
$showPartialCorrectAnswers = 1;
   
ANS( Formula("sin(x)")->cmp() );
+
ANS( Formula("sin(x)")->cmp()
  +
->withPostFilter(AnswerHints(
  +
Formula("tan(x)*cos(x)") =>
  +
"No credit for entering what you were given.",
  +
))
  +
);
   
COMMENT("Prevents students from entering trivial identities (entering what they were given)");
+
COMMENT("Prevents students from entering trivial
  +
identities (entering what they were given)");
   
 
ENDDOCUMENT();
 
ENDDOCUMENT();
Line 118: Line 118:
 
<p>
 
<p>
 
<b>Answer Evaluation:</b>
 
<b>Answer Evaluation:</b>
As is the answer.
 
  +
We use an answer hint to tell students that the cannot enter what they were given and receive credit.
  +
We include a comment visible only to instructors when they view the problem via the Library Browser that lets others know that this question won't allow students to enter exactly what they were given and earn credit.
 
</p>
 
</p>
 
</td>
 
</td>

Latest revision as of 16:19, 14 May 2010

Identities As Answers (Trig Identities, Laws of Logarithms and Exponents, etc.)


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 identical functions written in different ways (such as trig identities, laws of logarithms, laws of exponents, etc).

Problem Techniques Index

PG problem file Explanation
DOCUMENT();  

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGcourse.pl",
"answerHints.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 e^(pi*x) so that if a student enters tan(x) cos(x), WeBWorK will evaluate it as the function e^(pi x) cos(x). Since e^(pi x) cos(x) does not equal sin(x), if the student enters tan(x) cos(x) it will be marked incorrect. We have redefined the value of the function named tangent, though not given it a different name, so to the student it will still appear as the tangent function. (The student will have no clue that the tangent function has been redefined.) Of course, we have to choose carefully which functions we would like to redefine, and also redefine them as a function that a student is unlikely to type in (such as exchanging a trig function for an exponential function).

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() 
->withPostFilter(AnswerHints(
  Formula("tan(x)*cos(x)") => 
  "No credit for entering what you were given.",
))
);

COMMENT("Prevents students from entering trivial 
identities (entering what they were given)");

ENDDOCUMENT();

Answer Evaluation: We use an answer hint to tell students that the cannot enter what they were given and receive credit. We include a comment visible only to instructors when they view the problem via the Library Browser that lets others know that this question won't allow students to enter exactly what they were given and earn credit.

Problem Techniques Index