DifferentiatingFormulas: Difference between revisions
Jump to navigation
Jump to search
(New page: <h2>Differentiating Formulas: PG Code Snippet</h2> <!-- Header for these sections -- no modification needed --> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"...) |
(added historical tag and gave updated problem link) |
||
(7 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
{{historical}} | |||
<p style="font-size: 120%;font-weight:bold">This problem has been replaced with [https://openwebwork.github.io/pg-docs/sample-problems/DiffCalc/DifferentiateFunction.html a newer version of this problem]</p> | |||
<h2>Differentiating Formulas: PG Code Snippet</h2> | <h2>Differentiating Formulas: PG Code Snippet</h2> | ||
Line 34: | Line 37: | ||
<p> | <p> | ||
<b>Initialization:</b> | <b>Initialization:</b> | ||
In the initialization section, we need to include the macro file <code>MathObjects.pl</code>. | In the initialization section, we need to include the macro file <code>MathObjects.pl</code> or be using a parser that loads MathObjects.pl automatically. | ||
</p> | </p> | ||
</td> | </td> | ||
Line 52: | Line 55: | ||
$fxa = $fx->eval(x=>"$a"); | $fxa = $fx->eval(x=>"$a"); | ||
$fy = $f->D('y'); | $fy = $f->D('y'); | ||
$ | $fyx = $fy->D('x')->reduce; | ||
</pre> | </pre> | ||
</td> | </td> | ||
Line 61: | Line 64: | ||
x to be a variable, so we add the variable y to the context. | x to be a variable, so we add the variable y to the context. | ||
Then, we use the partial differentiation operator <code>D('var_name')</code> | Then, we use the partial differentiation operator <code>D('var_name')</code> | ||
to take a partial derivative with respect to that variable. | to take a partial derivative with respect to that variable. We can use the evaluate | ||
feature as expected. | |||
</p> | </p> | ||
</td> | </td> | ||
Line 81: | Line 85: | ||
\( f_y(x,y) \) = \{ans_rule(20)\} | \( f_y(x,y) \) = \{ans_rule(20)\} | ||
$PAR | $PAR | ||
\( f_{ | \( f_{yx} (x,y) \) = \{ans_rule(20)\} | ||
END_TEXT | END_TEXT | ||
Context()->normalStrings; | Context()->normalStrings; | ||
Line 98: | Line 102: | ||
<td style="background-color:#eeddff;border:black 1px dashed;"> | <td style="background-color:#eeddff;border:black 1px dashed;"> | ||
<pre> | <pre> | ||
ANS( $fx->cmp() ); | $showPartialCorrectAnswers=1; | ||
ANS( $fx ->cmp() ); | |||
ANS( $fxa->cmp() ); | ANS( $fxa->cmp() ); | ||
ANS( $fy->cmp() ); | ANS( $fy ->cmp() ); | ||
ANS( $ | ANS( $fyx->cmp() ); | ||
ENDDOCUMENT; | ENDDOCUMENT(); | ||
</pre> | </pre> | ||
<td style="background-color:#eeccff;padding:7px;"> | <td style="background-color:#eeccff;padding:7px;"> | ||
Line 119: | Line 125: | ||
[[Category:Problem Techniques]] | [[Category:Problem Techniques]] | ||
<ul> | |||
<li>[http://webwork.maa.org/wiki/Introduction_to_MathObjects Introduction_to_MathObjects]</li> | |||
</ul> |
Latest revision as of 13:20, 28 June 2023
This problem has been replaced with a newer version of this problem
Differentiating Formulas: PG Code Snippet
This PG code shows how to differentiate a MathObjects Formula.
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", ); TEXT(beginproblem()); |
Initialization:
In the initialization section, we need to include the macro file |
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 |
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. |