[system] / trunk / pg / macros / contextScientificNotation.pl Repository:
ViewVC logotype

Diff of /trunk/pg/macros/contextScientificNotation.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 5550 Revision 5551
1=head1 NAME
2
3contextScientificNotation.pl - Allows entry of scientific notation.
4
5=head1 DESCRIPTION
6
7This file implements a context in which students can enter
8answers in scientific notation. It tries hard to report
9useful error messages when the student's answer is not
10in the proper format, and it also allows you to control
11how many decimal digits they are allowed/required to
12enter, and how many the system will display.
13
14This probably should be called LimitedScientificNotation
15since it does not allow any operations other than the ones
16needed in Scientific notation. In the future it may be
17renamed if we produce a computational scientific notation
18context.
19
20To use this context, add
21
22 loadMacros("contextScientificNotation.pl");
23
24to the top of your problem file, and then use
25
26 Context("ScientificNotation");
27
28to select the contxt and make it active. You can create
29values in scientific notation in two ways:
30
31 $n1 = Compute("1.23 x 10^3");
32
33or
34
35 $n2 = ScientificNotation(1.23 * 10**3);
36
37(or even $n2 = ScientificNotation(1230), and it will be converted).
38
39You can control how many digits are displayed by setting the
40snDigits flag in the context. For example,
41
42 Context()->flags->set(snDigits=>2);
43
44sets the context to display at most 2 digits. The default is 6.
45By default, trailing zeros are removed, but you can ask that
46they be retained by issuing the command
47
48 Context()->flags->set(snTrimZeros=>0);
49
50It is also possible to specify how many decimal digits the
51student must enter. For example,
52
53 Context()->flags->set(snMinDigits=>3);
54
55would require the student to enter at least 3 digits past
56the decimal place (for a total of 4 significant digits,
57including the one to the left of the decimal). The default
58is 1 digit beyond the decimal. A value of 0 means that
59a decimal point and decimal values is optional.
60
61Similarly,
62
63 Context()->flags->set(snMaxDigits=>6);
64
65sets the maximum number to 6, so the student can't enter
66more than that. Setting this to 0 means no decimal places
67are allowed, effectively meaning students can only enter
68the numbers 0 through 9 (times a power of 10). Setting
69this to a negative number means that there is no upper
70limit on the number of digits the student may enter (this
71is the default).
72
73As an example, in order to force a fixed precision of
74three digits of precision, use
75
76 Context()->flags->set(
77 snDigits => 3,
78 snTrimZeros => 0,
79 snMinDigits => 3,
80 snMaxDigits => 3,
81 );
82
83Note that if you restrict the number of digits, you may
84need to adjust the tolerance values since the student
85may not be allowed to enter a more precise answer. In
86the example above, it would be appropriate to set the
87tolerance to .0001 and the tolType to "relative" in
88order to require the answers to be correct to the three
89digits that are shown.
90
91=cut
92
1loadMacros("MathObjects.pl"); 93loadMacros("MathObjects.pl");
2 94
3sub _contextScientificNotation_init {ScientificNotation::Init()} 95sub _contextScientificNotation_init {ScientificNotation::Init()}
4
5=head1 Context("ScientificNotation");
6
7 #########################################################################
8 #
9 # This file implements a context in which students can enter
10 # answers in scientific notation. It tries hard to report
11 # useful error messages when the student's answer is not
12 # in the proper format, and it also allows you to control
13 # how many decimal digits they are allowed/required to
14 # enter, and how many the system will display.
15 #
16 # This probably should be called LimitedScientificNotation
17 # since it does not allow any operations other than the ones
18 # needed in Scientific notation. In the future it may be
19 # renamed if we produce a computational scientific notation
20 # context.
21 #
22 # To use this context, add
23 #
24 # loadMacros("contextScientificNotation.pl");
25 #
26 # to the top of your problem file, and then use
27 #
28 # Context("ScientificNotation");
29 #
30 # to select the contxt and make it active. You can create
31 # values in scientific notation in two ways:
32 #
33 # $n1 = Compute("1.23 x 10^3");
34 #
35 # or
36 #
37 # $n2 = ScientificNotation(1.23 * 10**3);
38 #
39 # (or even $n2 = ScientificNotation(1230), and it will be converted).
40 #
41 # You can control how many digits are displayed by setting the
42 # snDigits flag in the context. For example,
43 #
44 # Context()->flags->set(snDigits=>2);
45 #
46 # sets the context to display at most 2 digits. The default is 6.
47 # By default, trailing zeros are removed, but you can ask that
48 # they be retained by issuing the command
49 #
50 # Context()->flags->set(snTrimZeros=>0);
51 #
52 # It is also possible to specify how many decimal digits the
53 # student must enter. For example,
54 #
55 # Context()->flags->set(snMinDigits=>3);
56 #
57 # would require the student to enter at least 3 digits past
58 # the decimal place (for a total of 4 significant digits,
59 # including the one to the left of the decimal). The default
60 # is 1 digit beyond the decimal. A value of 0 means that
61 # a decimal point and decimal values is optional.
62 #
63 # Similarly,
64 #
65 # Context()->flags->set(snMaxDigits=>6);
66 #
67 # sets the maximum number to 6, so the student can't enter
68 # more than that. Setting this to 0 means no decimal places
69 # are allowed, effectively meaning students can only enter
70 # the numbers 0 through 9 (times a power of 10). Setting
71 # this to a negative number means that there is no upper
72 # limit on the number of digits the student may enter (this
73 # is the default).
74 #
75 # As an example, in order to force a fixed precision of
76 # three digits of precision, use
77 #
78 # Context()->flags->set(
79 # snDigits => 3,
80 # snTrimZeros => 0,
81 # snMinDigits => 3,
82 # snMaxDigits => 3,
83 # );
84 #
85 # Note that if you restrict the number of digits, you may
86 # need to adjust the tolerance values since the student
87 # may not be allowed to enter a more precise answer. In
88 # the example above, it would be appropriate to set the
89 # tolerance to .0001 and the tolType to "relative" in
90 # order to require the answers to be correct to the three
91 # digits that are shown.
92 #
93
94=cut
95 96
96package ScientificNotation; 97package ScientificNotation;
97 98
98# 99#
99# Creates and initializes the ScientificNotation context 100# Creates and initializes the ScientificNotation context

Legend:
Removed from v.5550  
changed lines
  Added in v.5551

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9