# I want To adjust this code for below Matrix [closed]

may I ask for help to rewrite below code without using Function mode and only work for This Matrix $$\begin{pmatrix} {1,2,3\\4,5,6\\7,8,9} \end{pmatrix}$$ and my code is:

 Clear[practice];
practice[matA_] :=
Module[{n = Length[matA], matQ, matR = matA, x, c, s, matG},
matQ = IdentityMatrix[n];
Do[x = matR[[All, j]];
If[Norm[x[[i - 1 ;; i]]] > 0, c = x[[i - 1]]/Norm[x[[i - 1 ;; i]]];
s = -x[[i]]/Norm[x[[i - 1 ;; i]]];
matG = IdentityMatrix[n];
matG[[i - 1 ;; i, i - 1 ;; i]] = {{c, s}, {-s, c}};
matR = ConjugateTranspose[matG] . matR;
matQ = matQ . matG], {j, n}, {i, n, j + 1, -1}];
{matQ, matR}];


Thank You

• @Nasser , I want to change this code from any entry to only one matrix entry that I wrote, for clear I want to simplify this code and restrict this code to one $3*3$ matrix
– Muro
Jun 6 '21 at 10:50

To tell you the truth, I still do not understand the question.

But you say

rewrite below code without using Function mode

If you do not want the function, just remove it?

Clear["Global*"]
matA = Partition[Range[9], 3];
n = Length[matA];
matR = matA;
matQ = IdentityMatrix[n];
Do[x = matR[[All, j]];
If[Norm[x[[i - 1 ;; i]]] > 0,
c = x[[i - 1]]/Norm[x[[i - 1 ;; i]]];
s = -x[[i]]/Norm[x[[i - 1 ;; i]]];
matG = IdentityMatrix[n];
matG[[i - 1 ;; i, i - 1 ;; i]] = {{c, s}, {-s, c}};
matR = ConjugateTranspose[matG] . matR;
matQ = matQ . matG
],
{j, n}, {i, n, j + 1, -1}
];
{matQ, matR}
`

I do not see anything in the code that was hardcoded for specific matrix size and do not know what the function does.

If this is not what you meant, will delete this.