LU Decomposition

LU[A_]:=
(U=A;
n=Length[A];
L=Table[0,{n},{n}];
For[i=1,i≤n,i++,
L[[i,i]]=1
];
For[i=1, i≤n, i++,
For[j=i+1,j≤n,j++,
l=((U[[j,i]])/(U[[i,i]]));
L[[j,i]]=l;
U[[j,i]]=0;
For[k=i+1,k≤n,k++,
U[[j,k]]=U[[j,k]]-l*U[[i,k]];
]
]
];
{L,U}
)

A={{1,1,1},{1,2,2},{1,2,3}};
LU[A][[1]]//MatrixForm
LU[A][[2]]//MatrixForm

LUSolve

LUSolve[L_,U_,b_]:=(
n=Length[b];
y=Table[0,{i,n}] ;
For[i=1,i≤n, i++,
y[[i]]=((b[[i]]-Sum[L[[i,j]]y[[j]],{j,1,i-1}])/(L[[i,i]]))

];
x=Table[0,{i,n}] ;
For[i=n,i≥1, i--,
x[[i]]=((y[[i]]-Sum[U[[i,j]]x[[j]],{j,i+1,n}])/(U[[i,i]]))

];
x
)

A={{1,7,5},{1,2,2},{1,2,3}};
luA=LU[A];
LUSolve[luA[[1]],luA[[2]],{1,2,3}]

LinearSolve[{{1,7,5},{1,2,2},{1,2,3}},{1,2,3}]

Inverse Matrix

InverseMatrix[A_]:=(
{L,U}=LU[A];
n=Length[A];
AInverse=Table[0,{n},{n}];
For[k=1,k≤n,k++,
b=Table[If[l==k,1,0],{l,1,n}];
AInverse[[k]]=LUSolve[L,U,b];
];
Transpose[AInverse]
)

InverseMatrix[{{1,7,5},{1,2,2},{1,2,3}}]

Inverse[{{1,7,5},{1,2,2},{1,2,3}}]