Differentiating Formulas

This shows how to check "arbitrary" conditions on the student's answer.

Complete Code

Download file: DifferentiatingFormulas.pg

PG problem file

Explanation

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, 1);
$f = Formula("x*y^2");

$fx  = $f->D('x');
$fxa = $fx->substitute(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.

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.