########################################################### # # Example showing how to use the Parser to make # a formula that you can evaluate and print in TeX form. # 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'); # # Define some functions # $a = non_zero_random(-8,8,1); $b = random(1,8,1); @f = ( "1 + $a*x + $b x^2", "$a / (1 + $b x)", "$a x^3 + $b", "($a - x) / ($b + x^2)" ); # # Pick one at random # $k = random(0,$#f,1); $f = Formula($f[$k])->reduce; # # Where to evaluate it # $x = random(-5,5,1); ########################################################### # # The problem text # BEGIN_TEXT If \(\displaystyle f(x) = \{$f->TeX\}\) then \(f($x)=\) \{ans_rule(10)\}. END_TEXT ########################################################### # # The answer # ANS(num_cmp($f->eval(x=>$x))); $showPartialCorrectAnswers = 1; ########################################################### ENDDOCUMENT(); # This should be the last executable line in the problem.