Difference between revisions of "TrigIdentities1"

From WeBWorK_wiki
Jump to navigation Jump to search
m
Line 5: Line 5:
 
This PG code shows how to redefine a named function internally so that students must apply a trig identity and simplify their answer.
 
This PG code shows how to redefine a named function internally so that students must apply a trig identity and simplify their answer.
 
</p>
 
</p>
* Download file: [[File:TrigIdentities1.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/Trig/TrigIdentities1.pg FortLewis/Authoring/Templates/Trig/TrigIdentities1.pg]
* File location in NPL: <code>FortLewis/Authoring/Templates/Trig/TrigIdentities.pg</code>
 
   
   

Revision as of 22:27, 15 June 2013

Requiring Trig Identities be Used by Cleverly Redefining Functions

Click to enlarge

This PG code shows how to redefine a named function internally so that students must apply a trig identity and simplify their answer.



Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT();  

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"AnswerFormatHelp.pl",
"answerHints.pl",
);

TEXT(beginproblem());

Initialization:

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 redefine the function whose name is tan(x) to take values exp(pi * x).

Context()->texStrings;
BEGIN_TEXT
Simplify the expression as much as possible.
$BR
$BR
\( \tan(x) \cos(x) \) = \{ ans_rule(20) \}
\{ AnswerFormatHelp("formulas") \}
END_TEXT
Context()->normalStrings;

Main Text:

$showPartialCorrectAnswers = 1;

ANS(Formula("sin(x)")->cmp() 
->withPostFilter(AnswerHints(
  Compute("tan(x)*cos(x)") => 
  "No credit for entering what you were given.",
))
);

Answer Evaluation:

Context()->texStrings;
BEGIN_SOLUTION
${PAR}SOLUTION:${PAR}
Solution explanation goes here.
END_SOLUTION
Context()->normalStrings;

COMMENT('MathObject version.');

ENDDOCUMENT();

Solution:

Templates by Subject Area