[system] / trunk / webwork / system / courseScripts / PGdiffeqmacros.pl Repository:
ViewVC logotype

Diff of /trunk/webwork/system/courseScripts/PGdiffeqmacros.pl

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

Revision 107 Revision 108
751 } 751 }
752 752
753} 753}
754 754
755sub check_eigenvector { 755sub check_eigenvector {
756
756 my $eigenvalue = shift; 757 my $eigenvalue = shift;
757 my $matrix = shift; 758 my $matrix = shift;
758 my %options = @_; 759 my %options = @_;
760 assign_option_aliases( \%options, );
761
762 set_default_options( \%options,
763 'debug' => 0,
764 'correct_ans' => undef
765 );
766
767
759 my @correct_vector = (); 768 my @correct_vector = ();
760 @correct_vector = @{$options{'correct_ans'}} if defined ($options{'correct_ans'}); 769 @correct_vector = @{$options{'correct_ans'}} if defined ($options{'correct_ans'});
761 770
762 my $ans_eval = new AnswerEvaluator; 771 my $ans_eval = new AnswerEvaluator;
763 $ans_eval->ans_hash( correct_ans => "( " . join(", ", @correct_vector ) . " )" ); 772
773 $ans_eval->{debug} = $options{debug};
774 my $corr_ans_points = "( " . join(", ", @correct_vector). " )" ;
775 $ans_eval->ans_hash( correct_ans => $corr_ans_points );
764 $ans_eval->install_pre_filter(\&is_array); 776 $ans_eval->install_pre_filter(\&is_array);
765 $ans_eval->install_pre_filter(\&std_num_array_filter); 777 $ans_eval->install_pre_filter(\&std_num_array_filter);
766 778
767 $ans_eval->install_evaluator(sub { my $rh_ans = shift; 779 $ans_eval->install_evaluator(sub { my $rh_ans = shift;
768 my %options = @_; 780 my %options = @_;
769 my @vector = @{$rh_ans->input()}; 781 my @vector = @{$rh_ans->input()};
782 return($rh_ans) unless @correct_vector == @vector;
783 # make sure the vectors are the same dimension
770 784
771 unless (@correct_vector == @vector ) {
772 return($rh_ans) unless @correct_vector == @vector;
773 # make sure the vectors are the same dimension
774 }
775 my $vec = new Matrix(2,1); 785 my $vec = new Matrix(2,1);
776 $vec->assign(1,1, $vector[0]); 786 $vec->assign(1,1, $vector[0]);
777 $vec->assign(2,1, $vector[1]); 787 $vec->assign(2,1, $vector[1]);
778 my $out_vec = $matrix * $vec; 788 my $out_vec = $matrix * $vec;
779 my @diff; 789 my @diff;
782 $rh_ans->{score} = zero_check(\@diff); 792 $rh_ans->{score} = zero_check(\@diff);
783 $rh_ans; 793 $rh_ans;
784 794
785 }); 795 });
786 $ans_eval->install_post_filter( sub { my $rh_ans= shift; 796 $ans_eval->install_post_filter( sub { my $rh_ans= shift;
787 my %options = @_;
788 if ($rh_ans->catch_error('SYNTAX') ) { 797 if ($rh_ans->error_flag('SYNTAX') ) {
789 $rh_ans->{ans_message} = $rh_ans->{error_message}; 798 $rh_ans->{ans_message} = $rh_ans->{error_message};
790 $rh_ans->clear_error('SYNTAX'); 799 $rh_ans->clear_error('SYNTAX');
791 $rh_ans; 800 $rh_ans;
792 } 801 }
793 }); 802 });

Legend:
Removed from v.107  
changed lines
  Added in v.108

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9