########################################################### # # Example showing how to use the Parser's differentiation # capabilities. # DOCUMENT(); # This should be the first executable line in the problem. loadMacros( "PGbasicmacros.pl", "PGanswermacros.pl", "Parser.pl", "Differentiation.pl", ); TEXT(beginproblem()); ########################################################### # # Use standard numeric mode # Context('Numeric'); $x = Formula('x'); # used to construct formulas below. # # Define a function and its derivative and make them pretty # $a = random(1,8,1); $b = random(-8,8,1); $c = random(-8,8,1); $f = ($a*$x**2 + $b*$x + $c) -> reduce; $df = $f->D('x'); $x = random(-8,8,1); ########################################################### # # The problem text # BEGIN_TEXT Suppose \(f(x) = \{$f->TeX\}\). $PAR Then \(f'(x)=\) \{ans_rule(20)\},$BR and \(f'($x)=\) \{ans_rule(20)\}. $PAR (Same as previous problem, but using the formal differentiation package. Note that automatic differentiation does not always produce the simples form.) END_TEXT ########################################################### # # The answers # ANS(fun_cmp($df->string)); ANS(num_cmp($df->eval(x=>$x))); $showPartialCorrectAnswers = 1; ########################################################### ENDDOCUMENT(); # This should be the last executable line in the problem.