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



LU[A_,0]:=Module[{LU=A, n=Length[A],d,e,r,i,j},
Do[
d=1/LU[[r,r]];
Do[
e = d LU[[i,r]];
LU[[i,r]]=e;
Do[
LU[[i,j]]-= e* LU[[r,j]],
{j,r+1,n}
],
{i,r+1,n,1}],
{r,1,n-1,1}];
{LowerTriangularize[LU,-1]+SparseArray[Band[{1,1}]->1,{n,n}], 
UpperTriangularize[LU]}
]

LUPivot[A_,0]:=Module[{LU=A, n=Length[A],perm,pivot,d,e,r,i,j},
perm=Table[i,{i,n}];
Do[
(* Partial Pivoting *)
pivot=Ordering[Abs[LU[[r;;n,r]]],-1][[1]]+r-1;
perm[[{r,pivot}]]=perm[[{pivot,r}]];
LU[[{r,pivot}]]=LU[[{pivot,r}]];
(* End Partial Pivoting *)
d=1/LU[[r,r]];
Do[
e = d LU[[i,r]];
LU[[i,r]]=e;
Do[
LU[[i,j]]-= e* LU[[r,j]],
{j,r+1,n}
],
{i,r+1,n,1}],
{r,1,n-1,1}];
{LowerTriangularize[LU,-1]+SparseArray[Band[{1,1}]->1,{n,n}], 
UpperTriangularize[LU], perm}
]



