Difference between revisions of "DifferentiatingFormulas"

From WeBWorK_wiki
Jump to navigation Jump to search
(One intermediate revision by the same user not shown)
Line 106: Line 106:
 
ANS( $fyx->cmp() );
 
ANS( $fyx->cmp() );
   
ENDDOCUMENT;
+
ENDDOCUMENT();
 
</pre>
 
</pre>
 
<td style="background-color:#eeccff;padding:7px;">
 
<td style="background-color:#eeccff;padding:7px;">
Line 122: Line 122:
   
 
[[Category:Problem Techniques]]
 
[[Category:Problem Techniques]]
  +
  +
  +
<ul>
  +
<li>[http://webwork.maa.org/wiki/Introduction_to_MathObjects Introduction_to_MathObjects]</li>
  +
</ul>

Revision as of 22:08, 3 March 2010

Differentiating Formulas: PG Code Snippet


This PG code shows how to differentiate a MathObjects Formula.

Problem Techniques Index

PG problem file Explanation
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
);
TEXT(beginproblem());

Initialization: In the initialization section, we need to include the macro file MathObjects.pl or be using a parser that loads MathObjects.pl automatically.

Context("Numeric")->variables->add(y=>"Real");

$a = random(2,4,1);
$f = Formula("x*y^2");

$fx  = $f->D('x');
$fxa = $fx->eval(x=>"$a");
$fy  = $f->D('y');
$fyx = $fy->D('x')->reduce;
 

Setup: The Numeric context automatically defines x to be a variable, so we add the variable y to the context. Then, we use the partial differentiation operator D('var_name') to take a partial derivative with respect to that variable. We can use the evaluate feature as expected.

Context()->texStrings;
BEGIN_TEXT
Suppose \( f(x) = $f \).  Then
$PAR
\( \displaystyle \frac{\partial f}{\partial x} \) = \{ans_rule(20)\}
$PAR
\( f_x ($a,y) \) = \{ans_rule(20)\}
$PAR
\( f_y(x,y) \) = \{ans_rule(20)\}
$PAR
\( f_{yx} (x,y) \) = \{ans_rule(20)\}
END_TEXT
Context()->normalStrings;

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

$showPartialCorrectAnswers=1;

ANS( $fx ->cmp() );
ANS( $fxa->cmp() );
ANS( $fy ->cmp() );
ANS( $fyx->cmp() );

ENDDOCUMENT();

Answer Evaluation: As is the answer.

Problem Techniques Index