########################################################### # # Example showing how you can use perl expressions (not # just character strings) to generate formulas. # DOCUMENT(); # This should be the first executable line in the problem. loadMacros( "PGbasicmacros.pl", "PGanswermacros.pl", "Parser.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 = (2*$a*$x + $b) -> reduce; $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)\}. 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.