Parent Directory
|
Revision Log
Log message
1 ## DESCRIPTION 2 ## Linear Algebra 3 ## ENDDESCRIPTION 4 5 ## KEYWORDS ('linear algebra','matrix','eigenvalue','eigenvector') 6 ## Tagged by cmd6a 4/30/06 7 8 ## DBsubject('Linear Algebra') 9 ## DBchapter('Matrices') 10 ## DBsection('Eigenvalues') 11 ## Date('') 12 ## Author('modified by Shifrin') 13 ## Institution('Rochester') 14 ## TitleText1('') 15 ## EditionText1('') 16 ## AuthorText1('') 17 ## Section1('') 18 ## Problem1('') 19 20 DOCUMENT(); # This should be the first executable line in the problem. 21 22 loadMacros("PG.pl", 23 "PGbasicmacros.pl", 24 "PGchoicemacros.pl", 25 "PGanswermacros.pl", 26 "PGgraphmacros.pl", 27 "PGmatrixmacros.pl", 28 "PGnumericalmacros.pl", 29 "PGdiffeqmacros.pl" 30 ); 31 32 33 TEXT(beginproblem()); 34 $showPartialCorrectAnswers = 1; 35 36 $a= new Matrix(2,2); 37 # define matrix 38 $a11 = random(-1,1,2); 39 $a12 = non_zero_random(-3,3,1); 40 $mult = non_zero_random(-2,2,1); 41 $a21 = $mult * $a11; 42 $b1 = random(-1,1,2); 43 $a22 = $mult * $a12 + $b1; 44 45 $a->assign(1,1, $a11 ); 46 $a->assign(1,2, $a12 ); 47 $a->assign(2,1, $a21 ); 48 $a->assign(2,2, $a22 ); 49 $a_lr = $a->decompose_LR(); 50 $a_det = $a11 * $b1; 51 52 # define inverse matrix 53 $b = $a_lr->invert_LR(); 54 # define eigenvalues 55 $e = new Matrix(2,2); 56 $e->one(); 57 $e->assign(1,1, non_zero_random(-8,8,1)); 58 $e->assign(2,2, non_zero_random(-8,8,1)); 59 # make sure that the eigenvalues are distinct 60 while ($e->element(1,1) == $e->element(2,2)) { $e->assign(2,2, non_zero_random(-8,8,1)); } 61 # define final matrix 62 $matrix = $a * $e *$b; 63 $matrix_lr = $matrix->decompose_LR(); 64 $matrix_det = $matrix_lr->det_LR(); 65 66 BEGIN_TEXT 67 68 Find the eigenvalues and eigenvectors of the matrix 69 70 \( A= \{display_matrix_mm($matrix)\}\) . 71 $PAR 72 The smaller eigenvalue is \{ans_rule(10)\}, 73 with \{mbox('associated eigenvector', display_matrix([[ NAMED_ANS_RULE(vec1,10) ],[ NAMED_ANS_RULE_OPTION(vec1,10)]]),'.') \} 74 $BR 75 The larger eigenvalue is \{ ans_rule(10) \}, with 76 \{mbox('associated eigenvector', display_matrix([[ NAMED_ANS_RULE(vec2,10)], [NAMED_ANS_RULE_OPTION(vec2,10)]]), '.') \} 77 78 79 END_TEXT 80 if ( $e->element(1,1) < $e->element(2,2) ) { 81 ANS(num_cmp($e->element(1,1),tol=>.1)); 82 NAMED_ANS(vec1 => check_eigenvector($e->element(1,1), $matrix, 83 correct_ans =>[$a->column(1)->list]) ); 84 ANS(num_cmp($e->element(2,2),tol=>.1)); 85 NAMED_ANS(vec2 =>check_eigenvector($e->element(2,2), $matrix, 86 correct_ans =>[$a->column(2)->list]) );; 87 } else { 88 ANS(num_cmp($e->element(2,2),tol=>.1)); 89 NAMED_ANS(vec1 => check_eigenvector($e->element(2,2), $matrix, 90 correct_ans =>[$a->column(2)->list]) ); 91 ANS(num_cmp($e->element(1,1),tol=>.1)); 92 NAMED_ANS(vec2 => check_eigenvector($e->element(1,1), $matrix, 93 correct_ans =>[$a->column(1)->list]) ); 94 } 95 96 97 ######################################################### 98 # sub check_eigenvector { 99 # my $eigenvalue = shift; 100 # my $matrix = shift; 101 # my %options = @_; 102 # my @correct_vector = (); 103 # @correct_vector = @{$options{'correct_ans'}} if defined($options{'correct_ans'}); 104 # $ans_eval = sub { 105 # my $in = shift @_; 106 # my @in1 = split("~~0",$in); 107 # my $ans_hash = new AnswerHash( 108 # 'score' => 0, 109 # 'correct_ans' => "( " . join(", ", @correct_vector ) . " )", 110 # 'student_ans' => "( " . join(", ", @in1 ) . " )", 111 # 'ans_message' => '', 112 # 'type' => "std_number", 113 # 'preview_text_string' => '', 114 # 'preview_latex_string' => '', 115 # 'original_student_ans' => $in 116 # ); 117 # my @in=(); 118 # foreach $i (0..$#in1) { 119 # if ($in1[$i] =~/~~S/ ) { 120 # ($in[$i],$PG_eval_errors,$PG_full_error_report) = PG_answer_eval(math_constants($in1[$i])); 121 # } else { 122 # $PG_eval_errors = ' '; 123 # } 124 # if ($PG_eval_errors) { ##error message from eval or above 125 # $formattedSubmittedAnswer = $PG_eval_errors; 126 # $formattedSubmittedAnswer =clean_up_error_msg($formattedSubmittedAnswer); 127 # $PGanswerMessage = 'There is a syntax error in your answer'; 128 # $PGanswerMessage = '' if $PG_eval_errors eq ' '; 129 # my $ans_hash = new AnswerHash( 130 # 'score' => 0, 131 # 'correct_ans' => "( " . join(", ", @correct_vector ) . " )", 132 # 'student_ans' => [@in], 133 # 'ans_message' => $PGanswerMessage, 134 # 'type' => 'std_number', 135 # 'preview_text_string' => ' ', 136 # 'preview_latex_string' => ' ', 137 # 'original_student_ans' => "( " . join(", ", @in1 ) . " )" 138 # ); 139 # return($ans_hash); 140 # } 141 # } 142 # return($ans_hash) unless @correct_vector == @in; # make sure the vectors are the same dimension 143 # $vec = new Matrix(2,1); 144 # $vec->assign(1,1, $in[0]); 145 # $vec->assign(2,1, $in[1]); 146 # $out_vec = $matrix * $vec; 147 # $diff[0] = $out_vec->element(1,1) - $vec->element(1,1)*$eigenvalue; 148 # $diff[1] = $out_vec->element(2,1) - $vec->element(2,1)*$eigenvalue; 149 # $ans_hash->{score} = zero_check(~~@diff); 150 # $ans_hash; 151 # }; 152 # $ans_eval; 153 # } 154 # 155 156 157 ENDDOCUMENT() ; 158 159 160
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |