PrimeOperator

From WeBWorK_wiki
Revision as of 02:10, 27 November 2010 by Pearson (talk | contribs) (Update documentation links)
Jump to navigation Jump to search

Prime Operator (Differentiation)


This PG code shows how to allow the prime operator for differentiation.

Problem Techniques Index

PG problem file Explanation
DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserPrime.pl",
"parserAssignment.pl",
);

TEXT(beginproblem());

Initialization: We need to include the macros file parserPrime.pl.

Context("Numeric")->variables->add(y=>"Real");
Context()->constants->add(k=>0.01);
Context()->flags->set(formatStudentAnswer=>'parsed');

parser::Assignment->Allow;

# only use partial derivatives with respect to x
parser::Prime->Enable("x");

$answer1 = Formula("y = k x'");
$answer2 = Formula("(x^2)' + (y^2)'");

parser::Prime->Disable;

Setup: We need to enable the prime operator, and ought to also specify the variable for partial differentiation.

BEGIN_TEXT
Enter the equation \( y = k x' \) or \( y = k \):
\{ ans_rule(20) \} 
$PAR
Since we defined the prime operator as the partial
derivative with respect to \( x \), 
enter the expression \( (x^2+y^2)' \) or \( 2x \):
\{ ans_rule(20) \}
END_TEXT

Main Text: The problem text section of the file is as we'd expect.

$showPartialCorrectAnswers = 1;

ANS( $answer1->cmp() );
ANS( $answer2->cmp() );

ENDDOCUMENT();

Answer Evaluation: As is the answer.

Problem Techniques Index