public static void main(string[] args)
        {
            // declare the matrix
            DMatrix3x3 a = new DMatrix3x3();
            DMatrix3x3 b = new DMatrix3x3();

            // Can assign values the usual way
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    a.set(i, j, i + j + 1);
                }
            }

            // Direct manipulation of each value is the fastest way to assign/read values
            a.a11 = 12;
            a.a23 = 64;

            // can print the usual way too
            a.print();

            // most of the standard operations are support
            CommonOps_DDF3.transpose(a, b);
            b.print();

            Console.WriteLine("Determinant = " + CommonOps_DDF3.det(a));

            // matrix-vector operations are also supported
            // Constructors for vectors and matrices can be used to initialize its value
            DMatrix3 v      = new DMatrix3(1, 2, 3);
            DMatrix3 result = new DMatrix3();

            CommonOps_DDF3.mult(a, v, result);

            // Conversion into DMatrixRMaj can also be done
            DMatrixRMaj dm = ConvertDMatrixStruct.convert(a, null);

            dm.print();

            // This can be useful if you need do more advanced operations
            SimpleMatrix <DMatrixRMaj> sv = SimpleMatrix <DMatrixRMaj> .wrap(dm).svd().getV() as SimpleMatrix <DMatrixRMaj>;

            // can then convert it back into a fixed matrix
            DMatrix3x3 fv = ConvertDMatrixStruct.convert(sv.getDDRM(), (DMatrix3x3)null);

            Console.WriteLine("Original simple matrix and converted fixed matrix");
            sv.print();
            fv.print();
        }
Пример #2
0
        public static void csv()
        {
            DMatrixRMaj A = new DMatrixRMaj(2, 3, true, new double[] { 1, 2, 3, 4, 5, 6 });

            try
            {
                MatrixIO.saveCSV(A, "matrix_file.csv");
                DMatrixRMaj B = (DMatrixRMaj)MatrixIO.loadCSV("matrix_file.csv");
                B.print();
            }
            catch (IOException e)
            {
                throw new InvalidOperationException(e.Message, e);
            }
        }
Пример #3
0
        public static void serializedBinary()
        {
            DMatrixRMaj A = new DMatrixRMaj(2, 3, true, new double[] { 1, 2, 3, 4, 5, 6 });

            try
            {
                MatrixIO.saveBin(A, "matrix_file.data");
                DMatrixRMaj B = MatrixIO.loadBin <DMatrixRMaj>("matrix_file.data");
                B.print();
            }
            catch (IOException e)
            {
                throw new InvalidOperationException(e.Message, e);
            }
        }
Пример #4
0
        private void performImplicitDoubleStep(int x1, int x2,
                                               double b11, double b21, double b31)
        {
            if (!bulgeDoubleStepQn(x1, b11, b21, b31, 0, false))
            {
                return;
            }

            // get rid of the bump
            if (Q != null)
            {
                QrHelperFunctions_DDRM.rank1UpdateMultR(Q, u.data, gamma, 0, x1, x1 + 3, _temp.data);
                if (checkOrthogonal && !MatrixFeatures_DDRM.isOrthogonal(Q, UtilEjml.TEST_F64))
                {
                    u.print();

                    Q.print();
                    throw new InvalidOperationException("Bad");
                }
            }

            if (printHumps)
            {
                Console.WriteLine("Applied first Q matrix, it should be humped now. A = ");
                A.print("%12.3e");
                Console.WriteLine("Pushing the hump off the matrix.");
            }

            // perform double steps
            for (int i = x1; i < x2 - 2; i++)
            {
                if (bulgeDoubleStepQn(i) && Q != null)
                {
                    QrHelperFunctions_DDRM.rank1UpdateMultR(Q, u.data, gamma, 0, i + 1, i + 4, _temp.data);
                    if (checkOrthogonal && !MatrixFeatures_DDRM.isOrthogonal(Q, UtilEjml.TEST_F64))
                    {
                        throw new InvalidOperationException("Bad");
                    }
                }

                if (printHumps)
                {
                    Console.WriteLine("i = " + i + " A = ");
                    A.print("%12.3e");
                }
            }
            if (printHumps)
            {
                Console.WriteLine("removing last bump");
            }
            // the last one has to be a single step
            if (x2 - 2 >= 0 && bulgeSingleStepQn(x2 - 2) && Q != null)
            {
                QrHelperFunctions_DDRM.rank1UpdateMultR(Q, u.data, gamma, 0, x2 - 1, x2 + 1, _temp.data);
                if (checkOrthogonal && !MatrixFeatures_DDRM.isOrthogonal(Q, UtilEjml.TEST_F64))
                {
                    throw new InvalidOperationException("Bad");
                }
            }
            if (printHumps)
            {
                Console.WriteLine(" A = ");
                A.print("%12.3e");
            }
//        A.print("%12.3e");

            if (checkHessenberg && !MatrixFeatures_DDRM.isUpperTriangle(A, 1, UtilEjml.TEST_F64))
            {
                A.print("%12.3e");
                throw new InvalidOperationException("Bad matrix");
            }
        }