-4
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ @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 $\endgroup$
    – Muro
    Jun 6 '21 at 10:50
3
$\begingroup$

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.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.