Parent Directory
|
Revision Log
Updated example files to use new features of parser and its answer checkers.
1 ########################################################### 2 # 3 # Example showing how to use the Parser's differentiation 4 # capabilities. 5 # 6 7 DOCUMENT(); # This should be the first executable line in the problem. 8 9 loadMacros( 10 "PGbasicmacros.pl", 11 "PGanswermacros.pl", 12 "Parser.pl", 13 "Differentiation.pl", 14 ); 15 16 TEXT(beginproblem()); 17 18 ########################################################### 19 # 20 # Use standard numeric mode 21 # 22 Context('Numeric'); 23 $x = Formula('x'); # used to construct formulas below. 24 25 # 26 # Define a function and its derivative and make them pretty 27 # 28 $a = random(1,8,1); 29 $b = random(-8,8,1); 30 $c = random(-8,8,1); 31 32 $f = ($a*$x**2 + $b*$x + $c) -> reduce; 33 $df = $f->D('x'); 34 35 $x = random(-8,8,1); 36 37 ########################################################### 38 # 39 # The problem text 40 # 41 BEGIN_TEXT 42 43 Suppose \( f(x) = \{$f->TeX\}\). 44 $PAR 45 Then \(f'(x)=\) \{ans_rule(20)\},$BR 46 and \(f'($x)=\) \{ans_rule(20)\}. 47 $PAR 48 (Same as previous problem, but using the formal differentiation package. 49 Note that automatic differentiation does not always produce the simples form.) 50 51 END_TEXT 52 53 ########################################################### 54 # 55 # The answers 56 # 57 ANS(fun_cmp($df->string)); 58 ANS(num_cmp($df->eval(x=>$x))); 59 $showPartialCorrectAnswers = 1; 60 61 ########################################################### 62 63 ENDDOCUMENT(); # This should be the last executable line in the problem.
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |