… | |
… | |
11 | they want, and it doesn't have to be the one the professor used. |
11 | they want, and it doesn't have to be the one the professor used. |
12 | |
12 | |
13 | To use FormulaWithConstat objects, load this macro file at the |
13 | To use FormulaWithConstat objects, load this macro file at the |
14 | top of your problem: |
14 | top of your problem: |
15 | |
15 | |
16 | loadMacros("parserFormulaUpToConstant.pl"); |
16 | loadMacros("parserFormulaUpToConstant.pl"); |
17 | |
17 | |
18 | then create a formula with constant as follows: |
18 | then create a formula with constant as follows: |
19 | |
19 | |
20 | $f = FormulaUpToConstant("sin(x)+C"); |
20 | $f = FormulaUpToConstant("sin(x)+C"); |
21 | |
21 | |
22 | Note that the C should NOT already be a variable in the Context; |
22 | Note that the C should NOT already be a variable in the Context; |
23 | the FormulaUpToConstant object will handle adding it in for |
23 | the FormulaUpToConstant object will handle adding it in for |
24 | you. If you don't include a constant in your formula (i.e., if |
24 | you. If you don't include a constant in your formula (i.e., if |
25 | all the variables that you used are already in your Context, |
25 | all the variables that you used are already in your Context, |
26 | then the FormulaUpToConstant object will add "+C" for you. |
26 | then the FormulaUpToConstant object will add "+C" for you. |
27 | |
27 | |
28 | The FormulaUpToConstant should work like any normal Formula, |
28 | The FormulaUpToConstant should work like any normal Formula, |
29 | and in particular, you use $f->cmp to get its answer checker. |
29 | and in particular, you use $f->cmp to get its answer checker. |
30 | |
30 | |
31 | ANS($f->cmp); |
31 | ANS($f->cmp); |
32 | |
32 | |
33 | Note that the FormulaUpToConstant object creates its only private |
33 | Note that the FormulaUpToConstant object creates its only private |
34 | copy of the current Context (so that it can add variables without |
34 | copy of the current Context (so that it can add variables without |
35 | affecting the rest of the problem). You should not notice this |
35 | affecting the rest of the problem). You should not notice this |
36 | in general, but if you need to access that context, use $f->{context}. |
36 | in general, but if you need to access that context, use $f->{context}. |
37 | E.g. |
37 | E.g. |
38 | |
38 | |
39 | Context($f->{context}); |
39 | Context($f->{context}); |
40 | |
40 | |
41 | would make the current context the one being used by the |
41 | would make the current context the one being used by the |
42 | FormulaUpToConstant, while |
42 | FormulaUpToConstant, while |
43 | |
43 | |
44 | $f->{context}->variables->names |
44 | $f->{context}->variables->names |
45 | |
45 | |
46 | would return a list of the variables in the private context. |
46 | would return a list of the variables in the private context. |
47 | |
47 | |
48 | To get the name of the constant in use in the formula, |
48 | To get the name of the constant in use in the formula, |
49 | use |
49 | use |
50 | |
50 | |
51 | $f->constant. |
51 | $f->constant. |
52 | |
52 | |
53 | If you combine a FormulaUpToConstant with other formulas, |
53 | If you combine a FormulaUpToConstant with other formulas, |
54 | the result will be a new FormulaUpToConstant object, with |
54 | the result will be a new FormulaUpToConstant object, with |
55 | a new Context, and potentially a new + C added to it. This |
55 | a new Context, and potentially a new + C added to it. This |
56 | is likely not what you want. Instead, you should convert |
56 | is likely not what you want. Instead, you should convert |
57 | back to a Formula first, then combine with other objects, |
57 | back to a Formula first, then combine with other objects, |
58 | then convert back to a FormulaUpToConstant, if necessary. |
58 | then convert back to a FormulaUpToConstant, if necessary. |
59 | To do this, use the removeConstant() method: |
59 | To do this, use the removeConstant() method: |
60 | |
60 | |
61 | $f = FormulaUpToConstant("sin(x)+C"); |
61 | $f = FormulaUpToConstant("sin(x)+C"); |
62 | $g = Formula("cos(x)"); |
62 | $g = Formula("cos(x)"); |
63 | $h = $f->removeConstant + $g; # $h will be "sin(x)+cos(x)" |
63 | $h = $f->removeConstant + $g; # $h will be "sin(x)+cos(x)" |
64 | $h = FormulaUpToConstant($h); # $h will be "sin(x)+cos(x)+C" |
64 | $h = FormulaUpToConstant($h); # $h will be "sin(x)+cos(x)+C" |
65 | |
65 | |
66 | The answer evaluator by default will give "helpful" messages |
66 | The answer evaluator by default will give "helpful" messages |
67 | to the student when the "+ C" is left out. You can turn off |
67 | to the student when the "+ C" is left out. You can turn off |
68 | these messages using the showHints option to the cmp() method: |
68 | these messages using the showHints option to the cmp() method: |
69 | |
69 | |
70 | ANS($f->cmp(showHints => 0)); |
70 | ANS($f->cmp(showHints => 0)); |
71 | |
71 | |
72 | One of the hints is about whether the student's answer is linear |
72 | One of the hints is about whether the student's answer is linear |
73 | in the arbitrary constant. This test requires differentiating |
73 | in the arbitrary constant. This test requires differentiating |
74 | the student answer. Since there are times when that could be |
74 | the student answer. Since there are times when that could be |
75 | problematic, you can disable that test via the showLinearityHints |
75 | problematic, you can disable that test via the showLinearityHints |
76 | flag. (Note: setting showHints to 0 also disables these hints.) |
76 | flag. (Note: setting showHints to 0 also disables these hints.) |
77 | |
77 | |
78 | ANS($f->cmp(showLinearityHints => 0)); |
78 | ANS($f->cmp(showLinearityHints => 0)); |
79 | |
79 | |
80 | =cut |
80 | =cut |
81 | |
81 | |
82 | loadMacros("MathObjects.pl"); |
82 | loadMacros("MathObjects.pl"); |
83 | |
83 | |