[npl] / trunk / NationalProblemLibrary / Rochester / setLinearAlgebra11Eigenvalues / ur_la_11_29.pg Repository: Repository Listing bbplugincoursesdistsnplrochestersystemwww

# View of /trunk/NationalProblemLibrary/Rochester/setLinearAlgebra11Eigenvalues/ur_la_11_29.pg

Tue May 2 20:24:19 2006 UTC (7 years ago) by jjholt
File size: 3072 byte(s)
Update tags.


    1 ## DESCRIPTION
2 ## Linear Algebra
3 ## ENDDESCRIPTION
4
5 ## KEYWORDS ('linear algebra','matrix','eigenvalue','basis','orthogonal')
6 ## Tagged by cmd6a 4/30/06
7
8 ## DBsubject('Linear Algebra')
9 ## DBchapter('Matrices')
10 ## DBsection('Eigenvalues')
11 ## Date('')
12 ## Author('')
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
23 "PG.pl",
24 "PGbasicmacros.pl",
25 "PGchoicemacros.pl",
27 "PGgraphmacros.pl",
28 "PGmatrixmacros.pl",
29 "PGnumericalmacros.pl",
30 "PGauxiliaryFunctions.pl",
31 "PGmorematrixmacros.pl"
32 );
33
34 TEXT(beginproblem());
35 $showPartialCorrectAnswers = 1; 36 37$a= new Matrix(3,3);
38
39 # create an invertible matrix with det either 1  or -1
40
41 $a11 = non_zero_random(-2,2,1); 42$a21 = random(-1,1,2);
43 $a31 = random(-1,1,2); 44 45$b1 = random(-1,1,2);
46 $a12 =$b1 * $a11; 47$m = random(-1,1,2);
48 $a22 =$b1 * $a21 +$m;
49 $a32 =$b1 * $a31; 50 51$c = random(-1,1,1);
52 $d = random(-1,1,2); 53$n = random(-1,1,2);
54 $a13 =$c * $a11 +$d * $a12 +$n;
55 $a23 =$c * $a21 +$d * $a22; 56$a33 = $c *$a31 + $d *$a32;
57
58 $det = -$a31 * $m *$n;
59
60 # define matrix
61
62         $a->assign(1,1,$a11 );
63         $a->assign(1,2,$a12 );
64         $a->assign(1,3,$a13 );
65         $a->assign(2,1,$a21 );
66         $a->assign(2,2,$a22 );
67         $a->assign(2,3,$a23 );
68         $a->assign(3,1,$a31 );
69         $a->assign(3,2,$a32 );
70         $a->assign(3,3,$a33 );
71         $a_lr =$a->decompose_LR();
72         $a_det =$a_lr->det_LR();
73
74 # define inverse matrix
75         $b =$a_lr->invert_LR();
76
77 # define eigenvalues
78
79         $e = new Matrix(3,3); 80$e->one();
81
82 $eig1 = non_zero_random(-4,4,1); 83$eig2 = random(-4,4,1);
84 if ($eig1 ==$eig2) { $eig2 =$eig2+1;}
85   $e->assign(1,1,$eig1);
86   $e->assign(2,2,$eig1);
87   $e->assign(3,3,$eig2);
88
89 # define final matrix
90         $matrix =$a * $e *$b;
91         $matrix_lr =$matrix->decompose_LR();
92         $matrix_det =$matrix_lr->det_LR();
93
94 # matrix entries are integers, but we'll round them to avoid printing 0.999999999
95
96 foreach $i (1..3) { 97 foreach$j (1..3) {
98     $m[$i][$j] =$matrix->element($i,$j);
99     $m[$i][$j] = round($m[$i][$j]);
100     $matrix->assign($i,$j,$m[$i][$j]);
101   }
102 }
103
104 BEGIN_TEXT
105
106 \{ mbox( 'The matrix $$A=$$', display_matrix($matrix) ) \} 107 108$BR
109 has two real eigenvalues, $$\lambda_1 = eig1$$ of multiplicity $$2$$, and $$\lambda_2 = eig2$$ of multiplicity $$1$$.
110 Find an orthonormal basis for the eigenspace $$E_1$$.
111 $BR 112 \{ mbox( ans_array(3,1,15), ', ', ans_array_extension(3,1,15), '.' ) \} 113 114 END_TEXT 115 116 # a basis of the eigern space 117$col1 = $a -> column(1); 118$col2 = $a -> column(2); 119 # now apply Gram-Schmidt' 120$scalar = ($col1->scalar_product($col2))/($col1->scalar_product($col1));
121 $col2 =$col2 - $scalar*$col1;
122 # now make them unit vectors
123 $norm1 =$col1->length;
124 $col1 = (1/$norm1)*$col1; 125$norm2 = $col2->length; 126$col2 = (1/$norm2)*$col2;
127
128
129 ANS(basis_cmp([$col1,$col2], 'mode'=>'orthonormal', 'help'=>'verbose'));
130
131 ENDDOCUMENT();       # This should be the last executable line in the problem.
132