(* ::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.                                                         *)
(************************************************************************)



RandomSym[n_]:=Module[
{Q,Evals},
Q=QRDecomposition[RandomReal[{-1,1},{n,n}]][[1]];
Evals= RandomReal[{0.1,12},n];
Q.DiagonalMatrix[Evals].Transpose[Q]
]


CholeskyInnerOne[A_]:=Module[
{n=Length[A],R=0*A,i,j},
Do[
R[[i,i]]=Sqrt[A[[i,i]]-Sum[R[[k,i]]^2,{k,1,i-1}]];
Do[
R[[i,j]]=(A[[i,j]]-Sum[R[[k,i]] R[[k,j]],{k,1,i-1}])/R[[i,i]],
{j,i+1,n}],
{i,1,n}];
R
]


CholeskyInnerTwo[A_]:=Module[
{n=Length[A],R=0*A,i,j,ri,rj,rii},
Do[
ri=R[[1;;i-1,i]];
rii=Sqrt[A[[i,i]]-ri.ri];
R[[i,i]]=rii;
Do[
rj=R[[1;;i-1,j]];
R[[i,j]]=(A[[i,j]]-ri.rj)/rii,
{j,i+1,n}],
{i,1,n}];
R
]


CholeskyInnerThree[A_]:=Module[
{n=Length[A],R=0*A,i,j,ri,rj,rii},
Do[
ri=R[[1;;i-1,i]];
rii=Sqrt[A[[i,i]]-ri.ri];
R[[i,i]]=rii;
rj=R[[1;;i-1,i+1;;n]];
R[[i,i+1;;n]]=(A[[i,i+1;;n]]-ri.rj)/rii,
{i,1,n}];
R
]


CholeskyOuterOne[A_]:=Module[
{n=Length[A]},
AA=A;R=0*A;
Do[
R[[i,i]]=Sqrt[AA[[i,i]]];
s=AA[[i,i+1;;-1]]/R[[i,i]];
R[[i,i+1;;-1]]=s;
AA[[i+1;;-1,i+1;;-1]]=AA[[i+1;;-1,i+1;;-1]]-Outer[Times, s,s],
{i,1,n}];
R
]


CholeskyOuterTwo[A_]:=Module[
{n=Length[A]},
AA=A;R=0*A;
Do[
R[[i,i]]=Sqrt[AA[[i,i]]];
s=AA[[i,i+1;;-1]]/R[[i,i]];
R[[i,i+1;;-1]]=s;
AA[[i+1;;-1,i+1;;-1]]-=Outer[Times, s,s],
{i,1,n}];
R
]


CholeskyOuterThree[A_]:=Module[
{n=Length[A],r11=Sqrt[A[[1,1]]],s, AHat},
s=A[[1,2;;-1]]/r11;
AHat=A[[2;;-1,2;;-1]]-Outer[Times,s,s];
Flatten[
If[Length[A]>1,
Join[Join[{r11},s],CholeskyOuterThree[AHat]],
{r11}
]
]
]



