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

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

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

Revision 5394 Revision 5440
13 # they want, and it doesn't have to be the one the professor used. 13 # they want, and it doesn't have to be the one the professor used.
14 # 14 #
15 # To use FormulaWithConstat objects, load this macro file at the 15 # To use FormulaWithConstat objects, load this macro file at the
16 # top of your problem: 16 # top of your problem:
17 # 17 #
18 # loadMacros("parserFormulaUpToConstant"); 18 # loadMacros("parserFormulaUpToConstant.pl");
19 # 19 #
20 # then create a formula with constant as follows: 20 # then create a formula with constant as follows:
21 # 21 #
22 # $f = FormulaUpToConstant("sin(x)+C"); 22 # $f = FormulaUpToConstant("sin(x)+C");
23 # 23 #
69 # to the student when the "+ C" is left out. You can turn off 69 # to the student when the "+ C" is left out. You can turn off
70 # these messages using the showHints option to the cmp() method: 70 # these messages using the showHints option to the cmp() method:
71 # 71 #
72 # ANS($f->cmp(showHints => 0)); 72 # ANS($f->cmp(showHints => 0));
73 # 73 #
74 # One of the hints is about whether the student's answer is linear
75 # in the arbitrary constant. This test requires differentiating
76 # the student answer. Since there are times when that could be
77 # problematic, you can disable that test via the showLinearityHints
78 # flag. (Note: setting showHints to 0 also disables these hints.)
79 #
80 # ANS($f->cmp(showLinearityHints => 0));
81 #
74 ###################################################################### 82 ######################################################################
75 83
76=cut 84=cut
77 85
78package FormulaUpToConstant; 86package FormulaUpToConstant;
155 # (remember: return value of 0 is equal, and non-zero is unequal) 163 # (remember: return value of 0 is equal, and non-zero is unequal)
156 # 164 #
157 return abs($context->variables->get("n0")->{value}) < $context->flag("zeroLevelTol"); 165 return abs($context->variables->get("n0")->{value}) < $context->flag("zeroLevelTol");
158} 166}
159 167
168##################################################
169#
170# Here we override part of the answer comparison
171# routines in order to be able to generate
172# helpful error messages for students when
173# they leave off the + C.
174#
175
160# 176#
161# Show hints by default 177# Show hints by default
162# 178#
163sub cmp_defaults {((shift)->SUPER::cmp_defaults,showHints => 1)}; 179sub cmp_defaults {((shift)->SUPER::cmp_defaults,showHints => 1, showLinearityHints => 1)};
164 180
165# 181#
166# Add useful messages, if the author requested them 182# Add useful messages, if the author requested them
167# 183#
168sub cmp_postprocess { 184sub cmp_postprocess {
169 my $self = shift; my $ans = shift; 185 my $self = shift; my $ans = shift;
170 $self->SUPER::cmp_postprocess($ans); 186 $self->SUPER::cmp_postprocess($ans);
171 return unless $ans->{score} == 0 && !$ans->{isPreview}; 187 return unless $ans->{score} == 0 && !$ans->{isPreview};
172 return if $ans->{ans_message} || !$self->getFlag("showHints"); 188 return if $ans->{ans_message} || !$self->getFlag("showHints");
189 my $student = $ans->{student_value};
173 my $result = $ans->{correct_value} <=> $ans->{student_value}; # compare encodes the reason in the result 190 my $result = $ans->{correct_value} <=> $student; # compare encodes the reason in the result
174 $self->cmp_Error($ans,"Note: there is always more than one posibility") if $result == 2 || $result == 3; 191 $self->cmp_Error($ans,"Note: there is always more than one posibility") if $result == 2 || $result == 3;
175 $self->cmp_Error($ans,"Your answer is not the most general solution") 192 $self->cmp_Error($ans,"Your answer is not the most general solution")
176 if $result == 1 || ($result == 3 && $self->removeConstant == $ans->{student_value}); 193 if $result == 1 || ($result == 3 && $self->removeConstant == $student);
194 $self->cmp_Error($ans,"Your formula should be linear in the constant '$student->{constant}'")
195 if $result == -1 && $self->getFlag("showLinearityHints") && !$student->D($student->{constant})->isConstant;
177} 196}
178 197
198##################################################
179# 199#
180# Get the name of the constant 200# Get the name of the constant
181# 201#
182sub constant {(shift)->{constant}} 202sub constant {(shift)->{constant}}
183 203
237 # Do the usual Variable stuff. 257 # Do the usual Variable stuff.
238 # 258 #
239 $self->SUPER::new($equation,$name,$ref); 259 $self->SUPER::new($equation,$name,$ref);
240} 260}
241 261
242
2431; 2621;

Legend:
Removed from v.5394  
changed lines
  Added in v.5440

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9