This shows how to check "arbitrary" conditions on the student's answer.
Download file: DifferentiatingFormulas.pg
DOCUMENT();
loadMacros('PGstandard.pl', 'PGML.pl', 'PGcourse.pl');
Preamble
These standard macros need to be loaded.Context()->variables->add(y => 'Real');
$a = random(2, 4);
$f = Formula('x^2y');
$fx = $f->D('x');
$fxa = $fx->substitute(x => $a);
$fy = $f->D('y');
$fyx = $fy->D('x')->reduce;
Setup
The Numeric context includes the variable x
by default, but the variable y must be added to the
context.
The differentiation operator D(variable name) is used to
take a partial derivative with respect to the variable give for
variable name. Note that the differentaion operator returns
a MathObject Formula.
The substitute method is used to evaluate the
Formula for the partial derivative with respect to
x at a particular value.
BEGIN_PGML
Suppose [`f(x) = [$f]`]. Then
a. [``\frac{\partial f}{\partial x} =``] [____]{$fx}
b. [`f_x ([$a],y) =`] [____]{$fxa}
c. [`f_y(x, y) =`] [____]{$fy}
d. [`f_{yx}(x, y) =`] [___]{$fyx}
END_PGML
Statement
This is the problem statement in PGML.BEGIN_PGML_SOLUTION Solution explanation goes here. END_PGML_SOLUTION ENDDOCUMENT();
Solution
A solution should be provided here.