"Diary" file---log of computer applications in class. Math 310, Applied Linear Algebra Fall 2006, S. Smith ...to begin below, as of Monday 28 August 2006: octave:2> quit octave:2> 'mon 28 aug06' octave:2> a = [1 1 ; 1 -1] a = 1 1 1 -1 octave:3> quit octave:4> b = [7 5]' b = 7 5 octave:5> augmat = [a,b] augmat = 1 1 7 1 -1 5 octave:6> 'this is example of entering an augmented matrix' ans = this is example of entering an augmented matrix octave:7> 'end mon 28 aug 06' octave:8> quit octave:2> 'start wed 30 aug' ans = start wed 30 aug octave:3> a = [ 1 1 ; 1 -1] a = 1 1 1 -1 octave:4> b = [ 5 7 ]' b = 5 7 octave:5> aug = [a,b] aug = 1 1 5 1 -1 7 octave:6> copy = aug copy = 1 1 5 1 -1 7 octave:7> b = [7 5]' b = 7 5 octave:8> aug = [a,b] aug = 1 1 7 1 -1 5 octave:9> copy = aug copy = 1 1 7 1 -1 5 octave:10> copy(2,:) = -1 * copy(1,:) + copy(2,:) copy = 1 1 7 0 -2 -2 octave:11> 'now finish by doing back substitution' ans = now finish by doing back substitution octave:12> 'end wed 30 aug 06' ans = end wed 30 aug 06 octave:13> quit octave:2> 'start fri 1 sept 06' ans = start fri 1 sept 06 octave:3> clear octave:4> 'example of Gauss-Jordan using matlab/octave' ans = example of Gauss-Jordan using matlab/octave octave:5> a = [ 1 2 3; 4 5 6; 7 8 9] a = 1 2 3 4 5 6 7 8 9 octave:6> b = [ 6 15 24]' b = 6 15 24 octave:7> aug = [a,b] aug = 1 2 3 6 4 5 6 15 7 8 9 24 octave:8> rref(aug) error: `rref' undefined near line 8 column 1 error: evaluating index expression near line 8, column 1 octave:8> ref(aug) error: `ref' undefined near line 8 column 1 error: evaluating index expression near line 8, column 1 octave:8> help echelon help: sorry, `echelon' is not documented Additional help for builtin functions, operators, and variables is available in the on-line version of the manual. Use the command `help -i ' to search the manual index. Help and information about Octave is also available on the WWW at http://www.che.wisc.edu/octave/octave.html and via the help-octave@bevo.che.wisc.edu mailing list. octave:9> help -i echelon help: sorry, `echelon' is not indexed in the manual octave:10> help -i reduce help: sorry, `reduce' is not indexed in the manual octave:11> 'cant find software, sigh' ans = cant find software, sigh octave:12> quit octave:2> 'addendum, after class on Fri 1 Sept' ans = addendum, after class on Fri 1 Sept octave:3> 'our old version of octave does not have rref; but I found a copy...' ans = our old version of octave does not have rref; but I found a copy... octave:4> 'so here is that example I tried to give in class' ans = so here is that example I tried to give in class octave:5> a = [1 2 3; 4 5 6; 7 8 9] a = 1 2 3 4 5 6 7 8 9 octave:6> b = [6 15 24]' b = 6 15 24 octave:7> aug = [a,b] aug = 1 2 3 6 4 5 6 15 7 8 9 24 octave:8> rref(aug) ans = 1.00000 0.00000 -1.00000 0.00000 0.00000 1.00000 2.00000 3.00000 0.00000 0.00000 0.00000 0.00000 octave:9> 'and this is what we got in doing Gauss-Jordan by hand' ans = and this is what we got in doing Gauss-Jordan by hand octave:10> 'end of addendum for Fri 1 Sept 06' ans = end of addendum for Fri 1 Sept 06 octave:11> quit octave:2> 'start wed 6 sept 06' ans = start wed 6 sept 06 octave:3> 'set up equations for exer 13' ans = set up equations for exer 13 octave:4> a = [1 -1 0 0; -1 0 0 -1; 0 1 -1 0; 0 0 1 0] a = 1 -1 0 0 -1 0 0 -1 0 1 -1 0 0 0 1 0 octave:5> b = [50 870 -120 350]' b = 50 870 -120 350 octave:6> aug = [a,b] aug = 1 -1 0 0 50 -1 0 0 -1 870 0 1 -1 0 -120 0 0 1 0 350 octave:7> rref(aug) ans = 1 0 0 0 280 0 1 0 0 230 0 0 1 0 350 0 0 0 1 -1150 octave:8> b(2) = -870 b = 50 -870 -120 350 octave:9> aug = [a,b] aug = 1 -1 0 0 50 -1 0 0 -1 -870 0 1 -1 0 -120 0 0 1 0 350 octave:10> rref(aug) ans = 1 0 0 0 280 0 1 0 0 230 0 0 1 0 350 0 0 0 1 590 octave:11> 'exer 20a' ans = exer 20a octave:12> a = [1 -1 1 ; 2 2 0; 0 2 3 ] a = 1 -1 1 2 2 0 0 2 3 octave:13> b = [0 16 0]' b = 0 16 0 octave:14> aug = [a,b] aug = 1 -1 1 0 2 2 0 16 0 2 3 0 octave:15> rref(aug) ans = 1 0 0 5 0 1 0 3 0 0 1 -2 octave:16> a = [ 6 0 -1 0; 6 0 0 -2; 0 2 0 -1] a = 6 0 -1 0 6 0 0 -2 0 2 0 -1 octave:17> b = [0 0 0]' b = 0 0 0 octave:18> aug = [a,b] aug = 6 0 -1 0 0 6 0 0 -2 0 0 2 0 -1 0 octave:19> rref(aug) ans = 1.00000 0.00000 0.00000 -0.33333 0.00000 0.00000 1.00000 0.00000 -0.50000 0.00000 0.00000 0.00000 1.00000 -2.00000 0.00000 octave:20> 'did setup of appl4, no time for soln' ans = did setup of appl4, no time for soln octave:21> 'end of wed 6 sept' ans = end of wed 6 sept octave:22> quit octave:2> 'start fri 8 sept 06' ans = start fri 8 sept 06 octave:3> 'comment on sec 1.2 no 6b' ans = comment on sec 1.2 no 6b octave:4> a = [1 3 1 1; 2 -2 1 2; 3 1 2 -1] a = 1 3 1 1 2 -2 1 2 3 1 2 -1 octave:5> b = [3 8 -1]' b = 3 8 -1 octave:6> aug = [a,b] aug = 1 3 1 1 3 2 -2 1 2 8 3 1 2 -1 -1 octave:7> rref(aug) ans = 1.00000 0.00000 0.62500 0.00000 0.75000 0.00000 1.00000 0.12500 0.00000 -0.25000 0.00000 0.00000 0.00000 1.00000 3.00000 octave:8> 'exer 19 of sec 1.2' ans = exer 19 of sec 1.2 octave:9> a = [1/3 1/3 1/3; 1/3 1/2 1/6 ; 1/3 1/6 1/2] a = 0.33333 0.33333 0.33333 0.33333 0.50000 0.16667 0.33333 0.16667 0.50000 octave:10> b = [0 0 0]' b = 0 0 0 octave:11> aug = [a,b] aug = 0.33333 0.33333 0.33333 0.00000 0.33333 0.50000 0.16667 0.00000 0.33333 0.16667 0.50000 0.00000 octave:12> eye(3) ans = 1 0 0 0 1 0 0 0 1 octave:13> reduceda = a - eye(3) reduceda = -0.66667 0.33333 0.33333 0.33333 -0.50000 0.16667 0.33333 0.16667 -0.50000 octave:14> aug = [reduceda,b] aug = -0.66667 0.33333 0.33333 0.00000 0.33333 -0.50000 0.16667 0.00000 0.33333 0.16667 -0.50000 0.00000 octave:15> rref(aug) ans = 1.00000 0.00000 -1.00000 0.00000 0.00000 1.00000 -1.00000 0.00000 0.00000 0.00000 0.00000 0.00000 octave:16> 'matrix addition and scalar mult' ans = matrix addition and scalar mult octave:17> a = [1 2 3; 4 5 6] a = 1 2 3 4 5 6 octave:18> b = [3 1 7; 2 4 1] b = 3 1 7 2 4 1 octave:19> a + b ans = 4 3 10 6 9 7 octave:20> 5 * a ans = 5 10 15 20 25 30 octave:21> a a = 1 2 3 4 5 6 octave:22> a' ans = 1 4 2 5 3 6 octave:23> 'matrix mult' ans = matrix mult octave:24> a = [1 2 3 ; 4 5 6] a = 1 2 3 4 5 6 octave:25> b = [2 5 8 ; 3 6 9 ; 4 7 10] b = 2 5 8 3 6 9 4 7 10 octave:26> a * b ans = 20 38 56 47 92 137 octave:27> a = [1 2; 3 4] a = 1 2 3 4 octave:28> b = [5 6]' b = 5 6 octave:29> aug = [a,b] aug = 1 2 5 3 4 6 octave:30> rref(aug) ans = 1.00000 0.00000 -4.00000 0.00000 1.00000 4.50000 octave:31> 'so soln is' ans = so soln is octave:32> x = [-4 4.5]' x = -4.0000 4.5000 octave:33> 'check with matrix mult' ans = check with matrix mult octave:34> a * x ans = 5 6 octave:35> b b = 5 6 octave:36> 'so a*x really is b, so solution x worked' ans = so a*x really is b, so solution x worked octave:37> 'alternate way, see of ax-b is zero' ans = alternate way, see of ax-b is zero octave:38> a * x -b ans = 0 0 octave:39> 'appl 2 used in exer 30' ans = appl 2 used in exer 30 octave:40> a = [.7 .2; .3 .8] a = 0.70000 0.20000 0.30000 0.80000 octave:41> x = [8000 2000]' x = 8000 2000 octave:42> 'a * x is result after 1 time unit' ans = a * x is result after 1 time unit octave:43> a * x ans = 6000 4000 octave:44> 'exer 3, after 3 year? answer a^3 * x' ans = exer 3, after 3 year? answer a^3 * x octave:45> a * a * a * x ans = 4500.0 5500.0 octave:46> a^3 * x ans = 4500 5500 octave:47> 'end fri 8 sept' ans = end fri 8 sept octave:48> quit octave:2> 'start mon 11 sept' ans = start mon 11 sept octave:3> 'examples of matrix mult used to do row operations' ans = examples of matrix mult used to do row operations octave:4> a = [1 2 3 ; 4 5;6] error: number of columns must match error: number of columns must match error: evaluating assignment expression near line 4, column 3 octave:4> a = [1 2 3; 4 5 6] a = 1 2 3 4 5 6 octave:5> 'operation o desired is , add twice first row to second row' ans = operation o desired is , add twice first row to second row octave:6> 'old way, by hand, as in sec. 1.2:' ans = old way, by hand, as in sec. 1.2: octave:7> b = a b = 1 2 3 4 5 6 octave:8> b(2,:)= 2*b(1,:) + b(2,:) b = 1 2 3 6 9 12 octave:9> e = eye(2) e = 1 0 0 1 octave:10> 'apply operation o to that identity matrix:" error: unterminated string constant parse error: >>> 'apply operation o to that identity matrix:" ^ octave:10> e(2,1) = 2 e = 1 0 2 1 octave:11> 'this matrix e will be the elem matrix used to do the operation o, by matrix mult' ans = this matrix e will be the elem matrix used to do the operation o, by matrix mult octave:12> 'that is, this is the sec 1.4 way of doing it' ans = that is, this is the sec 1.4 way of doing it octave:13> e * a ans = 1 2 3 6 9 12 octave:14> 'examples like exer 2 about inverses' ans = examples like exer 2 about inverses octave:15> e = ( 0 1 ; 1 0] parse error: >>> e = ( 0 1 ; 1 0] ^ octave:15> a = [ 0 1 ; 1 0 ] a = 0 1 1 0 octave:16> 'claim that is its own inverse, that is, a * a should be id' ans = claim that is its own inverse, that is, a * a should be id octave:17> a * a ans = 1 0 0 1 octave:18> e = [5 0 ; 0 1] e = 5 0 0 1 octave:19> f = [1/5 0 ; 0 1] f = 0.20000 0.00000 0.00000 1.00000 octave:20> 'claim f is inverse of e, that is, f * e = id' ans = claim f is inverse of e, that is, f * e = id octave:21> f * e ans = 1 0 0 1 octave:22> e = [1 0 ; 2 1] e = 1 0 2 1 octave:23> f = [1 0 ; -2 1] f = 1 0 -2 1 octave:24> 'claim f is inverse of e, that is, f * e = id' ans = claim f is inverse of e, that is, f * e = id octave:25> f * e ans = 1 0 0 1 octave:26> 'exer 3a' ans = exer 3a octave:27> a = [2 -1; 5 3] a = 2 -1 5 3 octave:28> b = [-4 2 ; 5 3] b = -4 2 5 3 octave:29> 'operation o needed is , mult 1st row by -2' ans = operation o needed is , mult 1st row by -2 octave:30> 'so to get matrix, do that op to identity' ans = so to get matrix, do that op to identity octave:31> e = eye(2) e = 1 0 0 1 octave:32> e(1,1) = -2 e = -2 0 0 1 octave:33> e * a ans = -4 2 5 3 octave:34> b b = -4 2 5 3 octave:35> e*a - b ans = 0 0 0 0 octave:36> 'exer 6a' ans = exer 6a octave:37> a = [2 1 1 ; 6 4 5 ; 4 1 3] a = 2 1 1 6 4 5 4 1 3 octave:38> e1 = eye(3) e1 = 1 0 0 0 1 0 0 0 1 octave:39> e1(2,1) = -3 e1 = 1 0 0 -3 1 0 0 0 1 octave:40> e2 = eye(3) e2 = 1 0 0 0 1 0 0 0 1 octave:41> e2(3,1) = -3 e2 = 1 0 0 0 1 0 -3 0 1 octave:42> e3 =eye(3) e3 = 1 0 0 0 1 0 0 0 1 octave:43> e3(3,2) = 1 e3 = 1 0 0 0 1 0 0 1 1 octave:44> 32(3,1) = -2 parse error: >>> 32(3,1) = -2 ^ octave:44> e2(3,1) = -2 e2 = 1 0 0 0 1 0 -2 0 1 octave:45> e3 * e2 * e1 * a ans = 2 1 1 0 1 2 0 0 3 octave:46> 'end mon 11 sept 06' ans = end mon 11 sept 06 octave:47> quit octave:2> 'start wed 13 sept 06' ans = start wed 13 sept 06 octave:3> 'exer 9' ans = exer 9 octave:4> a = [ 1 0 1; 3 3 4; 2 2 3] a = 1 0 1 3 3 4 2 2 3 octave:5> b = [1 2 -3; -1 1 -1; 0 -2 3] b = 1 2 -3 -1 1 -1 0 -2 3 octave:6> 'to verify b is inverse of a, multiply & see if identity results' ans = to verify b is inverse of a, multiply & see if identity results octave:7> a * b ans = 1 0 0 0 1 0 0 0 1 octave:8> a * b - eye(3) ans = 0 0 0 0 0 0 0 0 0 octave:9> a a = 1 0 1 3 3 4 2 2 3 octave:10> inv(a) ans = 1.0000e-00 2.0000e+00 -3.0000e+00 -1.0000e+00 1.0000e-00 -1.0000e-00 3.3307e-16 -2.0000e+00 3.0000e+00 octave:11> b b = 1 2 -3 -1 1 -1 0 -2 3 octave:12> 'lets check 10a on computer' ans = lets check 10a on computer octave:13> a = [-1 1 ; 1 0] a = -1 1 1 0 octave:14> 'we calculated b as being the inverse of a' ans = we calculated b as being the inverse of a octave:15> b = [0 1; 1 1] b = 0 1 1 1 octave:16> a * b ans = 1 0 0 1 octave:17> a * b - eye(2) ans = 0 0 0 0 octave:18> inv(a) ans = 0 1 1 1 octave:19> b b = 0 1 1 1 octave:20> 'go back to exer 6, and do part b' ans = go back to exer 6, and do part b octave:21> a = [2 1 1; 6 4 5; 4 1 3] a = 2 1 1 6 4 5 4 1 3 octave:22> e1 = [1 0 0; -3 1 0; 0 0 1] e1 = 1 0 0 -3 1 0 0 0 1 octave:23> e2 = [1 0 0 ; 0 1 0; -2 0 1] e2 = 1 0 0 0 1 0 -2 0 1 octave:24> e3 = [1 0 0 ; 0 1 0 ; 0 1 1] e3 = 1 0 0 0 1 0 0 1 1 octave:25> l = inv(e1) * inv(e2) * inv(e3) l = 1 0 0 3 1 0 2 -1 1 octave:26> l * u error: `u' undefined near line 26 column 5 error: evaluating expression near line 26, column 5 error: evaluating binary operator `*' near line 26, column 3 error: evaluating assignment expression near line 26, column 3 octave:26> u = [2 1 1; 0 1 2; 0 0 3] u = 2 1 1 0 1 2 0 0 3 octave:27> a , l , u a = 2 1 1 6 4 5 4 1 3 l = 1 0 0 3 1 0 2 -1 1 u = 2 1 1 0 1 2 0 0 3 octave:28> l * u ans = 2 1 1 6 4 5 4 1 3 octave:29> a a = 2 1 1 6 4 5 4 1 3 octave:30> l * u - a ans = 0 0 0 0 0 0 0 0 0 octave:31> l,u l = 1 0 0 3 1 0 2 -1 1 u = 2 1 1 0 1 2 0 0 3 octave:32> 'so we did express a as a product of lower and upper triangular matrices' ans = so we did express a as a product of lower and upper triangular matrices octave:33> 'end wed 13 sept 06' ans = end wed 13 sept 06 octave:34> quit octave:2> 'start fri 15 sept' ans = start fri 15 sept octave:3> 'exer 8a on lu-decomposition' ans = exer 8a on lu-decomposition octave:4> a = [3 1 ; 9 5] a = 3 1 9 5 octave:5> e1 = [1 0; -3 1] e1 = 1 0 -3 1 octave:6> e1 * a ans = 3 1 0 2 octave:7> u = [3 1; 0 2] u = 3 1 0 2 octave:8> inv(e1) ans = 1 0 3 1 octave:9> l = inv(e1) l = 1 0 3 1 octave:10> l * u ans = 3 1 9 5 octave:11> a a = 3 1 9 5 octave:12> 'so we computed our l and our u, and their product is a' ans = so we computed our l and our u, and their product is a octave:13> u u = 3 1 0 2 octave:14> a,l,u a = 3 1 9 5 l = 1 0 3 1 u = 3 1 0 2 octave:15> [x,y] = lu(a) x = 0.33333 1.00000 1.00000 0.00000 y = 9.00000 5.00000 0.00000 -0.66667 octave:16> [p,x,y] = lu(a) p = 1.00000 0.00000 0.33333 1.00000 x = 9.00000 5.00000 0.00000 -0.66667 y = 0 1 1 0 octave:17> a a = 3 1 9 5 octave:18> x * u ans = 27.00000 19.00000 0.00000 -1.33333 octave:19> x * y ans = 5.00000 9.00000 -0.66667 0.00000 octave:20> p * a ans = 3.0000 1.0000 10.0000 5.3333 octave:21> x * y ans = 5.00000 9.00000 -0.66667 0.00000 octave:22> y *x ans = 0.00000 -0.66667 9.00000 5.00000 octave:23> help lu lu is a builtin function [L, U, P] = lu (A): LU factorization Additional help for builtin functions, operators, and variables is available in the on-line version of the manual. Use the command `help -i ' to search the manual index. Help and information about Octave is also available on the WWW at http://www.che.wisc.edu/octave/octave.html and via the help-octave@bevo.che.wisc.edu mailing list. octave:24> [x,y,p ] = lu(a) x = 1.00000 0.00000 0.33333 1.00000 y = 9.00000 5.00000 0.00000 -0.66667 p = 0 1 1 0 octave:25> p * a ans = 9 5 3 1 octave:26> x * y ans = 9 5 3 1 octave:27> 'look at exer 12a' ans = look at exer 12a octave:28> a = [5 3; 3 2] a = 5 3 3 2 octave:29> b = [6 2 ; 2 4] b = 6 2 2 4 octave:30> c = [4 -2 ; -6 3] c = 4 -2 -6 3 octave:31> '12a says solve ax + b = c' ans = 12a says solve ax + b = c octave:32> d = c - b d = -2 -4 -8 -1 octave:33> e = inv(a) * d e = 20.0000 -5.0000 -34.0000 7.0000 octave:34> 'this should be our x, test it:' ans = this should be our x, test it: octave:35> a * e + b ans = 4.0000 -2.0000 -6.0000 3.0000 octave:36> c c = 4 -2 -6 3 octave:37> a *x + b -c ans = 8.0000 7.0000 11.6667 3.0000 octave:38> a*x + b ans = 12.0000 5.0000 5.6667 6.0000 octave:39> a * e + b - c ans = 7.1054e-15 1.7764e-15 0.0000e+00 3.5527e-15 octave:40> x = e x = 20.0000 -5.0000 -34.0000 7.0000 octave:41> (c - b) * inv(a) ans = 8.0000 -14.0000 -13.0000 19.0000 octave:42> 'end fri 15 sept' ans = end fri 15 sept octave:43> quit octave:2> 'start mon 18 sept' ans = start mon 18 sept octave:3> 'sec 2.1, exer 3d' ans = sec 2.1, exer 3d octave:4> a = [4 3 0; 3 1 2; 5 -1 -4] a = 4 3 0 3 1 2 5 -1 -4 octave:5> det(a) ans = 58 octave:6> 'end mon 18 sept 06' ans = end mon 18 sept 06 octave:7> quit octave:2> 'start wed 20 sept 06' ans = start wed 20 sept 06 octave:3> 'lets check our answer to sec 2.2 number 2a' ans = lets check our answer to sec 2.2 number 2a octave:4> a = [0 1 2 3; 1 1 1 1; -2 -2 3 3; 1 2 -2 -3] a = 0 1 2 3 1 1 1 1 -2 -2 3 3 1 2 -2 -3 octave:5> det(a) ans = 10 octave:6> 'end wed 20 sept 06' ans = end wed 20 sept 06 octave:7> qauit error: `qauit' undefined near line 7 column 1 error: evaluating expression near line 7, column 1 octave:7> octave:7> quit octave:2> ' error: unterminated string constant parse error: >>> ' ^ octave:2> 'start monday 25 sept 06' ans = start monday 25 sept 06 octave:3> 'no computer examples done today; all theory!' ans = no computer examples done today; all theory! octave:4> 'end monday 25 sept 06' ans = end monday 25 sept 06 octave:5> quit octave:2> 'start fri 29 sept 06' ans = start fri 29 sept 06 octave:3> 'lets check for rref present' ans = lets check for rref present octave:4> a = [1 2 ; 3 4 ] a = 1 2 3 4 octave:5> rref(a) ans = 1 0 0 1 octave:6> 'so it is there again!' ans = so it is there again! octave:7> a = [-1 2 3; 3 4 2]' a = -1 3 2 4 3 2 octave:8> b = [2 6 6]' b = 2 6 6 octave:9> aug = [a,b] aug = -1 3 2 2 4 6 3 2 6 octave:10> rref(aug) ans = 1 0 0 0 1 0 0 0 1 octave:11> b = [-9 -2 5]' b = -9 -2 5 octave:12> aug = [a,b] aug = -1 3 -9 2 4 -2 3 2 5 octave:13> rref(aug) ans = 1 0 3 0 1 -2 0 0 0 octave:14> a = [1 1 1; 0 1 -2]' a = 1 0 1 1 1 -2 octave:15> b = [1 -1 0]' b = 1 -1 0 octave:16> aug = [a,b] aug = 1 0 1 1 1 -1 1 -2 0 octave:17> rref(aug) ans = 1 0 0 0 1 0 0 0 1 octave:18> 'end fri 29 sept 06' ans = end fri 29 sept 06 octave:19> quit octave:2> 'start wed 4 oct 06' ans = start wed 4 oct 06 octave:3> 'exer 2a' ans = exer 2a octave:4> a = [1 0 0; 0 1 1; 1 0 1]' a = 1 0 1 0 1 0 0 1 1 octave:5> b = [ 0 0 0]' b = 0 0 0 octave:6> aug = [a,b] aug = 1 0 1 0 0 1 0 0 0 1 1 0 octave:7> rref(aug) ans = 1 0 0 0 0 1 0 0 0 0 1 0 octave:8> 'only zero soln, so answer is lin.indep' ans = only zero soln, so answer is lin.indep octave:9> 'exer 2b' ans = exer 2b octave:10> a = [1 0 0; 0 1 1; 1 0 1; 1 2 3]' a = 1 0 1 1 0 1 0 2 0 1 1 3 octave:11> aug = [a,b] aug = 1 0 1 1 0 0 1 0 2 0 0 1 1 3 0 octave:12> rref(aug) ans = 1 0 0 0 0 0 1 0 2 0 0 0 1 1 0 octave:13> '4th col has no pivot, so inf no of solutions, nonzero, so ans is lin.dep.' ans = 4th col has no pivot, so inf no of solutions, nonzero, so ans is lin.dep. octave:14> 'exer 4c' ans = exer 4c octave:15> a = [ 1 0 2; 0 1 3; 0 0 0; 1 0 2] a = 1 0 2 0 1 3 0 0 0 1 0 2 octave:16> b b = 0 0 0 octave:17> b = [0 0 0 0]' b = 0 0 0 0 octave:18> aug = [a,b] aug = 1 0 2 0 0 1 3 0 0 0 0 0 1 0 2 0 octave:19> rref(aug) ans = 1 0 2 0 0 1 3 0 0 0 0 0 0 0 0 0 octave:20> 'exer 6c' ans = exer 6c octave:21> a = [2 1 -1; 1 1 0; 0 0 1] a = 2 1 -1 1 1 0 0 0 1 octave:22> b = [0 0 0]' b = 0 0 0 octave:23> aug = [a,b] aug = 2 1 -1 0 1 1 0 0 0 0 1 0 octave:24> rref(aug) ans = 1 0 0 0 0 1 0 0 0 0 1 0 octave:25> 'end wwed 4 oct 06' ans = end wwed 4 oct 06 octave:26> quit octave:2> 'start fri 6 oct 06' ans = start fri 6 oct 06 octave:3> 'sec 3.4, exer 8' ans = sec 3.4, exer 8 octave:4> x1 = [1 1 1]' x1 = 1 1 1 octave:5> x2 = [3 -1 4]' x2 = 3 -1 4 octave:6> 'are x1 x2 LI? error: unterminated string constant parse error: >>> 'are x1 x2 LI? ^ octave:6> ' error: unterminated string constant parse error: >>> ' ^ octave:6> aug =[x1,x2] aug = 1 3 1 -1 1 4 octave:7> rref(aug) ans = 1 0 0 1 0 0 octave:8> 'make bad choice' ans = make bad choice octave:9> b = x1 +x2 b = 4 0 5 octave:10> aug = [x1,x2,b] aug = 1 3 4 1 -1 0 1 4 5 octave:11> rref(aug) ans = 1 0 1 0 1 1 0 0 0 octave:12> 'so this b does n ot make x1 x2 b into a basis, since not LI' ans = so this b does n ot make x1 x2 b into a basis, since not LI octave:13> 'try adding vectors from std basis' ans = try adding vectors from std basis octave:14> xe = [1 0 0] xe = 1 0 0 octave:15> aug = [x1,x2,x3] error: `x3' undefined near line 15 column 14 error: evaluating expression near line 15, column 14 error: evaluating assignment expression near line 15, column 5 octave:15> x3 = [1 0 0]' x3 = 1 0 0 octave:16> aug = [ x1 , x2, x3] aug = 1 3 1 1 -1 0 1 4 0 octave:17> rref(aug) ans = 1 0 0 0 1 0 0 0 1 octave:18> octave:18> octave:18> octave:18> 'exer 10' ans = exer 10 octave:19> x1 = [1 2 2]' x1 = 1 2 2 octave:20> x2 = [ 2 5 4]' x2 = 2 5 4 octave:21> x3 = [1 3 2]' x3 = 1 3 2 octave:22> x4 = [2 7 4]' x4 = 2 7 4 octave:23> x5 = [11 0]' x5 = 11 0 octave:24> x5 = [1 1 10]' x5 = 1 1 10 octave:25> x5 = [1 1 0 ]' x5 = 1 1 0 octave:26> 'check span' ans = check span octave:27> aug [x1, x2, x3 , x4, x5] parse error: use `(' and `)' as index operators, not `[' and `]' >>> aug [x1, x2, x3 , x4, x5] ^ octave:27> rref(aug) ans = 1 0 0 0 1 0 0 0 1 octave:28> aug = [x1 , x2, x3, x4 , x5] aug = 1 2 1 2 1 2 5 3 7 1 2 4 2 4 0 octave:29> rref(aug) ans = 1 0 -1 -4 0 0 1 1 3 0 0 0 0 0 1 octave:30> aug = x1 aug = 1 2 2 octave:31> rref(x1) ans = 1 0 0 octave:32> aug = [x1,x2] aug = 1 2 2 5 2 4 octave:33> rref(aug) ans = 1 0 0 1 0 0 octave:34> aug = [x1,x2,x3] aug = 1 2 1 2 5 3 2 4 2 octave:35> rref(aug) ans = 1 0 -1 0 1 1 0 0 0 octave:36> 'so cant add x3; try x4' ans = so cant add x3; try x4 octave:37> aug = [x1 , x2, x4] aug = 1 2 2 2 5 7 2 4 4 octave:38> rref(aug) ans = 1 0 -4 0 1 3 0 0 0 octave:39> 'so cant add x4, try x5' ans = so cant add x4, try x5 octave:40> aug = [x1, x2, x5] aug = 1 2 1 2 5 1 2 4 0 octave:41> rref(aug) ans = 1 0 0 0 1 0 0 0 1 octave:42> 'end fri 6 oct' ans = end fri 6 oct octave:43> quit octave:2> 'start mon 9 oct 06' ans = start mon 9 oct 06 octave:3> 'no computer examples done today' ans = no computer examples done today octave:4> 'end mon 9 oct 06' ans = end mon 9 oct 06 octave:5> quit octave:2> 'start wed 11 oct' ans = start wed 11 oct octave:3> 'sec 3.5,exer 4 on coordinates in the basis E' ans = sec 3.5,exer 4 on coordinates in the basis E octave:4> e1 = [5 3]' e1 = 5 3 octave:5> e2 = [3 2]' e2 = 3 2 octave:6> a = [e1, e2] a = 5 3 3 2 octave:7> x = [1 1]' x = 1 1 octave:8> y = [1 -1]' y = 1 -1 octave:9> z = [10 7]' z = 10 7 octave:10> aug= [a,x] aug = 5 3 1 3 2 1 octave:11> rref(aug) ans = 1.00000 0.00000 -1.00000 0.00000 1.00000 2.00000 octave:12> aug = [a,y] aug = 5 3 1 3 2 -1 octave:13> rref(aug) ans = 1.00000 0.00000 5.00000 0.00000 1.00000 -8.00000 octave:14> 'for z' ans = for z octave:15> aug = [a,z] aug = 5 3 10 3 2 7 octave:16> rref(aug) ans = 1.00000 0.00000 -1.00000 0.00000 1.00000 5.00000 octave:17> 'example of exer 9 TYPe' ans = example of exer 9 TYPe octave:18> a = [2 2; -1 1] a = 2 2 -1 1 octave:19> b = [3 7[4~]' parse error: >>> b = [3 7[4~]' ^ octave:19> b = [3 7]' b = 3 7 octave:20> aug =[a,b] aug = 2 2 3 -1 1 7 octave:21> rref(aug) ans = 1.00000 0.00000 -2.75000 0.00000 1.00000 4.25000 octave:22> 'end wed 11 oct' ans = end wed 11 oct octave:23> quit octave:2> 'start fri 13 oct' ans = start fri 13 oct octave:3> 'exer 2a' ans = exer 2a octave:4> 'need inverse of matrix from 1a' ans = need inverse of matrix from 1a octave:5> a = [1 1; -1 1]' a = 1 -1 1 1 octave:6> inv(a) ans = 0.50000 0.50000 -0.50000 0.50000 octave:7> 'exer 3a---now neither old or new is standard basis' ans = exer 3a---now neither old or new is standard basis octave:8> a = [1 1; -1 1]' a = 1 -1 1 1 octave:9> v1 = [3 2]' v1 = 3 2 octave:10> aug = [a,v1] aug = 1 -1 3 1 1 2 octave:11> rref(aug) ans = 1.00000 0.00000 2.50000 0.00000 1.00000 -0.50000 octave:12> v~v2 = [4 3]' parse error: >>> v~v2 = [4 3]' ^ octave:12> v2 = [4 3]' v2 = 4 3 octave:13> aug = [a,v2] aug = 1 -1 4 1 1 3 octave:14> rref(aug) ans = 1.00000 0.00000 3.50000 0.00000 1.00000 -0.50000 octave:15> a = [1 1 1; 1 2 2; 2 3 4]' a = 1 1 2 1 2 3 1 2 4 octave:16> inv(a) ans = 2 0 -1 -1 2 -1 0 -1 1 octave:17> t = inv(a) t = 2 0 -1 -1 2 -1 0 -1 1 octave:18> 'exer 5b part i' ans = exer 5b part i octave:19> v = [3 2 5]' v = 3 2 5 octave:20> 'this IS the coord vector in old = std basis' ans = this IS the coord vector in old = std basis octave:21> 'so just mult by trans matrix' ans = so just mult by trans matrix octave:22> newcoord = t * v newcoord = 1 -4 3 octave:23> 'COULD have done coords in part (b) by DIRECT computing" error: unterminated string constant parse error: >>> 'COULD have done coords in part (b) by DIRECT computing" ^ octave:23> a a = 1 1 2 1 2 3 1 2 4 octave:24> aug = [a,v] aug = 1 1 2 3 1 2 3 2 1 2 4 5 octave:25> rref(aug) ans = 1 0 0 1 0 1 0 -4 0 0 1 3 octave:26> 'exer 9a, easy direction, SEE coordinates needed' ans = exer 9a, easy direction, SEE coordinates needed octave:27> a = [2 -1 ; 2 1]' a = 2 2 -1 1 octave:28> inv(a) ans = 0.25000 -0.50000 0.25000 0.50000 octave:29> octave:29> 'made up example in space of 2 by 2 matrices' ans = made up example in space of 2 by 2 matrices octave:30> a = [ 1 0 0 0; 1 1 0 0; 1 1 1 0 ; 1 1 1 1]' a = 1 1 1 1 0 1 1 1 0 0 1 1 0 0 0 1 octave:31> 'that was new in terms of old; use inverse to get old in terms of new' ans = that was new in terms of old; use inverse to get old in terms of new octave:32> inv(a) ans = 1 -1 0 0 0 1 -1 0 0 0 1 -1 0 0 0 1 octave:33> 'exer 1a of sec 3.6, row space only' ans = exer 1a of sec 3.6, row space only octave:34> a = [1 3 2; 2 1 4; 4 7 8] a = 1 3 2 2 1 4 4 7 8 octave:35> rref(a) ans = 1 0 2 0 1 0 0 0 0 octave:36> 'end fri 13 oct' ans = end fri 13 oct octave:37> quit octave:3> octave:3> 'start mon 16 oct 06' ans = start mon 16 oct 06 octave:4> 'exer 1a of sec 3.6 for column space, long way' ans = exer 1a of sec 3.6 for column space, long way octave:5> a = [1 3 2; 2 1 4; 4 7 8] a = 1 3 2 2 1 4 4 7 8 octave:6> x = a' x = 1 2 4 3 1 7 2 4 8 octave:7> b = rref(x) b = 1.00000 0.00000 2.00000 0.00000 1.00000 1.00000 0.00000 0.00000 0.00000 octave:8> c = b' c = 1.00000 0.00000 0.00000 0.00000 1.00000 0.00000 2.00000 1.00000 0.00000 octave:9> 'but just doing rref to a would change column space' ans = but just doing rref to a would change column space octave:10> rref(a) ans = 1 0 2 0 1 0 0 0 0 octave:11> octave:11> 'exer 1b, has lots of columns' ans = exer 1b, has lots of columns octave:12> a = [-3 1 3 4; 1 2 -1 -2; -3 8 4 2] a = -3 1 3 4 1 2 -1 -2 -3 8 4 2 octave:13> rref(a) ans = 1.00000 0.00000 0.00000 -1.42857 0.00000 1.00000 0.00000 -0.28571 0.00000 0.00000 1.00000 0.00000 octave:14> 'end mon 16 oct' ans = end mon 16 oct octave:15> quit octave:2> 'start fri 20 oct 06' ans = start fri 20 oct 06 octave:3> 'no computer examples done today' ans = no computer examples done today octave:4> 'end fri 20 oct 06' ans = end fri 20 oct 06 octave:5> quit octave:2> 'start mon 23 oct 2006' ans = start mon 23 oct 2006 octave:3> 'exer 7a sec 4.2' ans = exer 7a sec 4.2 octave:4> a =[ 1 1 1 ; 1 1 0 ; 1 0 01]' a = 1 1 1 1 1 0 1 0 1 octave:5> a(3,3) = 0 a = 1 1 1 1 1 0 1 0 0 octave:6> b = [1 0 0]' b = 1 0 0 octave:7> aug = [a,b] aug = 1 1 1 1 1 1 0 0 1 0 0 0 octave:8> rref(aug) ans = 1 0 0 0 0 1 0 0 0 0 1 1 octave:9> 'end mon 23 oct' ans = end mon 23 oct octave:10> quit octave:2> 'start wed 25 oct 06' ans = start wed 25 oct 06 octave:3> 'exer 1a of sec 4.3' ans = exer 1a of sec 4.3 octave:4> a = [-1 0 ; 1 0 ] a = -1 0 1 0 octave:5> s = [1 -1 ; 1 1] s = 1 -1 1 1 octave:6> inv(s) * a * s ans = 0 0 1 -1 octave:7> a = [-1 0 ; 0 1] a = -1 0 0 1 octave:8> inv(s) * a * s ans = 0 1 1 0 octave:9> 'this agrees with the b that we computed by hand' ans = this agrees with the b that we computed by hand octave:10> 'exer 4' ans = exer 4 octave:11> a = [3 -1 -2; 2 0 -2; 2 -1 -1] a = 3 -1 -2 2 0 -2 2 -1 -1 octave:12> v1 = [1 1 1]' v1 = 1 1 1 octave:13> a * v1 ans = 0 0 0 octave:14> v2 = [1 2 0]' v2 = 1 2 0 octave:15> v3 = [0 -2 1]' v3 = 0 -2 1 octave:16> s = [v1, v2, v3] s = 1 1 0 1 2 -2 1 0 1 octave:17> sinv = inv(s) sinv = -2 1 2 3 -1 -2 2 -1 -1 octave:18> b = sinv * a * s b = 0 0 0 0 1 0 0 0 1 octave:19> 'end wewd 25 oct' ans = end wewd 25 oct octave:20> quit octave:3> 'start fri 27 oct 06' ans = start fri 27 oct 06 octave:4> v = [1 2 3] v = 1 2 3 octave:5> w = [ 6 5 4] w = 6 5 4 octave:6> v' * w ans = 6 5 4 12 10 8 18 15 12 octave:7> v = v' v = 1 2 3 octave:8> w = w' w = 6 5 4 octave:9> v' * w ans = 28 octave:10> v' * v ans = 14 octave:11> sqrt(v' * v) ans = 3.7417 octave:12> norm(v) ans = 3.7417 octave:13> 'exer 1, find angle' ans = exer 1, find angle octave:14> 'part a' ans = part a octave:15> v = [2 1 3]' v = 2 1 3 octave:16> w = [6 3 9]' w = 6 3 9 octave:17> costheta = (v' * w) / ( sqrt(x' * x) * sqrt(y' * y) ) error: `x' undefined near line 17 column 30 error: evaluating expression near line 17, column 30 error: evaluating unary operator `'' near line 17, column 30 error: evaluating binary operator `*' near line 17, column 33 error: evaluating argument list element number 1 error: evaluating index expression near line 17, column 25 error: evaluating binary operator `*' near line 17, column 38 error: evaluating binary operator `/' near line 17, column 21 error: evaluating assignment expression near line 17, column 10 octave:17> costheta = (v' * w) / ( sqrt(v' * v) * sqrt(w' * w) ) costheta = 1 octave:18> 'so angle is 0, vectors are multiples of each other' ans = so angle is 0, vectors are multiples of each other octave:19> 'part b' ans = part b octave:20> v = [2 -3]' v = 2 -3 octave:21> w = 3 2]' parse error: >>> w = 3 2]' ^ octave:21> w = [3 2]' w = 3 2 octave:22> v' * w ans = 0 octave:23> 'exer 3 part b' ans = exer 3 part b octave:24> x = [3 5]' x = 3 5 octave:25> y = [1 1]' y = 1 1 octave:26> coeff = (x' * y) / (y' * y) coeff = 4 octave:27> 'need that many copies of y' ans = need that many copies of y octave:28> 4 * y ans = 4 4 octave:29> p = coeff * y p = 4 4 octave:30> xlessp = x - p xlessp = -1 1 octave:31> xlessp' * p ans = 0 octave:32> 'exer 2' ans = exer 2 octave:33> x = [1 -1 1]' x = 1 -1 1 octave:34> 'exer 3b' ans = exer 3b octave:35> x = [1 2 1]' x = 1 2 1 octave:36> y = [1 -1 2]' y = 1 -1 2 octave:37> a = [x,y] a = 1 1 2 -1 1 2 octave:38> b = a' b = 1 2 1 1 -1 2 octave:39> rref(b) ans = 1.00000 0.00000 1.66667 0.00000 1.00000 -0.33333 octave:40> 'end fri 27 oct' ans = end fri 27 oct octave:41> quit octave:2> 'start mon 30 oct 06' ans = start mon 30 oct 06 octave:3> b 'sec 5.3, exer 1a' parse error: >>> b 'sec 5.3, exer 1a' ^ octave:3> a = [1 1; 2 -3; 0 0 ] a = 1 1 2 -3 0 0 octave:4> b = [3 1 2]' b = 3 1 2 octave:5> aug = [a,b] aug = 1 1 3 2 -3 1 0 0 2 octave:6> 'let's get normal equations, multiplying by transpose' parse error: >>> 'let's get normal equations, multiplying by transpose' ^ octave:6> normaug = a' * aug normaug = 5 -5 5 -5 10 0 octave:7> 'solve to get xhat' ans = solve to get xhat octave:8> rref(normaug) ans = 1 0 2 0 1 1 octave:9> 'the solution is xhat' ans = the solution is xhat octave:10> xhat = [2 1]' xhat = 2 1 octave:11> 'projection is A times xhat' ans = projection is A times xhat octave:12> p = a * xhat p = 3 1 0 octave:13> eeror = b - p eeror = 0 0 2 octave:14> 'check orthogonality' ans = check orthogonality octave:15> error' * p error: unspecified error error: evaluating expression near line 15, column 1 error: evaluating unary operator `'' near line 15, column 1 error: evaluating binary operator `*' near line 15, column 8 error: evaluating assignment expression near line 15, column 8 octave:15> error = eeror error = 0 0 2 octave:16> error' * p ans = 0 octave:17> sizeerror = norm(error) sizeerror = 2 octave:18> 'exer 1b' ans = exer 1b octave:19> a = [-1 1; 2 1; 1 -2] a = -1 1 2 1 1 -2 octave:20> b = [10 5 20]' b = 10 5 20 octave:21> aug = [a,b] aug = -1 1 10 2 1 5 1 -2 20 octave:22> rref(aug) ans = 1 0 0 0 1 0 0 0 1 octave:23> normaug = a' * aug normaug = 6 -1 20 -1 6 -25 octave:24> rref(aug) ans = 1 0 0 0 1 0 0 0 1 octave:25> aug aug = -1 1 10 2 1 5 1 -2 20 octave:26> a a = -1 1 2 1 1 -2 octave:27> rref(normaug) ans = 1.00000 0.00000 2.71429 0.00000 1.00000 -3.71429 octave:28> 'this involves square roots, octave didnt tell us which' ans = this involves square roots, octave didnt tell us which octave:29> xhat = [2.71429 -3.71429]' xhat = 2.7143 -3.7143 octave:30> p = a * xhat p = -6.4286 1.7143 10.1429 octave:31> error = b - p error = 16.4286 3.2857 9.8571 octave:32> error' * p ans = -1.9286e-04 octave:33> 'exer 3a' ans = exer 3a octave:34> a = [1 2; 2 4 ; -1 -2] a = 1 2 2 4 -1 -2 octave:35> b = [3 2 1]' b = 3 2 1 octave:36> aug = [a,b] aug = 1 2 3 2 4 2 -1 -2 1 octave:37> rref(aug) ans = 1 2 0 0 0 1 0 0 0 octave:38> octave:38> normaug = a' * aug normaug = 6 12 6 12 24 12 octave:39> rref(aug) ans = 1 2 0 0 0 1 0 0 0 octave:40> rref(normaug) ans = 1 2 1 0 0 0 octave:41> 'solns are [1 0]' plus any mult of [-2 1]' ' parse error: >>> 'solns are [1 0]' plus any mult of [-2 1]' ' ^ octave:41> p = a * [1 0]' p = 1 2 -1 octave:42> 'another solution for xhat is [-1 1]', but should be same p' parse error: >>> 'another solution for xhat is [-1 1]', but should be same p' ^ octave:42> q = a * [-1 1]' q = 1 2 -1 octave:43> 'end mon 30 oct' ans = end mon 30 oct octave:44> quit octave:2> 'start wed 1 nov 06' ans = start wed 1 nov 06 octave:3> 'sec 5.3, exer 5' ans = sec 5.3, exer 5 octave:4> a = [-1 0 1 2; 1 1 1 1]' a = -1 1 0 1 1 1 2 1 octave:5> b = [0 1 3 9]' b = 0 1 3 9 octave:6> aug = [a,b] aug = -1 1 0 0 1 1 1 1 3 2 1 9 octave:7> rref(aug) ans = 1 0 0 0 1 0 0 0 1 0 0 0 octave:8> normaug = a' * aug normaug = 6 2 21 2 4 13 octave:9> rref(normaug) ans = 1.00000 0.00000 2.90000 0.00000 1.00000 1.80000 octave:10> 'so best slope m is 2.9, best intercept b is 1.8' ans = so best slope m is 2.9, best intercept b is 1.8 octave:11> x = a(:,1) x = -1 0 1 2 octave:12> xsq = x^2 error: for A^b, A must be square error: evaluating assignment expression near line 12, column 5 octave:12> xsq = [ 1 0 1 4]' xsq = 1 0 1 4 octave:13> ones = [1 1 1 1]' ones = 1 1 1 1 octave:14> a [ ones, x, xsq] parse error: use `(' and `)' as index operators, not `[' and `]' >>> a [ ones, x, xsq] ^ octave:14> a = [ones, x, xsq] a = 1 -1 1 1 0 0 1 1 1 1 2 4 octave:15> aug = [a,b] aug = 1 -1 1 0 1 0 0 1 1 1 1 3 1 2 4 9 octave:16> rref(aug) ans = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 octave:17> 'so cant gete exact quadratic, let's do least squares to get best fit' parse error: >>> 'so cant gete exact quadratic, let's do least squares to get best fit' ^ octave:17> normaug = a' * aug normaug = 4 2 6 13 2 6 8 21 6 8 18 39 octave:18> rref(normaug) ans = 1.00000 0.00000 0.00000 0.55000 0.00000 1.00000 0.00000 1.65000 0.00000 0.00000 1.00000 1.25000 octave:19> 'if there were an exercise saying fit to a cubic' ans = if there were an exercise saying fit to a cubic octave:20> x x = -1 0 1 2 octave:21> xcube = [-1 0 1 8] xcube = -1 0 1 8 octave:22> xcube = xcube' xcube = -1 0 1 8 octave:23> a = [ones, x, xsq, xcube] a = 1 -1 1 -1 1 0 0 0 1 1 1 1 1 2 4 8 octave:24> aug = [a,b] aug = 1 -1 1 -1 0 1 0 0 0 1 1 1 1 1 3 1 2 4 8 9 octave:25> rref(aug) ans = 1.00000 0.00000 0.00000 0.00000 1.00000 0.00000 1.00000 0.00000 0.00000 1.00000 0.00000 0.00000 1.00000 0.00000 0.50000 0.00000 0.00000 0.00000 1.00000 0.50000 octave:26> octave:26> 'end wed 1 nov' ans = end wed 1 nov octave:27> quit octave:2> 'start fri 3 nov 06' ans = start fri 3 nov 06 octave:3> 'no computer examples done today error: unterminated string constant parse error: >>> 'no computer examples done today ^ octave:3> ' error: unterminated string constant parse error: >>> ' ^ octave:3> 'no computer examples done today' ans = no computer examples done today octave:4> 'end fri 3 nov' ans = end fri 3 nov octave:5> quit octave:2> 'start mon 6 nov 06' ans = start mon 6 nov 06 octave:3> 'no computer examples done today' ans = no computer examples done today octave:4> 'end mon 6 nov' ans = end mon 6 nov octave:5> quit octave:2> 'start wed 8 nov 06' ans = start wed 8 nov 06 octave:3> 're Thm 5.5.6, look at exer 21,22' ans = re Thm 5.5.6, look at exer 21,22 octave:4> a = [1/2 1/2 1/2 1/2; -1/2 -1/2 1/2 1/2]' a = 0.50000 -0.50000 0.50000 -0.50000 0.50000 0.50000 0.50000 0.50000 octave:5> 'for part (b) , use the following vectors... (i) is :' ans = for part (b) , use the following vectors... (i) is : octave:6> b = [4 0 0 0]' b = 4 0 0 0 octave:7> 'set up as usual least squares' ans = set up as usual least squares octave:8> aug = [ a, b] aug = 0.50000 -0.50000 4.00000 0.50000 -0.50000 0.00000 0.50000 0.50000 0.00000 0.50000 0.50000 0.00000 octave:9> rref(aug) ans = 1 0 0 0 1 0 0 0 1 0 0 0 octave:10> 'so cannot solve exactly by ch1' ans = so cannot solve exactly by ch1 octave:11> 'so form normal equations' ans = so form normal equations octave:12> normaug = a' * aug normaug = 1 0 2 0 1 -2 octave:13> 'this system is already solve, we can see what xhat is!' ans = this system is already solve, we can see what xhat is! octave:14> xhat = [2 -2]' xhat = 2 -2 octave:15> 'exer 22, find a*xhat as proj p ...also use "projection matrix" !' ans = exer 22, find a*xhat as proj p ...also use "projection matrix" ! octave:16> p = a * xhat p = 2 2 0 0 octave:17> a * a' ans = 0.50000 0.50000 0.00000 0.00000 0.50000 0.50000 0.00000 0.00000 0.00000 0.00000 0.50000 0.50000 0.00000 0.00000 0.50000 0.50000 octave:18> a * a' * b ans = 2 2 0 0 octave:19> P = a * a' P = 0.50000 0.50000 0.00000 0.00000 0.50000 0.50000 0.00000 0.00000 0.00000 0.00000 0.50000 0.50000 0.00000 0.00000 0.50000 0.50000 octave:20> 'end wed 8 nov' ans = end wed 8 nov octave:21> quit octave:2> 'start fri 10 nov' ans = start fri 10 nov octave:3> 'exer 1a of see 5.6' ans = exer 1a of see 5.6 octave:4> x1 = [-1 1]' x1 = -1 1 octave:5> x2 = [3 5]' x2 = 3 5 octave:6> q1 = x1 q1 = -1 1 octave:7> q2 = x2 - ( (x2'*q1) / (q1' * q1) ) * q1 q2 = 4 4 octave:8> u1 = q1 / norm(q1) u1 = -0.70711 0.70711 octave:9> u2 = q2 / norm(q2) u2 = 0.70711 0.70711 octave:10> 'end fri 10 nov' ans = end fri 10 nov octave:11> quit octave:2> 'start mon nov 13 2006' ans = start mon nov 13 2006 octave:3> 'doing exer 7 of sec 5.6' ans = doing exer 7 of sec 5.6 octave:4> a = [1 1 1 -1; 1 1 3 5] a = 1 1 1 -1 1 1 3 5 octave:5> rref(a) ans = 1 1 0 -4 0 0 1 3 octave:6> 'exer 2, matrix 1a' ans = exer 2, matrix 1a octave:7> a = [ -1 1; 3 5]' a = -1 3 1 5 octave:8> 'got q from Gram Schmidt in exer 1' ans = got q from Gram Schmidt in exer 1 octave:9> u1 = 1/sqrt(2) * [-1 1]' u1 = -0.70711 0.70711 octave:10> u2 = 1/sqrt(2) * [1 1]' u2 = 0.70711 0.70711 octave:11> q = [u1,u2] q = -0.70711 0.70711 0.70711 0.70711 octave:12> r = q' * a r = 1.41421 1.41421 0.00000 5.65685 octave:13> a a = -1 3 1 5 octave:14> q * r ans = -1.00000 3.00000 1.00000 5.00000 octave:15> a - q* r ans = -2.2204e-16 4.4409e-16 2.2204e-16 8.8818e-16 octave:16> 'exer 5 of sec 5.6' ans = exer 5 of sec 5.6 octave:17> a = [ 2 1 2; 1 1 1]' a = 2 1 1 1 2 1 octave:18> b = [12 6 18]' b = 12 6 18 octave:19> 'check we need least squares, is it solvable by ch 1 ?' ans = check we need least squares, is it solvable by ch 1 ? octave:20> aug = [a,b] aug = 2 1 12 1 1 6 2 1 18 octave:21> rref(aug) ans = 1 0 0 0 1 0 0 0 1 octave:22> normaug = a' * aug normaug = 9 5 66 5 3 36 octave:23> rref(normaug) ans = 1.00000 0.00000 9.00000 0.00000 1.00000 -3.00000 octave:24> xhat = [9 -3]' xhat = 9 -3 octave:25> 'that was soln by old sec 5.4 method, before qr,...so know answer' ans = that was soln by old sec 5.4 method, before qr,...so know answer octave:26> 'now doing via qr factorization, we applied Gram Schmidt to cols of a' ans = now doing via qr factorization, we applied Gram Schmidt to cols of a octave:27> u1 = 1/3 * [2 1 2]' u1 = 0.66667 0.33333 0.66667 octave:28> u2 = 1/sqrt(18) * [-1 4 -1]' u2 = -0.23570 0.94281 -0.23570 octave:29> q = [u1,u2] q = 0.66667 -0.23570 0.33333 0.94281 0.66667 -0.23570 octave:30> r = q' * a r = 3.00000 1.66667 0.00000 0.47140 octave:31> q * r ans = 2.00000 1.00000 1.00000 1.00000 2.00000 1.00000 octave:32> a a = 2 1 1 1 2 1 octave:33> xhat xhat = 9 -3 octave:34> newxhat = inv(r)*q'*b newxhat = 9 -3 octave:35> 'end mon 13 nov' ans = end mon 13 nov octave:36> quit octave:2> 'wed 15 nov 06' ans = wed 15 nov 06 octave:3> 'sec 6.1, re-do exer 6a by computer' ans = sec 6.1, re-do exer 6a by computer octave:4> a = [3 2 ; 4 1]' a = 3 4 2 1 octave:5> eig(a) ans = 5 -1 octave:6> 'that was eig with ONE input' ans = that was eig with ONE input octave:7> 'could now solve for eigenvectors using rref' ans = could now solve for eigenvectors using rref octave:8> b = a * 5 * eye(2) b = 15 20 10 5 octave:9> b = a - 5 * eye(2) b = -2 4 2 -4 octave:10> rref(b) ans = 1 -2 0 0 octave:11> a a = 3 4 2 1 octave:12> a = [3 2 ; 4 1] a = 3 2 4 1 octave:13> eig(a) ans = 5.00000 -1.00000 octave:14> b = a - 5 * eye(2) b = -2 2 4 -4 octave:15> rref(b) ans = 1 -1 0 0 octave:16> [vec,val] = eig(a) vec = 0.70711 -0.44721 0.70711 0.89443 val = 5.00000 0.00000 0.00000 -1.00000 octave:17> 'exer 1d' ans = exer 1d octave:18> a = [3 -8; 2 3] a = 3 -8 2 3 octave:19> eig(a) ans = 3 + 4i 3 - 4i octave:20> [vec,val] = eig(a) vec = 0.89443 + 0.00000i 0.89443 + 0.00000i 0.00000 - 0.44721i 0.00000 + 0.44721i val = 3 + 4i 0 + 0i 0 + 0i 3 - 4i octave:21> a a = 3 -8 2 3 octave:22> a - (3 * 4i)*eye(2) ans = 3 - 12i -8 + 0i 2 + 0i 3 - 12i octave:23> a - (3 +4i) * eye(2) ans = 0 - 4i -8 + 0i 2 + 0i 0 - 4i octave:24> 'end wed 15 nov 06'[ > ' parse error: >>> ' ^ octave:24> 'end wed 15 nov' ans = end wed 15 nov octave:25> quit octave:2> 'start mon 20 nov 06' ans = start mon 20 nov 06 octave:3> 'exer 1a of sec 6.2' ans = exer 1a of sec 6.2 octave:4> a = [ 1 1; -2 4] a = 1 1 -2 4 octave:5> [vec,val] = eig(a) vec = 0.70711 0.44721 0.70711 0.89443 val = 2.00000 0.00000 0.00000 3.00000 octave:6> 'exer 2a' ans = exer 2a octave:7> a = [-1 2; 2 -1] a = -1 2 2 -1 octave:8> eig(a) ans = -3 1 octave:9> rref( a + 3 * eye(2) ) ans = 1 1 0 0 octave:10> rref( a - 1 * eye(2) ) ans = 1 -1 0 0 octave:11> 'we compute matrix of eigenvectors' ans = we compute matrix of eigenvectors octave:12> vectors = [ -1 1; 1 1] vectors = -1 1 1 1 octave:13> initialvalues = [3 1 > ]' initialvalues = 3 1 octave:14> aug = [vectors, initialvalues] aug = -1 1 3 1 1 1 octave:15> rref(aug) ans = 1 0 -1 0 1 2 octave:16> 'so this gives the constants for the particular solution with initial values' ans = so this gives the constants for the particular solution with initial values octave:17> 'end mon 20 nov 06' ans = end mon 20 nov 06 octave:18> qyut error: `qyut' undefined near line 18 column 1 error: evaluating expression near line 18, column 1 octave:18> kigiyt error: `kigiyt' undefined near line 18 column 1 error: evaluating expression near line 18, column 1 octave:18> lgout error: `lgout' undefined near line 18 column 1 error: evaluating expression near line 18, column 1 octave:18> lkog error: `lkog' undefined near line 18 column 1 error: evaluating expression near line 18, column 1 octave:18> ;l parse error: >>> ;l ^ octave:18> octave:18> octave:18> logout error: `logout' undefined near line 18 column 1 error: evaluating expression near line 18, column 1 octave:18> qui5 error: `qui5' undefined near line 18 column 1 error: evaluating expression near line 18, column 1 octave:18> quit octave:2> 'start wed 22 nov 06' ans = start wed 22 nov 06 octave:3> 'exer 4 of sec 6.2' ans = exer 4 of sec 6.2 octave:4> a = [-.16 .04; .16 -.16] a = -0.160000 0.040000 0.160000 -0.160000 octave:5> [vec,val] = eig(a) vec = 0.44721 -0.44721 0.89443 0.89443 val = -0.08000 0.00000 0.00000 -0.24000 octave:6> v = [1 -1; 2 2] v = 1 -1 2 2 octave:7> iv = [40 20]' iv = 40 20 octave:8> aug = [v,iv] aug = 1 -1 40 2 2 20 octave:9> rref(aug) ans = 1 0 25 0 1 -15 octave:10> 'exer 5b' ans = exer 5b octave:11> a = [0 0 1 0; 0 0 0 1; 2 0 0 1; 0 2 1 0] a = 0 0 1 0 0 0 0 1 2 0 0 1 0 2 1 0 octave:12> [vec,val] = eig(a) vec = -0.31623 0.31623 0.50000 -0.50000 -0.31623 -0.31623 -0.50000 -0.50000 -0.63246 -0.63246 0.50000 0.50000 -0.63246 0.63246 -0.50000 0.50000 val = 2.00000 0.00000 0.00000 0.00000 0.00000 -2.00000 0.00000 0.00000 0.00000 0.00000 1.00000 0.00000 0.00000 0.00000 0.00000 -1.00000 octave:13> 'exer 6' ans = exer 6 octave:14> a = [0 0 1 0; 0 0 0 1; 0 -2 1 1; 2 0 2 -1] a = 0 0 1 0 0 0 0 1 0 -2 1 1 2 0 2 -1 octave:15> [vec,val] = eig(a) vec = 0.32959 + 0.00000i -0.58835 + 0.00000i -0.33204 + 0.00000i -0.33204 - 0.00000i -0.39734 + 0.00000i 0.39223 + 0.00000i -0.36617 + 0.22096i -0.36617 - 0.22096i -0.54678 + 0.00000i 0.58835 + 0.00000i -0.44145 - 0.26638i -0.44145 + 0.26638i 0.65918 + 0.00000i -0.39223 + 0.00000i -0.66409 + 0.00000i -0.66409 + 0.00000i val = -1.65897 + 0.00000i 0.00000 + 0.00000i 0.00000 + 0.00000i 0.00000 + 0.00000i 0.00000 + 0.00000i -1.00000 + 0.00000i 0.00000 + 0.00000i 0.00000 + 0.00000i 0.00000 + 0.00000i 0.00000 + 0.00000i 1.32948 + 0.80225i 0.00000 + 0.00000i 0.00000 + 0.00000i 0.00000 + 0.00000i 0.00000 + 0.00000i 1.32948 - 0.80225i octave:16> a a = 0 0 1 0 0 0 0 1 0 -2 1 1 2 0 2 -1 octave:17> a(3,4) = 2 a = 0 0 1 0 0 0 0 1 0 -2 1 2 2 0 2 -1 octave:18> [vec,val] = eig(a) vec = 0.63246 -0.31623 -0.31623 -0.31623 -0.31623 0.31623 -0.31623 -0.63246 -0.63246 0.63246 -0.63246 -0.31623 0.31623 -0.63246 -0.63246 -0.63246 val = -1.00000 0.00000 0.00000 0.00000 0.00000 -2.00000 0.00000 0.00000 0.00000 0.00000 2.00000 0.00000 0.00000 0.00000 0.00000 1.00000 octave:19> b = [1 0 -3 2]' b = 1 0 -3 2 octave:20> aug = [vec,b] aug = 0.63246 -0.31623 -0.31623 -0.31623 1.00000 -0.31623 0.31623 -0.31623 -0.63246 0.00000 -0.63246 0.63246 -0.63246 -0.31623 -3.00000 0.31623 -0.63246 -0.63246 -0.63246 2.00000 octave:21> rref(aug) ans = 1.00000 0.00000 0.00000 0.00000 -0.00000 0.00000 1.00000 0.00000 0.00000 -3.16228 0.00000 0.00000 1.00000 0.00000 3.16228 0.00000 0.00000 0.00000 1.00000 -3.16228 octave:22> 'nicer look, if we use integer eigenvectors error: unterminated string constant parse error: >>> 'nicer look, if we use integer eigenvectors ^ octave:22> vec vec = 0.63246 -0.31623 -0.31623 -0.31623 -0.31623 0.31623 -0.31623 -0.63246 -0.63246 0.63246 -0.63246 -0.31623 0.31623 -0.63246 -0.63246 -0.63246 octave:23> v1 = [2 -1 -2 1]' v1 = 2 -1 -2 1 octave:24> v2 = [-1 1 2 -2]' v2 = -1 1 2 -2 octave:25> v3 = [1 1 2 2]' v3 = 1 1 2 2 octave:26> vec vec = 0.63246 -0.31623 -0.31623 -0.31623 -0.31623 0.31623 -0.31623 -0.63246 -0.63246 0.63246 -0.63246 -0.31623 0.31623 -0.63246 -0.63246 -0.63246 octave:27> v4 = [1 2 1 2]' v4 = 1 2 1 2 octave:28> integervec = [v1,v2,v3,v4] integervec = 2 -1 1 1 -1 1 1 2 -2 2 2 1 1 -2 2 2 octave:29> newaug = [integervec,b] newaug = 2 -1 1 1 1 -1 1 1 2 0 -2 2 2 1 -3 1 -2 2 2 2 octave:30> rref(newaug) ans = 1 0 0 0 0 0 1 0 0 -1 0 0 1 0 -1 0 0 0 1 1 octave:31> 'yes, these are nicer constants, using the integer eigenvectors...' ans = yes, these are nicer constants, using the integer eigenvectors... octave:32> 'end wed 22 nov' ans = end wed 22 nov octave:33> quit octave:2> 'start mon 27 nov 06' ans = start mon 27 nov 06 octave:3> 'sec 6.3, exer 1a' ans = sec 6.3, exer 1a octave:4> a = [0 1 ; 1 0 ] a = 0 1 1 0 octave:5> eig(a) ans = -1 1 octave:6> [vec,val ] = eig(a) vec = -0.70711 0.70711 0.70711 0.70711 val = -1 0 0 1 octave:7> 'here vec is the matrix x of eigenvectors, in diagonalizing; val is the diagonal matrix d' ans = here vec is the matrix x of eigenvectors, in diagonalizing; val is the diagonal matrix d octave:8> x = vec x = -0.70711 0.70711 0.70711 0.70711 octave:9> d = val d = -1 0 0 1 octave:10> inv(x) * a * x ans = -1.0000e+00 1.0137e-17 -1.0137e-17 1.0000e+00 octave:11> a a = 0 1 1 0 octave:12> x * d * inv(x) ans = -1.0137e-17 1.0000e+00 1.0000e+00 -1.0137e-17 octave:13> 'prettier if we use integer eigenvectors' ans = prettier if we use integer eigenvectors octave:14> vec vec = -0.70711 0.70711 0.70711 0.70711 octave:15> v1 = [-1 1]' v1 = -1 1 octave:16> v2 = [1 1 ]' v2 = 1 1 octave:17> 'lets use new x given by these integer eigenvectors' ans = lets use new x given by these integer eigenvectors octave:18> x = [v1,v2] x = -1 1 1 1 octave:19> inv(x) * a * x ans = -1 0 0 1 octave:20> d d = -1 0 0 1 octave:21> x * d * inv(x) ans = 0 1 1 0 octave:22> a a = 0 1 1 0 octave:23> 'now exer 1f' ans = now exer 1f octave:24> a = [1 2 -1; 2 4 -2; 3 6 -3] a = 1 2 -1 2 4 -2 3 6 -3 octave:25> eig(a) ans = 2.0000e+00 2.3292e-17 -1.9397e-15 octave:26> [vec,val] = eig(a) vec = 0.26726 0.84146 0.23783 0.53452 -0.16319 0.33664 0.80178 0.51508 0.91110 val = 2.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 -0.00000 octave:27> x = vec x = 0.26726 0.84146 0.23783 0.53452 -0.16319 0.33664 0.80178 0.51508 0.91110 octave:28> x3 = x(:,3} error: invalid character `}' near line 28, column 12 parse error: >>> x3 = x(:,3} ^ octave:28> x x = 0.26726 0.84146 0.23783 0.53452 -0.16319 0.33664 0.80178 0.51508 0.91110 octave:29> x(:,3) ans = 0.23783 0.33664 0.91110 octave:30> x = x(:,3) x = 0.23783 0.33664 0.91110 octave:31> y = x / .23783 y = 1.0000 1.4155 3.8309 octave:32> a a = 1 2 -1 2 4 -2 3 6 -3 octave:33> rref(a - 2 * eye(3)) ans = 1.00000 0.00000 -0.33333 0.00000 1.00000 -0.66667 0.00000 0.00000 0.00000 octave:34> rref(a - 0 * eye(3) ) ans = 1 2 -1 0 0 0 0 0 0 octave:35> xq = [1 2 3 ]' xq = 1 2 3 octave:36> x2 = [-2 1 0]' x2 = -2 1 0 octave:37> x3 = [1 0 1]' x3 = 1 0 1 octave:38> x = [x1,x2,x3] error: `x1' undefined near line 38 column 6 error: evaluating expression near line 38, column 6 error: evaluating assignment expression near line 38, column 3 octave:38> x1 = xq x1 = 1 2 3 octave:39> x = [x1,x2,x3] x = 1 -2 1 2 1 0 3 0 1 octave:40> inv(x) * a * x ans = 2.00000 0.00000 0.00000 0.00000 0.00000 0.00000 -0.00000 0.00000 0.00000 octave:41> d = [2 0 0 ; 0 0 0 ; 0 0 0] d = 2 0 0 0 0 0 0 0 0 octave:42> x * d * inv(x) ans = 1.0000 2.0000 -1.0000 2.0000 4.0000 -2.0000 3.0000 6.0000 -3.0000 octave:43> a a = 1 2 -1 2 4 -2 3 6 -3 octave:44> 'exer 2, applied to exer 1f' ans = exer 2, applied to exer 1f octave:45> a a = 1 2 -1 2 4 -2 3 6 -3 octave:46> x x = 1 -2 1 2 1 0 3 0 1 octave:47> d d = 2 0 0 0 0 0 0 0 0 octave:48> d^6 ans = 64 0 0 0 0 0 0 0 0 octave:49> x * (d^6) * inv(x) ans = 32.000 64.000 -32.000 64.000 128.000 -64.000 96.000 192.000 -96.000 octave:50> 'do directly' ans = do directly octave:51> a^6 ans = 32 64 -32 64 128 -64 96 192 -96 octave:52> 'end mon 27 nov' ans = end mon 27 nov octave:53> quit octave:2> 'start wed 29 nov 06' ans = start wed 29 nov 06 octave:3> 'exer 8a' ans = exer 8a octave:4> 'case lambda = 0' ans = case lambda = 0 octave:5> a = [1 1 0 ; 1 1 0 ; 0 0 0] a = 1 1 0 1 1 0 0 0 0 octave:6> eig(a) ans = 0 0 2 octave:7> [vec,val] = eig(a) vec = -0.70711 0.00000 0.70711 0.70711 0.00000 0.70711 0.00000 1.00000 0.00000 val = 0 0 0 0 0 0 0 0 2 octave:8> b = a - 0 * eye(3) b = 1 1 0 1 1 0 0 0 0 octave:9> rref(b) ans = 1 1 0 0 0 0 0 0 0 octave:10> b = a - 2*eye(3) b = -1 1 0 1 -1 0 0 0 -2 octave:11> rref(b) ans = 1 -1 0 0 0 1 0 0 0 octave:12> 'we now want to do case lambda = 2' ans = we now want to do case lambda = 2 octave:13> a a = 1 1 0 1 1 0 0 0 0 octave:14> a(3,3) =2 a = 1 1 0 1 1 0 0 0 2 octave:15> eig(a) ans = 0 2 2 octave:16> rref(a - 2*eye(3)) ans = 1 -1 0 0 0 0 0 0 0 octave:17> 'exer 8b' ans = exer 8b octave:18> a a = 1 1 0 1 1 0 0 0 2 octave:19> a(1,3) = 1 a = 1 1 1 1 1 0 0 0 2 octave:20> a(2,3) = 1 a = 1 1 1 1 1 1 0 0 2 octave:21> a (3,3) = 0 a = 1 1 1 1 1 1 0 0 0 octave:22> 'this is alpha = 0b case of 8b' ans = this is alpha = 0b case of 8b octave:23> eig(a) ans = 2 0 0 octave:24> rref(a) ans = 1 1 1 0 0 0 0 0 0 octave:25> 'now alpha = 2 case of 8b' ans = now alpha = 2 case of 8b octave:26> a a = 1 1 1 1 1 1 0 0 0 octave:27> a(3,3)=2 a = 1 1 1 1 1 1 0 0 2 octave:28> eig(a) ans = 2 0 2 octave:29> rref(a - 2*eye(3)) ans = 1 -1 0 0 0 1 0 0 0 octave:30> 'exer 20' ans = exer 20 octave:31> a = [.8 .2 ; .3 .7]' a = 0.80000 0.30000 0.20000 0.70000 octave:32> eig(a) ans = 1.00000 0.50000 octave:33> 'find AN eigenvector for 1' ans = find AN eigenvector for 1 octave:34> rref(a - 1 *eye(2) ) ans = 1.00000 -1.50000 0.00000 0.00000 octave:35> 'exer 26a' ans = exer 26a octave:36> a = [1 1; -1 -1] a = 1 1 -1 -1 octave:37> eig(a) ans = 1.4135e-20 + 6.8384e-17i 1.4135e-20 - 6.8384e-17i octave:38> a a = 1 1 -1 -1 octave:39> a* a ans = 0 0 0 0 octave:40> 'exer 27a' ans = exer 27a octave:41> a [ -2 -1; 6 3] parse error: use `(' and `)' as index operators, not `[' and `]' >>> a [ -2 -1; 6 3] ^ octave:41> a a = 1 1 -1 -1 octave:42> a = [-2 -1 ; 6 3] a = -2 -1 6 3 octave:43> eig(a) ans = 1.0000e+00 -4.5157e-17 octave:44> [vec,val] = eig(a) vec = -0.31623 -0.44721 0.94868 0.89443 val = 1.00000 0.00000 0.00000 -0.00000 octave:45> 'end wed 29 nov' ans = end wed 29 nov octave:46> quit octave:2> 'start fri dec 1 06' ans = start fri dec 1 06 octave:3> 'notice octave/matlab autmotically do conjugate when you transpose complex vectors!' ans = notice octave/matlab autmotically do conjugate when you transpose complex vectors! octave:4> b = [1+2i 3-4i] b = 1 + 2i 3 - 4i octave:5> b' ans = 1 - 2i 3 + 4i octave:6> 'sec 6.4' ans = sec 6.4 octave:7> 'exer 1'' error: unterminated string constant parse error: >>> 'exer 1'' ^ octave:7> z = [4 + 2i ; 4i] z = 4 + 2i 0 + 4i octave:8> w = [-2 ; 2+i] w = -2 + 0i 2 + 1i octave:9> z' ans = 4 - 2i 0 - 4i octave:10> z' * z ans = 36 octave:11> sqrt(z' * z) ans = 6 octave:12> w w = -2 + 0i 2 + 1i octave:13> z' * w ans = -4 - 4i octave:14> 'exer 2' ans = exer 2 octave:15> z1 = [(1+i)/2 ; (1-i)/2] z1 = 0.50000 + 0.50000i 0.50000 - 0.50000i octave:16> z2 = [i/sqrt(2); -1/sqrt(2)] z2 = 0.00000 + 0.70711i -0.70711 + 0.00000i octave:17> norm(z1) ans = 1 octave:18> z1' * z2 ans = 0 octave:19> 'exer 4: which of these matrices are Hermitian? normal?' ans = exer 4: which of these matrices are Hermitian? normal? octave:20> 'exer 4a' ans = exer 4a octave:21> a = [1-i 2 ; 2 3] a = 1 - 1i 2 + 0i 2 + 0i 3 + 0i octave:22> a' ans = 1 + 1i 2 + 0i 2 + 0i 3 + 0i octave:23> 'is difference a - aprime equal to 0?' ans = is difference a - aprime equal to 0? octave:24> a - a' ans = 0 - 2i 0 + 0i 0 + 0i 0 + 0i octave:25> 'so a is not hermitian' ans = so a is not hermitian octave:26> inv(a) ans = -0.30000 + 0.90000i 0.20000 - 0.60000i 0.20000 - 0.60000i 0.20000 + 0.40000i octave:27> a a = 1 - 1i 2 + 0i 2 + 0i 3 + 0i octave:28> a' ans = 1 + 1i 2 + 0i 2 + 0i 3 + 0i octave:29> 'unitary if inv of a is equal to a^H; subtract to see' ans = unitary if inv of a is equal to a^H; subtract to see octave:30> inv(a) - a' ans = -1.3000 - 0.1000i -1.8000 - 0.6000i -1.8000 - 0.6000i -2.8000 + 0.4000i octave:31> 'not unitary' ans = not unitary octave:32> 'is it normal, does a commute with a^H ?' ans = is it normal, does a commute with a^H ? octave:33> a a = 1 - 1i 2 + 0i 2 + 0i 3 + 0i octave:34> a' ans = 1 + 1i 2 + 0i 2 + 0i 3 + 0i octave:35> a * a' ans = 6 + 0i 8 - 2i 8 + 2i 13 + 0i octave:36> a' * a ans = 6 + 0i 8 + 2i 8 - 2i 13 + 0i octave:37> (a * a') - (a' * a) ans = 0 + 0i 0 - 4i 0 + 4i 0 + 0i octave:38> 'exer 4b' ans = exer 4b octave:39> a = [1 2-i ; 2+i -1] a = 1 + 0i 2 - 1i 2 + 1i -1 + 0i octave:40> a a = 1 + 0i 2 - 1i 2 + 1i -1 + 0i octave:41> a' ans = 1 + 0i 2 - 1i 2 + 1i -1 + 0i octave:42> a - a' ans = 0 0 0 0 octave:43> 'so a is Hermitian' ans = so a is Hermitian octave:44> inv(a) ans = 0.16667 + 0.00000i 0.33333 - 0.16667i 0.33333 + 0.16667i -0.16667 + 0.00000i octave:45> a' ans = 1 + 0i 2 - 1i 2 + 1i -1 + 0i octave:46> 'so not unitary' ans = so not unitary octave:47> 'normal?' ans = normal? octave:48> (a* a') - (a' * a) ans = 0 0 0 0 octave:49> 'so it is also normal' ans = so it is also normal octave:50> 'end fri 1 dec' ans = end fri 1 dec octave:51> quit octave:2> 'start mon 4 dec 06' ans = start mon 4 dec 06 octave:3> octave:3> 'exer 5: find orthogonal or unitary diagonalizing matrix' ans = exer 5: find orthogonal or unitary diagonalizing matrix octave:4> 'exer 5a' ans = exer 5a octave:5> a = [2 1; 1 2] a = 2 1 1 2 octave:6> a - a' ans = 0 0 0 0 octave:7> 'so a is symnmetric' ans = so a is symnmetric octave:8> 'so it will have an othogonal idagonalizeation' ans = so it will have an othogonal idagonalizeation octave:9> eig(a) ans = 1 3 octave:10> 'get eigenvectors partly by hand' ans = get eigenvectors partly by hand octave:11> rref(a - 1 * eye(2)) ans = 1 1 0 0 octave:12> rref( a - 3*eye(2) ) ans = 1 -1 0 0 octave:13> 'for ordinary diagonalization, as in sec 6.3, just use this matrix of eigenectors' ans = for ordinary diagonalization, as in sec 6.3, just use this matrix of eigenectors octave:14> x = [-1 1; 1 1 ]' x = -1 1 1 1 octave:15> inv(x) * a * x ans = 1 0 0 3 octave:16> 'for orthogonal diagonalization, need o.n. basis; here just divide by length' ans = for orthogonal diagonalization, need o.n. basis; here just divide by length octave:17> v1 = [-1/sqrt(2) 1/sqrt(2)]' v1 = -0.70711 0.70711 octave:18> v2 = [1/sqrt(2) 1/sqrt(2)]' v2 = 0.70711 0.70711 octave:19> u = [v1,v2] u = -0.70711 0.70711 0.70711 0.70711 octave:20> inv(u) * a * u ans = 1.0000e+00 -1.0137e-17 4.8030e-17 3.0000e+00 octave:21> 'is u orthogonal?' ans = is u orthogonal? octave:22> u u = -0.70711 0.70711 0.70711 0.70711 octave:23> u' ans = -0.70711 0.70711 0.70711 0.70711 octave:24> inv(w) error: `w' undefined near line 24 column 5 error: evaluating expression near line 24, column 5 error: evaluating argument list element number 1 error: evaluating index expression near line 24, column 1 octave:24> inv(u) ans = -0.70711 0.70711 0.70711 0.70711 octave:25> u' ans = -0.70711 0.70711 0.70711 0.70711 octave:26> inv(u) - u' ans = -1.1102e-16 1.1102e-16 1.1102e-16 1.1102e-16 octave:27> 'this is what octave does when we use the two-answer version of eig functioni' ans = this is what octave does when we use the two-answer version of eig functioni octave:28> [vec,val] = eig(a) vec = -0.70711 0.70711 0.70711 0.70711 val = 1 0 0 3 octave:29> 'exer 5b' ans = exer 5b octave:30> a [ 1 3+i; 3-i -1] parse error: use `(' and `)' as index operators, not `[' and `]' >>> a [ 1 3+i; 3-i -1] ^ octave:30> a a = 2 1 1 2 octave:31> a = [1 3+i; 3-i 4] a = 1 + 0i 3 + 1i 3 - 1i 4 + 0i octave:32> a' ans = 1 + 0i 3 + 1i 3 - 1i 4 + 0i octave:33> a - a' ans = 0 0 0 0 octave:34> 'so a is hermitian' ans = so a is hermitian octave:35> 'so we can get a unitary diaganlization' ans = so we can get a unitary diaganlization octave:36> eig(a) ans = -1.0000 6.0000 octave:37> [vec,val] = eig(a) vec = 0.80178 + 0.26726i 0.50709 + 0.16903i -0.53452 + 0.00000i 0.84515 + 0.00000i val = -1.00000 0.00000 0.00000 6.00000 octave:38> v1 = vec(1,;) parse error: >>> v1 = vec(1,;) ^ octave:38> v1 = vec(1,:) v1 = 0.80178 + 0.26726i 0.50709 + 0.16903i octave:39> v1 = vec(:,1) v1 = 0.80178 + 0.26726i -0.53452 + 0.00000i octave:40> v2 = vec(:,2) v2 = 0.50709 + 0.16903i 0.84515 + 0.00000i octave:41> v1' * v2 ans = -4.6458e-17 - 1.1343e-17i octave:42> norm(v1) ans = 1.0000 octave:43> norm(v2) ans = 1 octave:44> 'so we see that v1,v2 is an o.n.basis consisting of eigenvectors' ans = so we see that v1,v2 is an o.n.basis consisting of eigenvectors octave:45> 'so they will give us the unitary diagonalizeation' ans = so they will give us the unitary diagonalizeation octave:46> 'vec should be a unitary matrix' ans = vec should be a unitary matrix octave:47> inv(vec) ans = 0.80178 - 0.26726i -0.53452 + 0.00000i 0.50709 - 0.16903i 0.84515 + 0.00000i octave:48> vec' ans = 0.80178 - 0.26726i -0.53452 + 0.00000i 0.50709 - 0.16903i 0.84515 + 0.00000i octave:49> inv(vec) - vec' ans = 0.00000 + 0.00000i 0.00000 + 0.00000i 0.00000 - 0.00000i 0.00000 + 0.00000i octave:50> inv(vec) * a * vec ans = -1.0000e+00 + 8.2142e-18i -2.5224e-16 - 3.4487e-17i -5.0849e-16 + 1.5176e-16i 6.0000e+00 - 3.3788e-17i octave:51> 'exer 5f' ans = exer 5f octave:52> a = [1 1 1; 1 1 1; 1 1 1] a = 1 1 1 1 1 1 1 1 1 octave:53> eig(a) ans = -2.8448e-17 9.5479e-17 3.0000e+00 octave:54> 'eigenvalues are 0 0 3' ans = eigenvalues are 0 0 3 octave:55> 'get eigenvectors for 3; for 0' ans = get eigenvectors for 3; for 0 octave:56> 'apply Gram Schmidt to 2-dim eigenspace for 0' ans = apply Gram Schmidt to 2-dim eigenspace for 0 octave:57> v1 = 1/sqrt(3) * [1 1 1]' v1 = 0.57735 0.57735 0.57735 octave:58> v2 = 1/sqrt(2) * [-1 1 0]' v2 = -0.70711 0.70711 0.00000 octave:59> v3 = 1/sqrt(6) * [1 1 -2]' v3 = 0.40825 0.40825 -0.81650 octave:60> 'should give unitary matrix' ans = should give unitary matrix octave:61> u = [v1,v2,v3]' u = 0.57735 0.57735 0.57735 -0.70711 0.70711 0.00000 0.40825 0.40825 -0.81650 octave:62> inv(u) - u' ans = -2.2204e-16 -1.1102e-16 -1.1102e-16 -2.2204e-16 0.0000e+00 -1.1102e-16 -2.2204e-16 -6.0526e-17 2.2204e-16 octave:63> 'I mean orthogonal matrix, not unitary, since in real case' ans = I mean orthogonal matrix, not unitary, since in real case octave:64> inv(u) * a * u ans = 0.077558 0.471405 -0.066600 0.471405 2.865251 -0.404804 -0.066600 -0.404804 0.057191 octave:65> a a = 1 1 1 1 1 1 1 1 1 octave:66> u u = 0.57735 0.57735 0.57735 -0.70711 0.70711 0.00000 0.40825 0.40825 -0.81650 octave:67> v1 v1 = 0.57735 0.57735 0.57735 octave:68> v2 v2 = -0.70711 0.70711 0.00000 octave:69> v3 v3 = 0.40825 0.40825 -0.81650 octave:70> u = [v1,v2,v3] u = 0.57735 -0.70711 0.40825 0.57735 0.70711 0.40825 0.57735 0.00000 -0.81650 octave:71> inv(u) - u' ans = -2.2204e-16 -1.1102e-16 -2.2204e-16 -1.1102e-16 1.1102e-16 0.0000e+00 -1.1102e-16 -1.1102e-16 2.2204e-16 octave:72> inv(u) * a * u ans = 3.00000 -0.00000 -0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 octave:73> 'give an example of method NOT working, if a is NOT symmetric' ans = give an example of method NOT working, if a is NOT symmetric octave:74> a = [1 1; 2 2] a = 1 1 2 2 octave:75> a - a' ans = 0 -1 1 0 octave:76> 'a is not symmetric' ans = a is not symmetric octave:77> eig(a) ans = 3.0000e+00 1.3347e-16 octave:78> 'eigenvalues are 3,0] error: unterminated string constant parse error: >>> 'eigenvalues are 3,0] ^ octave:78> octave:78> ' error: unterminated string constant parse error: >>> ' ^ octave:78> 'end mon 4 dec 06' ans = end mon 4 dec 06 octave:79> quit octave:2> 'start wed 6 dec 06' ans = start wed 6 dec 06 octave:3> 'doing sec 6.6, exer 3 but apply to matrix of exer 1b' ans = doing sec 6.6, exer 3 but apply to matrix of exer 1b octave:4> octave:4> a = [2 1/2 -1; 1/2 3 3/2; -1 3/2 1] a = 2.00000 0.50000 -1.00000 0.50000 3.00000 1.50000 -1.00000 1.50000 1.00000 octave:5> a' - a ans = 0 0 0 0 0 0 0 0 0 octave:6> eig(a) ans = -0.33724 2.53380 3.80344 octave:7> [vec,val] = eig(a) vec = 0.431424 -0.901898 0.021284 -0.422834 -0.222991 -0.878343 0.796922 0.369938 -0.477556 val = -0.33724 0.00000 0.00000 0.00000 2.53380 0.00000 0.00000 0.00000 3.80344 octave:8> x = vec x = 0.431424 -0.901898 0.021284 -0.422834 -0.222991 -0.878343 0.796922 0.369938 -0.477556 octave:9> inv(x) * a * x ans = -3.3724e-01 -2.2558e-16 1.9058e-16 -6.6462e-17 2.5338e+00 -1.8025e-17 -1.8323e-16 3.7784e-17 3.8034e+00 octave:10> 'strong form on made up exercise' ans = strong form on made up exercise octave:11> a = [1 1; 1 2] a = 1 1 1 2 octave:12> eig(a) ans = 0.38197 2.61803 octave:13> [vec,val] = eig(a) vec = -0.85065 0.52573 0.52573 0.85065 val = 0.38197 0.00000 0.00000 2.61803 octave:14> x = vec x = -0.85065 0.52573 0.52573 0.85065 octave:15> inv(x) ans = -0.85065 0.52573 0.52573 0.85065 octave:16> x' ans = -0.85065 0.52573 0.52573 0.85065 octave:17> inv(x) * a * x ans = 3.8197e-01 -5.1489e-16 1.6935e-16 2.6180e+00 octave:18> x' * a * x ans = 3.8197e-01 2.9409e-17 1.6935e-16 2.6180e+00 octave:19> eig(a) ans = 0.38197 2.61803 octave:20> 'exer 6, which are pos def, neg def, indef?' ans = exer 6, which are pos def, neg def, indef? octave:21> 'exer 6a' ans = exer 6a octave:22> a = [3 2 ; 2 2] a = 3 2 2 2 octave:23> eig(a) ans = 0.43845 4.56155 octave:24> 'all pos eigenvalues, so pos def' ans = all pos eigenvalues, so pos def octave:25> 'exer 6b] error: unterminated string constant parse error: >>> 'exer 6b] ^ octave:25> 'exer 6b' ans = exer 6b octave:26> ' error: unterminated string constant parse error: >>> ' ^ octave:26> a = [3 4 ; 4 1] a = 3 4 4 1 octave:27> eig(a) ans = -2.1231 6.1231 octave:28> 'exer 6d' ans = exer 6d octave:29> a = [-2 0 1; 0 -1 0 ; 1 0 -2] a = -2 0 1 0 -1 0 1 0 -2 octave:30> eig(a) ans = -3 -1 -1 octave:31> 'end 6 dec' ans = end 6 dec octave:32> quit octave:2> octave:2> start 'fri dec 8 06' parse error: >>> start 'fri dec 8 06' ^ octave:2> 'sec 6.7, exer 1' ans = sec 6.7, exer 1 octave:3> '1a' ans = 1a octave:4> a = [ 6 4 -2; 4 5 3 ; -2 3 6] a = 6 4 -2 4 5 3 -2 3 6 octave:5> 'check for pos def by method 1 from sec 6.6, that is, eigenvalus positive?' ans = check for pos def by method 1 from sec 6.6, that is, eigenvalus positive? octave:6> eig(a) ans = -0.50147 7.85695 9.64453 octave:7> 'by method 1 we see will not be pos def' ans = by method 1 we see will not be pos def octave:8> 'by method of sec 6.7, det of principal submatrices' ans = by method of sec 6.7, det of principal submatrices octave:9> det(a) ans = -38.000 octave:10> 'exer 1d' ans = exer 1d octave:11> a = [4 2 1 ; 2 3 -2; 1 -2 5] a = 4 2 1 2 3 -2 1 -2 5 octave:12> eig(a) ans = 0.38814 5.34132 6.27053 octave:13> 'so from old method we see pos def is yes' ans = so from old method we see pos def is yes octave:14> det(a) ans = 13.000 octave:15> 'exer 4' ans = exer 4 octave:16> '4b' ans = 4b octave:17> a = [9 -3; -3 2] a = 9 -3 -3 2 octave:18> 'use op of add 3 times 1st row to 2nd row' ans = use op of add 3 times 1st row to 2nd row octave:19> 'this operation has matrix as follows' ans = this operation has matrix as follows octave:20> x = eye(2) x = 1 0 0 1 octave:21> x(2,1) = 3 x = 1 0 3 1 octave:22> x * a ans = 9 -3 24 -7 octave:23> 'sorry, use 1/3 not 3!' ans = sorry, use 1/3 not 3! octave:24> x(2,1) = 1/3 x = 1.00000 0.00000 0.33333 1.00000 octave:25> x * a ans = 9 -3 0 1 octave:26> u = x * a u = 9 -3 0 1 octave:27> l = iv(x) error: `iv' undefined near line 27 column 5 error: evaluating index expression near line 27, column 5 error: evaluating assignment expression near line 27, column 3 octave:27> l = inv(x) l = 1.00000 0.00000 -0.33333 1.00000 octave:28> a a = 9 -3 -3 2 octave:29> l * u ans = 9 -3 -3 2 octave:30> l' ans = 1.00000 -0.33333 0.00000 1.00000 octave:31> u * inv(l') ans = 9 0 0 1 octave:32> d = u * inv(l') d = 9 0 0 1 octave:33> u u = 9 -3 0 1 octave:34> u * l' ans = 9 -6 0 1 octave:35> u u = 9 -3 0 1 octave:36> a a = 9 -3 -3 2 octave:37> l * u ans = 9 -3 -3 2 octave:38> u u = 9 -3 0 1 octave:39> l l = 1.00000 0.00000 -0.33333 1.00000 octave:40> d d = 9 0 0 1 octave:41> l' ans = 1.00000 -0.33333 0.00000 1.00000 octave:42> d * l' ans = 9 -3 0 1 octave:43> u u = 9 -3 0 1 octave:44> a a = 9 -3 -3 2 octave:45> l * d * l' ans = 9 -3 -3 2 octave:46> u * inv(l') ans = 9 0 0 1 octave:47> d * l' ans = 9 -3 0 1 octave:48> u u = 9 -3 0 1 octave:49> 'exer 5, applying to 4b' ans = exer 5, applying to 4b octave:50> 'let e be square root so to speak of d' ans = let e be square root so to speak of d octave:51> e = [3 0 ; 0 1] e = 3 0 0 1 octave:52> 'new l, call it m, is old l multiplied on right by e' ans = new l, call it m, is old l multiplied on right by e octave:53> m = l * e m = 3 0 -1 1 octave:54> m' ans = 3 -1 0 1 octave:55> a a = 9 -3 -3 2 octave:56> m * m' ans = 9 -3 -3 2 octave:57> 'end fri 8 dec' ans = end fri 8 dec octave:58> quit