コード例 #1
0
ファイル: qMtrx.cs プロジェクト: wouldyougo/EMD
        /// <summary>
        /// вычисление R
        /// хз что это
        /// </summary>
        /// <param name="x"></param>
        /// <param name="Num_rs"></param>
        /// <returns></returns>
        public static TMatrix EvaluateR(TMatrix x, int Num_rs)
        {
            int i;
            double Val;
            double[] X_s;
            TMatrix Ret = new TMatrix(Num_rs, 1);

            if (x.GetRows() != 1)
                //throw E;
                throw new System.ApplicationException("неверные параметры вычислени¤ R");

            try
            {
                X_s = new double[x.GetCols()];
                for (i = 0; i < x.GetCols(); i++)
                    X_s[i] = x.GetElm(0, i);
                for (i = 0; i < Ret.GetRows(); i++)
                {
                    Val = GlobalMembersMtrx.eval_function(i, X_s, Num_rs, x.GetCols()); // ¬ычисл¤ем i-ю функцию
                    Ret.PutElm(i, 0, Val); // ‘ормируем Ret
                }
            }
            catch
            {
                //throw E;
                throw new System.ApplicationException();
            }
            X_s = null;
            return Ret;
        }
コード例 #2
0
ファイル: qMtrx.cs プロジェクト: wouldyougo/EMD
        //---------------------------------------------------------------------------
        /// <summary>
        /// вычисление матрицы якоби
        /// </summary>
        /// <param name="x">параметры вычислени¤ матрицы якоби</param>
        /// <param name="Num_rs">параметры вычислени¤ матрицы якоби</param>
        /// <param name="h">параметры вычислени¤ матрицы якоби</param>
        /// <returns></returns>
        public static TMatrix EvaluateJ(TMatrix x, int Num_rs, double h)
        {
            TMatrix Val_1 = new TMatrix();
            TMatrix Val_2 = new TMatrix();
            TMatrix Val = new TMatrix();

            if (x.GetRows() != 1)
                //throw E;
                throw new System.ApplicationException("неверные параметры вычислени¤ матрицы якоби");
            TMatrix Ret = new TMatrix(Num_rs, x.GetCols());
            TMatrix X_s = new TMatrix(1, x.GetCols());

            try
            {
                for (int i = 0; i < Ret.GetCols(); i++)
                {
                    for (int j = 0; j < X_s.GetCols(); j++)
                        X_s.PutElm(0, j, x.GetElm(0, j));
                    X_s.PutElm(0, i, x.GetElm(0, i) - h);
                    Val_1 = GlobalMembersMtrx.EvaluateR(X_s, Num_rs);
                    for (int j = 0; j < X_s.GetCols(); j++)
                        X_s.PutElm(0, j, x.GetElm(0, j));
                    X_s.PutElm(0, i, x.GetElm(0, i) + h);
                    Val_2 = GlobalMembersMtrx.EvaluateR(X_s, Num_rs);
                    Val = (1 / (2 * h)) * (Val_2 - Val_1);
                    for (int j = 0; j < Ret.GetRows(); j++)
                        Ret.PutElm(j, i, (double)Val.GetElm(j, 0));
                }
            }
            catch
            {
                //throw E;
                throw new System.ApplicationException();
            }
            return Ret;
        }
コード例 #3
0
ファイル: qMtrx.cs プロジェクト: wouldyougo/EMD
        //---------------------------------------------------------------------------
        //C++ TO C# CONVERTER NOTE: This 'CopyFrom' method was converted from the original C++ copy assignment operator:
        //ORIGINAL LINE: TMatrix& operator = (const TMatrix& M)
        public TMatrix CopyFrom(TMatrix M)
        {
            if (Data == null)
            {
                Rows = M.GetRows();
                Cols = M.GetCols();
                Data = new double[Rows][];
                for (int i = 0; i < Rows; i++)
                    Data[i] = new double[Cols];
            }
            else if (M.GetRows() != Rows || M.GetCols() != Cols)
            {
                for (int i = 0; i < Rows; i++)
                    Data[i] = null;
                Data = null;
                Rows = M.GetRows();
                Cols = M.GetCols();
                Data = new double[Rows][];
                for (int i = 0; i < Rows; i++)
                    Data[i] = new double[Cols];
            }

            for (int i = 0; i < Rows; i++)
                for (int j = 0; j < Cols; j++)
                    PutElm(i, j, M.GetElm(i, j));
            return this;
        }
コード例 #4
0
ファイル: qMtrx.cs プロジェクト: wouldyougo/EMD
        public static TMatrix operator ~(TMatrix A)
        {
            int k_step;
            bool Stop = false;
            double phi_k;
            double phi_k1;

            TMatrix A_plus = new TMatrix();
            TMatrix F_k = new TMatrix();
            TMatrix F_k1 = new TMatrix();
            TMatrix I = new TMatrix();
            TMatrix AtA = new TMatrix();

            TMatrix M = new TMatrix(A.GetCols(), A.GetRows());

            AtA = !M * M;
            //C++ TO C# CONVERTER WARNING: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created if it does not yet exist:
            //ORIGINAL LINE: F_k = AtA;
            F_k.CopyFrom(AtA);
            F_k.Make_I();
            //C++ TO C# CONVERTER WARNING: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created if it does not yet exist:
            //ORIGINAL LINE: I = AtA;
            I.CopyFrom(AtA);
            I.Make_I();

            //C++ TO C# CONVERTER WARNING: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created if it does not yet exist:
            //ORIGINAL LINE: F_k = I;
            F_k.CopyFrom(I);
            phi_k = AtA.Trace();
            k_step = 2;

            for (; ; )
            {
                F_k1 = (phi_k * I) - (AtA * F_k);
                phi_k1 = (AtA * F_k1).Trace() / k_step;

                if (Math.Abs(phi_k1) == 0)
                    Stop = true;
                if (k_step > M.GetRows())
                    Stop = true;
                if (k_step > M.GetCols())
                    Stop = true;
                if (Stop == true)
                    break;

                //C++ TO C# CONVERTER WARNING: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created if it does not yet exist:
                //ORIGINAL LINE: F_k = F_k1;
                F_k.CopyFrom(F_k1);
                phi_k = phi_k1;
                k_step++;
            }

            TMatrix No_rang = new TMatrix(1, 1);
            No_rang.PutElm(0, 0, (double)10E+200);
            //C++ TO C# CONVERTER WARNING: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created if it does not yet exist:
            //ORIGINAL LINE: A_plus = No_rang;
            A_plus.CopyFrom(No_rang);
            if (phi_k == 0)
                return A_plus;
            A_plus = (1 / phi_k) * F_k * (!M);
            return A_plus;
        }
コード例 #5
0
ファイル: qMtrx.cs プロジェクト: wouldyougo/EMD
 //---------------------------------------------------------------------------
 public static TMatrix operator -(TMatrix A, TMatrix B)
 {
     TMatrix M = new TMatrix();
     if (A.GetRows() == B.GetRows() && A.GetCols() == B.GetCols())
     {
         //C++ TO C# CONVERTER WARNING: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created if it does not yet exist:
         //ORIGINAL LINE: M = A;
         M.CopyFrom(A);
         for (int i = 0; i < M.GetRows(); i++)
             for (int j = 0; j < M.GetCols(); j++)
                 M.PutElm(i, j, A.GetElm(i, j) - B.GetElm(i, j));
     }
     else
         //throw E;
         throw new System.ApplicationException("попытка вычитани¤ матриц разного размера");
     return M;
 }
コード例 #6
0
ファイル: qMtrx.cs プロジェクト: wouldyougo/EMD
 //---------------------------------------------------------------------------
 public static TMatrix operator *(double m, TMatrix A)
 {
     TMatrix M = new TMatrix(A.GetRows(), A.GetCols());
     for (int i = 0; i < M.GetRows(); i++)
         for (int j = 0; j < M.GetCols(); j++)
             M.PutElm(i, j, m * A.GetElm(i, j));
     return M;
 }
コード例 #7
0
ファイル: qMtrx.cs プロジェクト: wouldyougo/EMD
        //---------------------------------------------------------------------------
        public static TMatrix operator *(TMatrix A, TMatrix B)
        {
            double sum;
            TMatrix M = new TMatrix(A.GetRows(), B.GetCols());

            if (A.GetCols() == B.GetRows())
            {
                for (int i = 0; i < M.GetRows(); i++)
                    for (int j = 0; j < M.GetCols(); j++)
                    {
                        sum = 0.0;
                        for (int k = 0; k < A.GetCols(); k++)
                            sum += A.GetElm(i, k) * B.GetElm(k, j);
                        M.PutElm(i, j, sum);
                    }
            }
            else
                //throw E;
                throw new System.ApplicationException("неверные размеры умножаемых матриц");
            return M;
        }
コード例 #8
0
ファイル: qMtrx.cs プロジェクト: wouldyougo/EMD
 //---------------------------------------------------------------------------
 public TMatrix(ref TMatrix M)
 {
     Cols = M.GetCols();
     Rows = M.GetRows();
     Data = new double[Rows][];
     for (int i = 0; i < Rows; i++)
         Data[i] = new double[Cols];
     for (int i = 0; i < Rows; i++)
         for (int j = 0; j < Cols; j++)
             Data[i][j] = M.GetElm(i, j);
 }
コード例 #9
0
ファイル: qMatrix.cs プロジェクト: wouldyougo/EMD
        //---------------------------------------------------------------------------
        public List<List<double>> clcPIMatrix(List<List<double>> aMtrx)
        {
            int Row = 0;
            int Col = 0;
            Row = aMtrx.Count;
            if (Row != 0)
            {
                Col = aMtrx[0].Count;
            }
            TMatrix A = new TMatrix(Row, Col);
            for (int i = 0; i < Row; i++)
            {
                for (int j = 0; j < Col; j++)
                {
                    //         double tmp = 0;
                    //         tmp = aMtrx[i][j];
                    //         A.PutElm(i,j, tmp );
                    A.PutElm(i, j, aMtrx[i][j]);
                }
            }
            A = ~A;
            //List<List<double> > tVctr = new List<List<double> >(Col, new List<double>(Row));
            List<List<double>> tVctr = new List<List<double>>(Col);
            for (int i = 0; i < Col; i++)
                tVctr[i] = new List<double>(Row);

            for (int j = 0; j < Col; j++)
            {
                for (int i = 0; i < Row; i++)
                {
                    //         double tmp = 0;
                    //         tmp = A.GetElm(j,i);
                    //         tVctr[j][i] = tmp;
                    tVctr[j][i] = A.GetElm(j, i);
                }
            }
            return tVctr;
        }