(* ::Package:: *)

(************************************************************************)
(* This file was generated automatically by the Mathematica front end.  *)
(* It contains Initialization cells from a Notebook file, which         *)
(* typically will have the same name as this file except ending in      *)
(* ".nb" instead of ".m".                                               *)
(*                                                                      *)
(* This file is intended to be loaded into the Mathematica kernel using *)
(* the package loading commands Get or Needs.  Doing so is equivalent   *)
(* to using the Evaluate Initialization Cells menu command in the front *)
(* end.                                                                 *)
(*                                                                      *)
(* DO NOT EDIT THIS FILE.  This entire file is regenerated              *)
(* automatically each time the parent Notebook file is saved in the     *)
(* Mathematica front end.  Any changes you make to this file will be    *)
(* overwritten.                                                         *)
(************************************************************************)



CGS[A_]:= Module[
{m,n,Q,R,i,j,v,r},
{m,n}=Dimensions[A];
Q=Table[0,{m},{n}];
R=Table[0,{n},{n}];
Do[
v=A[[All,j]];
Do[
r=Q[[All,i]].A[[All,j]];
v=v-r Q[[All,i]];
R[[i,j]]=r,
{i,j-1}];
r=Norm[v];
Q[[All,j]]=v/r;
R[[j,j]]=r,
{j,1,n}
];
{Q,R}
]


Clear[MGS,A]
MGS[A_]:= Module[
{m,n,V,Q,R,i,j,q, v,r},
{m,n}=Dimensions[A];
V=A;
Q=Table[0,{m},{n}];
R=Table[0,{n},{n}];
Do[
v=V[[All,i]];
r = Norm[v];
q=v/r;
Q[[All,i]]=q;
R[[i,i]]=r;
Do[
v=V[[All,j]];
r=q.v;
v=v-r q;
V[[All,j]]=v;
R[[i,j]]=r,
{j,i+1,n}
],
{i,1,n}
];
{Q,R}
]



