Esempio n. 1
0
        public static MMatrix Floor(MMatrix A)
        {
            MMatrix B = A.Clone();
            for (int i = 0; i < B.row; ++i)
                for (int j = 0; j < B.col; ++j)
                    B[i, j] = Math.Floor(B[i,j]);

            return B;
        }
Esempio n. 2
0
        public static double SpectralRadius_Jacobi(MMatrix A)
        {
            Vector Eigenvalues = new Vector();
            MMatrix Eigenvectors = new MMatrix();
            MMatrix temp = A.Clone();

            temp.Jacobi_Cyclic_Method(ref Eigenvalues, ref Eigenvectors);
            Eigenvalues.Sort(true);

            return Math.Abs(Eigenvalues[0]);
        }
Esempio n. 3
0
        //A = P^1*L*U = Pt*L*U
        private static void FactorLU_withP(MMatrix matrix, int size)
        {
            MMatrix A = matrix.Clone();
            MMatrix P = MMatrix.DiagonalMatrix(size, 1);
            A.LU_L = new double[size, size];

            for (int i = 0; i < size; ++i)
                A.LU_L[i, i] = 1;

            for (int i = 0; i < size; ++i)
            {
                //Interchange row if the entry [i,i] is 0
                if (A[i, i] == 0)	// if diagonal entry is zero,
                    for (int k = i + 1; k < A.row; ++k)
                        if (A[k, i] != 0)	 //check if some below entry is non-zero
                        {
                            A.InterchangeRow(i, k);	// then interchange the two rows
                            P.InterchangeRow(i, k);
                        }
                if (A[i, i] == 0)	// if not found any non-zero diagonal entry
                    throw new MMatrixException("Cannot factor LU for this matrix");

                for (int j = i + 1; j < size; ++j)
                {
                    A.LU_L[j, i] = A[j, i] / A[i, i];
                    A.AddRow(j, i, -A.LU_L[j, i]);
                }
            }
            matrix.LU_P = P.MArray;
            matrix.LU_L = A.LU_L;
            matrix.LU_U = A.MArray;
        }
 public SystemOfEquation(MMatrix CoefficientMatrix, Vector b)
 {
     this.CoefficientMatrix = CoefficientMatrix.Clone();
     this.b = b.Clone();
 }