hw2hint_98F - R Q QR Algorithm of Diagonalization of a...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Hint to Homework #2 : Mathematica Householder Transformation, QR Decomposition, and QR Algorithm October 21, 1998 command to form a QR algorithm for diagonalization of the mass matrix : QR Decompostion of Mg by the Householder transformation In[146]:= R=N[Mg] Q=IdentityMatrix[neq]; Block[{i,j}, Do[RT=Transpose[R]; mi=RT[[i]]; If[i>1,Do[mi[[j]]=0,{j,1,i-1}]]; norm=Sqrt[mi.mi]; vi=mi; vi[[i]]=vi[[i]]-norm; P=IdentityMatrix[neq]-2*Outer[Times,vi,vi]/(vi.vi); R=P.R; Q=Q.P,{i,1,neq-1}]]
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: R Q QR Algorithm of Diagonalization of a matrix A In[151]:= error=1; toler=0.001; iter=0; While[error>toler, R=A; Q=IdentityMatrix[neq]; Block[{i,j}, Do[RT=Transpose[R]; mi=RT[[i]]; If[i>1,Do[mi[[j]]=0,{j,1,i-1}]]; norm=Sqrt[mi.mi]; vi=mi; vi[[i]]=vi[[i]]-norm; P=IdentityMatrix[neq]-2*Outer[Times,vi,vi]/(vi.vi); R=P.R; Q=Q.P,{i,1,neq-1}]]; An=R.Q; error=Sqrt[Flatten[An-A].Flatten[An-A]]/Sqrt[Flatten[An].Flatten[An]]; iter=iter+1; Print["iteration = ",iter," relative error = ",error]; A=An] A...
View Full Document

This document was uploaded on 12/08/2011.

Page1 / 2

hw2hint_98F - R Q QR Algorithm of Diagonalization of a...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online