コード例 #1
0
ファイル: CellArray.cs プロジェクト: pwdlugosz/Spectre
        public static CellArray Multiply(CellArray A, CellArray B)
        {
            if (!CellArray.IsMatrix(A) || !CellArray.IsMatrix(B))
            {
                throw new Exception("Both A and B must be matrixes");
            }

            int A_Rows = A.Count, B_Rows = B.Count;
            int A_Cols = CellArray.ColumnCount(A), B_Cols = CellArray.ColumnCount(B);

            if (A_Cols != B_Rows)
            {
                throw new Exception(string.Format("Dimension mismatch A {0}:{1} B {2}:{3}", A_Rows, A_Cols, B_Rows, B_Cols));
            }

            CellArray C = CellArray.Matrix(A_Rows, B_Cols);

            // Main Loop //
            for (int i = 0; i < A_Rows; i++)
            {
                // Sub Loop One //
                for (int j = 0; j < B_Cols; j++)
                {
                    // Sub Loop Two //
                    for (int k = 0; k < A_Cols; k++)
                    {
                        C[i].valueARRAY[j] = (C[i].valueARRAY[j].IsNull ? A[i].valueARRAY[k] * B[k].valueARRAY[j] : A[i].valueARRAY[k] * B[k].valueARRAY[j] + C[i].valueARRAY[j]);
                    }
                }
            }

            // Return C //
            return(C);
        }
コード例 #2
0
ファイル: CellArray.cs プロジェクト: pwdlugosz/Spectre
        public static Cell Determinant(CellArray A)
        {
            if (!CellArray.IsMatrix(A))
            {
                throw new Exception("A must be a matrix");
            }

            int A_Rows = A.Count;
            int A_Cols = CellArray.ColumnCount(A);

            if (A_Rows != A_Cols)
            {
                throw new Exception(string.Format("Matrix must be square {0}:{1}", A_Rows, A_Cols));
            }

            LUDecomposition engine = new LUDecomposition(A);

            return(engine.det());
        }
コード例 #3
0
ファイル: CellArray.cs プロジェクト: pwdlugosz/Spectre
        public static CellArray Inverse(CellArray A)
        {
            if (!CellArray.IsMatrix(A))
            {
                throw new Exception("A must be a matrix");
            }

            int A_Rows = A.Count;
            int A_Cols = CellArray.ColumnCount(A);

            if (A_Rows != A_Cols)
            {
                throw new Exception(string.Format("Matrix must be square {0}:{1}", A_Rows, A_Cols));
            }

            LUDecomposition engine = new LUDecomposition(A);

            CellArray B = CellArray.Identity(A_Rows);

            return(engine.solve(B));
        }
コード例 #4
0
ファイル: CellArray.cs プロジェクト: pwdlugosz/Spectre
        public static CellArray Transpose(CellArray A)
        {
            int Rows    = A.Count;
            int Columns = 0;

            if (!CellArray.IsMatrix(A, out Columns))
            {
                throw new Exception("Cannot transpose a non-matrix");
            }

            CellArray B = CellArray.Matrix(Columns, Rows);

            for (int i = 0; i < Rows; i++)
            {
                for (int j = 0; j < Columns; j++)
                {
                    B[j].ARRAY[i] = A[i].ARRAY[j];
                }
            }
            return(B);
        }