// A = Q * R  QR Decomposition
void QRDecomp(MAT &A,MAT &Q, MAT &R){
    int n=A.dim();
    MAT AT(A.tpose());
    MAT QT(Q.tpose());
    VEC S(n);			//sum vector
    R[0][0]=sqrt(AT[0]*AT[0]);	//initial R
    QT[0]=AT[0]/R[0][0];		//initial Q

    for(int j=1;j<n;j++){
    	for(int i=0;i<n;i++){
            S[i] = 0;
        }       //initialization of sum vector
        for(int i=0;i<=j;i++){
          	R[i][j] = QT[i]*AT[j];
        } 
        for(int i=0;i<=j-1;i++){ 
          	S = S + R[i][j]*QT[i];		//do the summation
        }
        S = AT[j] - S;  
        R[j][j]=sqrt(S*S);
        QT[j] = S/R[j][j];
    }
    Q=QT.tpose(); 
        
}
VEC choSolve(MAT &L, VEC b){
	VEC y(b);
	y = fwdSubs1(L,b);				//do the forward substitution to solve y
	L = L.tpose();					//compute the transpose of L
	VEC x(y);
	x = bckSubs(L,y);				//do the backward substitution to solve x
	return x;
}