[system] / trunk / webwork2 / doc / parser / problems / sample03.pg Repository: Repository Listing bbplugincoursesdistsnplrochestersystemwww

# View of /trunk/webwork2/doc/parser/problems/sample03.pg

Sat Aug 14 19:33:10 2004 UTC (8 years, 9 months ago) by dpvc
File size: 1409 byte(s)
```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
10   "PGbasicmacros.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 #