| 1 | #!/usr/local/bin/webwork-perl |
1 | #!/usr/local/bin/perl |
| 2 | |
2 | |
| 3 | # This file is PGanswermacros.pl |
3 | # This file is PGanswermacros.pl |
| 4 | # This includes the subroutines for the ANS macros, that |
4 | # This includes the subroutines for the ANS macros, that |
| 5 | # is, macros allowing a more flexible answer checking |
5 | # is, macros allowing a more flexible answer checking |
| 6 | #################################################################### |
6 | #################################################################### |
| … | |
… | |
| 1107 | $answer_evaluator->install_pre_filter(\&is_a_number); |
1107 | $answer_evaluator->install_pre_filter(\&is_a_number); |
| 1108 | } elsif ($mode eq 'arith') { |
1108 | } elsif ($mode eq 'arith') { |
| 1109 | $answer_evaluator->install_pre_filter(\&is_an_arithmetic_expression); |
1109 | $answer_evaluator->install_pre_filter(\&is_an_arithmetic_expression); |
| 1110 | } elsif ($mode eq 'frac') { |
1110 | } elsif ($mode eq 'frac') { |
| 1111 | $answer_evaluator->install_pre_filter(\&is_a_fraction); |
1111 | $answer_evaluator->install_pre_filter(\&is_a_fraction); |
|
|
1112 | |
|
|
1113 | } elsif ($mode eq 'phase_pi') { |
|
|
1114 | $answer_evaluator->install_pre_filter(\&phase_pi); |
| 1112 | |
1115 | |
| 1113 | } else { |
1116 | } else { |
| 1114 | $PGanswerMessage = 'Tell your professor that there is an error in his or her answer mechanism. No mode was specified.'; |
1117 | $PGanswerMessage = 'Tell your professor that there is an error in his or her answer mechanism. No mode was specified.'; |
| 1115 | $formattedSubmittedAnswer = $in; |
1118 | $formattedSubmittedAnswer = $in; |
| 1116 | } |
1119 | } |
| … | |
… | |
| 3302 | } else { |
3305 | } else { |
| 3303 | return $is_a_fraction; |
3306 | return $is_a_fraction; |
| 3304 | } |
3307 | } |
| 3305 | } |
3308 | } |
| 3306 | |
3309 | |
|
|
3310 | =head4 phase_pi |
|
|
3311 | I often discovered that the answers I was getting, when using the arctan function would be off by phases of |
|
|
3312 | pi, which for the tangent function, were equivalent values. This method allows for this. |
|
|
3313 | =cut |
|
|
3314 | |
|
|
3315 | sub phase_pi { |
|
|
3316 | my ($num,%options) = @_; |
|
|
3317 | my $process_ans_hash = ( ref( $num ) eq 'AnswerHash' ) ? 1 : 0 ; |
|
|
3318 | my ($rh_ans); |
|
|
3319 | if ($process_ans_hash) { |
|
|
3320 | $rh_ans = $num; |
|
|
3321 | $num = $rh_ans->{correct_ans}; |
|
|
3322 | } |
|
|
3323 | while( ($rh_ans->{correct_ans}) > 3.14159265358979/2 ){ |
|
|
3324 | $rh_ans->{correct_ans} -= 3.14159265358979; |
|
|
3325 | } |
|
|
3326 | while( ($rh_ans->{correct_ans}) <= -3.14159265358979/2 ){ |
|
|
3327 | $rh_ans->{correct_ans} += 3.14159265358979; |
|
|
3328 | } |
|
|
3329 | $rh_ans; |
|
|
3330 | } |
|
|
3331 | |
| 3307 | =head4 is_an_arithemetic_expression |
3332 | =head4 is_an_arithemetic_expression |
| 3308 | |
3333 | |
| 3309 | =cut |
3334 | =cut |
| 3310 | |
3335 | |
| 3311 | sub is_an_arithmetic_expression { |
3336 | sub is_an_arithmetic_expression { |