A A = 1 2 3 4 5 6 7 8 10 x=A([1 2],1) x = 1 4 r=norm(x) r = 4.1231 c=x(1)/r c = 0.2425 s=-x(2)/r s = -0.9701 G=[c -s;s c] G = 0.2425 0.9701 -0.9701 0.2425 G'*G-eye(2) ans = 1.0e-17 * 0 0.5317 0.5317 0 G12=eye(3); G12([1 2],[1 2])=G G12 = 0.2425 0.9701 0 -0.9701 0.2425 0 0 0 1.0000 A1=G12*A A1 = 4.1231 5.3358 6.5485 0 -0.7276 -1.4552 7.0000 8.0000 10.0000 x=A1([1 3],1) x = 4.1231 7.0000 r=norm(x); c=x(1)/r c = 0.5075 s=-x(2)/r s = -0.8616 G=[c -s;s c] G = 0.5075 0.8616 -0.8616 0.5075 G'*G-eye(2) ans = 1.0e-15 * -0.1110 -0.0062 -0.0062 -0.1110 G13=eye(3); G13([1,3],[1 3])=G G13 = 0.5075 0 0.8616 0 1.0000 0 -0.8616 0 0.5075 A2=G13*A1 A2 = 8.1240 9.6011 11.9399 0 -0.7276 -1.4552 -0.0000 -0.5374 -0.5672 A2(3,1) ans = -4.4409e-16 A2(3,1)=0; x=A2([2 3],2) x = -0.7276 -0.5374 r=norm(x); c=x(1)/r; s=-x(2)/r; G=[c -s;s c] G = -0.8044 -0.5941 0.5941 -0.8044 G'*G-eye(2) ans = 1.0e-16 * 0 -0.1102 -0.1102 0 G23=eye(3); G23([2 3],[2 3])=G G23 = 1.0000 0 0 0 -0.8044 -0.5941 0 0.5941 -0.8044 A3=G23*A2 A3 = 8.1240 9.6011 11.9399 0 0.9045 1.5076 0 0.0000 -0.4082 A3(3,2) ans = 5.5511e-17 A3(3,2)=0; R=A3 R = 8.1240 9.6011 11.9399 0 0.9045 1.5076 0 0 -0.4082 G=G23*G13*G12 G = 0.1231 0.4924 0.8616 0.9045 0.3015 -0.3015 -0.4082 0.8165 -0.4082 G'*G-eye(3) ans = 1.0e-15 * 0 -0.0245 -0.0331 -0.0245 -0.1110 -0.0607 -0.0331 -0.0607 -0.2220 Q=G' Q = 0.1231 0.9045 -0.4082 0.4924 0.3015 0.8165 0.8616 -0.3015 -0.4082 R R = 8.1240 9.6011 11.9399 0 0.9045 1.5076 0 0 -0.4082 [Q1,R1]=qr(A) Q1 = -0.1231 0.9045 0.4082 -0.4924 0.3015 -0.8165 -0.8616 -0.3015 0.4082 R1 = -8.1240 -9.6011 -11.9399 0 0.9045 1.5076 0 0 0.4082 A=[1 2 3;4 5 6;7 8 9] A = 1 2 3 4 5 6 7 8 9 [Q1,R1]=qr(A) Q1 = -0.1231 0.9045 0.4082 -0.4924 0.3015 -0.8165 -0.8616 -0.3015 0.4082 R1 = -8.1240 -9.6011 -11.0782 0 0.9045 1.8091 0 0 -0.0000 R1(3,3) ans = -1.1116e-15 x=A([1 2],1) x = 1 4 r=norm(x);c=x(1)/r;s=-x(2)/r; G=[c -s;s c]; G12=eye(3); G12([1 2],[1 2])=G; A1=G12*A A1 = 4.1231 5.3358 6.5485 0 -0.7276 -1.4552 7.0000 8.0000 9.0000 x=A1([1 3],1); r=norm(x);c=x(1)/r;s=-x(2)/r; G=[c -s;s c]; G13=eye(3); G13([1,3],[1 3])=G; A2=G13*A1 A2 = 8.1240 9.6011 11.0782 0 -0.7276 -1.4552 -0.0000 -0.5374 -1.0747 A2(3,1)=0; x=A2([2 3],2); r=norm(x);c=x(1)/r;s=-x(2)/r; G=[c -s;s c]; G23=eye(3); G23([2 3],[2 3])=G G23 = 1.0000 0 0 0 -0.8044 -0.5941 0 0.5941 -0.8044 A3=G23*A2 A3 = 8.1240 9.6011 11.0782 0 0.9045 1.8091 0 0.0000 0 A3(3,2)=0 A3 = 8.1240 9.6011 11.0782 0 0.9045 1.8091 0 0 0 R=A3; G=G23*G13*G12; Q=G' Q = 0.1231 0.9045 -0.4082 0.4924 0.3015 0.8165 0.8616 -0.3015 -0.4082 R R = 8.1240 9.6011 11.0782 0 0.9045 1.8091 0 0 0 [Q1,R1]=qr(A) Q1 = -0.1231 0.9045 0.4082 -0.4924 0.3015 -0.8165 -0.8616 -0.3015 0.4082 R1 = -8.1240 -9.6011 -11.0782 0 0.9045 1.8091 0 0 -0.0000 det(R) ans = 0 det(R1) ans = 8.1689e-15 det(A) ans = -9.5162e-16 A=[1 1 1 1 1;1 2 3 4 5]' A = 1 1 1 2 1 3 1 4 1 5 [Q,R]=qr(A) Q = -0.4472 -0.6325 -0.4149 -0.3626 -0.3104 -0.4472 -0.3162 0.0672 0.3996 0.7320 -0.4472 0.0000 0.8377 -0.2013 -0.2403 -0.4472 0.3162 -0.2174 0.6543 -0.4739 -0.4472 0.6325 -0.2726 -0.4900 0.2925 R = -2.2361 -6.7082 0 3.1623 0 0 0 0 0 0 A=[1 1 1 1 1;1 2 3 4 5] A = 1 1 1 1 1 1 2 3 4 5 [Q,R]=qr(A) Q = -0.7071 -0.7071 -0.7071 0.7071 R = -1.4142 -2.1213 -2.8284 -3.5355 -4.2426 0 0.7071 1.4142 2.1213 2.8284 Q*R-A ans = 1.0e-14 * -0.0333 -0.0555 -0.1332 -0.0666 -0.0888 0 -0.0222 -0.0444 0 0 A=[1 1 1 1 1;1 1 3 4 5] A = 1 1 1 1 1 1 1 3 4 5 A=[1 1 1 1 1;1 1 3 4 5]' A = 1 1 1 1 1 3 1 4 1 5 [Q,R]=qr(A) Q = -0.4472 -0.5031 -0.4384 -0.4269 -0.4153 -0.4472 -0.5031 0.0759 0.3590 0.6421 -0.4472 0.0559 0.8314 -0.2089 -0.2492 -0.4472 0.3354 -0.2125 0.6893 -0.4089 -0.4472 0.6149 -0.2563 -0.4125 0.4313 R = -2.2361 -6.2610 0 3.5777 0 0 0 0 0 0 A=[1 1 1 1 1;2 2 2 2 2]' A = 1 2 1 2 1 2 1 2 1 2 [Q,R]=qr(A) Q = -0.4472 0.8944 -0.0000 -0.0000 -0.0000 -0.4472 -0.2236 -0.5000 -0.5000 -0.5000 -0.4472 -0.2236 0.8333 -0.1667 -0.1667 -0.4472 -0.2236 -0.1667 0.8333 -0.1667 -0.4472 -0.2236 -0.1667 -0.1667 0.8333 R = -2.2361 -4.4721 0 -0.0000 0 0 0 0 0 0 R(2,2) ans = -2.3269e-16 A=[1 1 1 1 1;1 1 1 1 1]' A = 1 1 1 1 1 1 1 1 1 1 R(2,2) ans = -2.3269e-16 [Q,R]=qr(A) Q = -0.4472 0.8944 -0.0000 -0.0000 -0.0000 -0.4472 -0.2236 -0.5000 -0.5000 -0.5000 -0.4472 -0.2236 0.8333 -0.1667 -0.1667 -0.4472 -0.2236 -0.1667 0.8333 -0.1667 -0.4472 -0.2236 -0.1667 -0.1667 0.8333 R = -2.2361 -2.2361 0 -0.0000 0 0 0 0 0 0 R(2,2) ans = -1.1634e-16 A A = 1 1 1 1 1 1 1 1 1 1 U=[1+i 0; 0 (1-i)/2] U = 1.0000 + 1.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.5000 - 0.5000i U'*U ans = 2.0000 0 0 0.5000 U=[(1+i)/sqrt(2) 0; 0 (1-i)/sqrt(2)] U = 0.7071 + 0.7071i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.7071 - 0.7071i U'*U ans = 1.0000 0 0 1.0000 det(U) ans = 1.0000 U=[i 0;0 1] U = 0.0000 + 1.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 1.0000 + 0.0000i U'*U ans = 1 0 0 1 det(U) ans = 0.0000 + 1.0000i det(U') ans = 0.0000 - 1.0000i U=0.5*[1+i1-i;1-i 1+i] {Undefined function or variable 'i1'.} U=0.5*[1+i 1-i;1-i 1+i] U = 0.5000 + 0.5000i 0.5000 - 0.5000i 0.5000 - 0.5000i 0.5000 + 0.5000i U'*U ans = 1 0 0 1 det(U) ans = 0.0000 + 1.0000i det(U') ans = 0.0000 - 1.0000i A=[1 2 3;4 5 6;7 8 9] A = 1 2 3 4 5 6 7 8 9 [Q,R]=qr(A); A=R*Q A = 15.2727 -6.9031 0.0000 -2.0041 -0.2727 -0.0000 0.0000 0.0000 -0.0000 [Q,R]=qr(A);A=R*Q A = 16.1586 -4.7469 -0.0000 0.1520 -1.1586 0.0000 0.0000 -0.0000 -0.0000 [Q,R]=qr(A);A=R*Q A = 16.1139 -4.9095 0.0000 -0.0105 -1.1139 -0.0000 0.0000 0.0000 -0.0000 [Q,R]=qr(A);A=R*Q A = 16.1171 -4.8983 -0.0000 0.0007 -1.1171 0.0000 0.0000 -0.0000 -0.0000 [Q,R]=qr(A);A=R*Q A = 16.1168 -4.8990 0.0000 -0.0001 -1.1168 -0.0000 0.0000 0.0000 -0.0000 [Q,R]=qr(A);A=R*Q A = 16.1168 -4.8990 -0.0000 0.0000 -1.1168 0.0000 0.0000 -0.0000 -0.0000 format long A A = 16.116844961530521 -4.898975996867128 -0.000000000000005 0.000003488699230 -1.116844961530516 0.000000000000000 0.000000000000000 -0.000000000000000 -0.000000000000000 [Q,R]=qr(A);A=R*Q A = 16.116843901083847 -4.898979727321645 0.000000000000005 -0.000000241755286 -1.116843901083842 -0.000000000000000 0.000000000000000 0.000000000000000 -0.000000000000000 [Q,R]=qr(A);A=R*Q A = 16.116843974569342 -4.898979468813518 -0.000000000000005 0.000000016752842 -1.116843974569337 0.000000000000000 0.000000000000000 -0.000000000000000 -0.000000000000000 [Q,R]=qr(A);A=R*Q A = 16.116843969477042 -4.898979486727276 0.000000000000005 -0.000000001160917 -1.116843969477035 -0.000000000000000 0.000000000000000 0.000000000000000 -0.000000000000000 [Q,R]=qr(A);A=R*Q A = 16.116843969829922 -4.898979485485912 -0.000000000000005 0.000000000080448 -1.116843969829915 0.000000000000000 0.000000000000000 -0.000000000000000 -0.000000000000000 [Q,R]=qr(A);A=R*Q A = 16.116843969805469 -4.898979485571934 0.000000000000005 -0.000000000005575 -1.116843969805462 -0.000000000000000 0.000000000000000 0.000000000000000 -0.000000000000000 [Q,R]=qr(A);A=R*Q A = 16.116843969807164 -4.898979485565973 -0.000000000000005 0.000000000000386 -1.116843969807156 0.000000000000000 0.000000000000000 -0.000000000000000 -0.000000000000000 [Q,R]=qr(A);A=R*Q A = 16.116843969807046 -4.898979485566386 0.000000000000005 -0.000000000000027 -1.116843969807039 -0.000000000000000 0.000000000000000 0.000000000000000 -0.000000000000000 [Q,R]=qr(A);A=R*Q A = 16.116843969807054 -4.898979485566358 -0.000000000000005 0.000000000000002 -1.116843969807047 0.000000000000000 0.000000000000000 -0.000000000000000 -0.000000000000000 [Q,R]=qr(A);A=R*Q A = 16.116843969807054 -4.898979485566359 0.000000000000005 -0.000000000000000 -1.116843969807046 -0.000000000000000 0.000000000000000 0.000000000000000 -0.000000000000000 [Q,R]=qr(A);A=R*Q A = 16.116843969807054 -4.898979485566359 -0.000000000000005 0.000000000000000 -1.116843969807046 0.000000000000000 0.000000000000000 -0.000000000000000 -0.000000000000000 [Q,R]=qr(A);A=R*Q A = 16.116843969807054 -4.898979485566359 0.000000000000005 -0.000000000000000 -1.116843969807046 -0.000000000000000 0.000000000000000 0.000000000000000 -0.000000000000000 [Q,R]=qr(A);A=R*Q A = 16.116843969807054 -4.898979485566359 -0.000000000000005 0.000000000000000 -1.116843969807046 0.000000000000000 0.000000000000000 -0.000000000000000 -0.000000000000000 A(3,:) ans = 1.0e-15 * 0.000000000000000 -0.000000000000000 -0.453828149038388 A(2,1) ans = 4.277731343481284e-20 eig([1 2 3;4 5 6;7 8 9]) ans = 16.116843969807043 -1.116843969807042 -0.000000000000001 A=[1 2 3;4 5 6;7 8 10] A = 1 2 3 4 5 6 7 8 10 B=A; [Q,R]=qr(A);A=R*Q A = 16.015151515151523 -6.643313090275599 -0.351763235340715 -1.744333604709241 -0.181818181818182 -0.123091490979333 -0.351763235340724 -0.123091490979332 0.166666666666667 [Q,R]=qr(A);A=R*Q A = 16.734901091206172 -4.591852870124714 -1.387640361961922 0.103994577180329 -0.924995774381694 -0.163293978368585 0.004329289496538 -0.056348940814890 0.190094683175528 [Q,R]=qr(A);A=R*Q A = 16.705972325154956 -4.778103139904833 1.101530965515702 -0.005618047608844 -0.905188921702173 0.087249784220137 -0.000051633457236 -0.012258112213257 0.199216596547222 [Q,R]=qr(A);A=R*Q A = 16.707575645373918 -4.756835669230492 -1.166034089869882 0.000304694911433 -0.905573495906818 -0.102572861891548 0.000000612011625 -0.002679769739270 0.197997850532904 [Q,R]=qr(A);A=R*Q A = 16.707488852274018 -4.760586669730308 1.151953726732982 -0.000016517107063 -0.905788488580077 0.099285175888949 -0.000000007263903 -0.000586825609606 0.198299636306062 [Q,R]=qr(A);A=R*Q A = 16.707493558112098 -4.759821952928859 -1.155037578385545 0.000000895428649 -0.905728788028376 -0.100001571180982 0.000000000086187 -0.000128428785502 0.198235229916282 [Q,R]=qr(A);A=R*Q A = 16.707493303006178 -4.759986628855633 1.154362647968516 -0.000000048542524 -0.905742708764995 0.099844969526661 -0.000000000001023 -0.000028110989789 0.198249405758822 [Q,R]=qr(A);A=R*Q A = 16.707493316835937 -4.759950748132400 -1.154510379953173 0.000000002631570 -0.905739623575714 -0.099879236721606 0.000000000000012 -0.000006152850940 0.198246306739784 [Q,R]=qr(A);A=R*Q A = 16.707493316086204 -4.759958593591898 1.154478044747155 -0.000000000142662 -0.905740301314316 0.099871736961665 -0.000000000000000 -0.000001346727159 0.198246985228119 [Q,R]=qr(A);A=R*Q A = 16.707493316126847 -4.759956876865901 -1.154485122232361 0.000000000007734 -0.905740152857232 -0.099873378467943 0.000000000000000 -0.000000294769261 0.198246836730390 [Q,R]=qr(A);A=R*Q A = 16.707493316124644 -4.759957252596051 1.154483573124729 -0.000000000000419 -0.905740185358372 0.099873019179551 -0.000000000000000 -0.000000064518596 0.198246869233733 [Q,R]=qr(A);A=R*Q A = 16.707493316124765 -4.759957170358262 -1.154483912190787 0.000000000000023 -0.905740178244235 -0.099873097819896 0.000000000000000 -0.000000014121720 0.198246862119477 for k=1:10, [Q,R]=qr(A);A=R*Q; end A A = 16.707493316124758 -4.759957185125937 -1.154483851303510 0.000000000000000 -0.905740179521761 -0.099873083698179 0.000000000000000 -0.000000000000004 0.198246863397010 eig(B) ans = 16.707493316124744 -0.905740179521759 0.198246863397009 help hess hess Hessenberg form. H = hess(A) is the Hessenberg form of the matrix A. The Hessenberg form of a matrix is zero below the first subdiagonal and has the same eigenvalues as A. If the matrix is symmetric or Hermitian, the form is tridiagonal. [P,H] = hess(A) produces a unitary matrix P and a Hessenberg matrix H so that A = P*H*P' and P'*P = EYE(SIZE(P)). [AA,BB,Q,Z] = hess(A,B) for square matrices A and B, produces an upper Hessenberg matrix AA, an upper triangular matrix BB, and unitary matrices Q and Z such that Q*A*Z = AA, Q*B*Z = BB. Reference page for hess A=B; A=hess(A) A = 1.000000000000000 -3.597007303087045 -0.248069469178417 -8.062257748298549 14.799999999999997 2.399999999999999 0 0.399999999999997 0.199999999999999 B B = 1 2 3 4 5 6 7 8 10 for k=1:10, [Q,R]=qr(A);A=R*Q; end A A = 16.707493316126847 4.759957131908719 -1.154484070687116 -0.000000000007734 -0.905740174920756 0.099873134580804 0 0.000000050882121 0.198246858793914 for k=1:10, [Q,R]=qr(A);A=R*Q; end A A = 16.707493316124758 4.759957185125935 -1.154483851303556 -0.000000000000000 -0.905740179521760 0.099873083698189 0 0.000000000000013 0.198246863397007 diary off