# Hello, I’m trying to do the QR decomposition using Gram Schmidt but I’m having problems because I can’t find the R matrix. Could you help me?

First of all I don’t want to use the reflection method. Only Gram-Schmidt.

So here’s the program for Gram-Schidt:

``GS[A_] := Module[{u = {}, col, e = {}, ae, t},   col = Transpose[A];(* list with the column vectors of A *)   u = Append[u, col[]];   e = AppendTo[e, u[]/Norm[u[]]];   For[i = 2, i <= Length[A], i++, ae = 0; t = 1;    While[t <= i - 1, ae = ae - (col[[i]].e[[t]])*e[[t]]; t++];    u = AppendTo[u, col[[i]] + ae];    e = Append[e, u[[i]]/Norm[u[[i]]]]]; {u, e}] ``

with this simple matrix:

``B = {{1, 3, 1}, {2, 2, 1}, {3, 2, 3}}; ``

gives

``{{{1, 2, 3}, {29/14, 1/7, -(11/14)}, {14/69, -(49/69), 28/69}}, {{1/    Sqrt, Sqrt[2/7], 3/Sqrt}, {29/Sqrt, Sqrt[2/    483], -(11/Sqrt)}, {2/Sqrt, -(7/Sqrt), 4/Sqrt}}} ``

Now the code for QR decomposition is:

``QR[A_] := Module[{Ak, i, Q, R = {}, a = {}, col, k},   Ak = FullSimplify[GS[A]];   col = Transpose[A];(* list with the column vectors of A *)   Q = MatrixForm[Transpose[Ak[]]];   For[i = 1, i <= Length[Ak[]], i++, a = {}; k == 1;    While[k <= Length[col], a = AppendTo[a, col[[k]]. Ak[][[i]]];      k++];     R = AppendTo[R, a]];   R = UpperTriangularize[R]; {Q, R}] ``

but I can’t find matrix R, once it’s giving me a list like this{{},{},{}} and I’m stuck. Please help me.Thanks!

Posted on Categories cheapest proxies