C#, código Haishibei (37) - o código-fonte C# do "método Levinson" para resolver "equações de Tobelize"

usando Sistema;

namespace Zhou.CSharp.Algorithm
{     /// <summary>     /// Class LEquations para resolver equações lineares     /// Original Zhou Changfa     /// Adaptado para confusão profunda     /// </summary>     public static static class LEquations     {






        /// <summary>
        /// Método de Levinson para resolver as equações de Tobelitz
        /// </summary>
        /// <param name="mtxLECoef">matriz de coeficientes especificada</param>
        /// < param name="mtxLEConst" >matriz constante especificada</param>
        /// <param name="mtxResult">Objeto de referência da matriz, matriz de solução do sistema de equação de retorno</param>
        /// <return>tipo de bool, sistema de equação Se a solução foi bem-sucedida</ return>
        public static bool GetRootsetTlvs(Matrix mtxLECoef, Matrix mtxLEConst, Matrix mtxResult)
        {             int i, j, k;             double a, beta, q, c, h;

            // Número de incógnitas
            int n = mtxLECoef.GetNumColumns();

            // Inicializa o vetor de solução
            mtxResult.Init(n, 1);
            double[] x = mtxResult.GetData();

            // array constante
            double[] pDataConst = mtxLEConst.GetData();

            // Cria o array T
            double[] t = new double[n];

            // estrutura T pairs
            for (i = 0; i < n; ++i)
            {                 t[i] = mtxLECoef.GetElement(0, i)             ;

            // array temporário
            double[] s = new double[n];
            double[] y = new double[n];

            // Equações não Toberlitz, este método não pode ser usado para resolver
            a = t[0];
            if (Math.Abs(a) < float.Epsilon)
            {                 return false;             }

            // Método Levinson para resolver
            y[0] = 1.0;
            x[0] = pDataConst[0] / a;
            for (k = 1; k <= n - 1; k++)
            {                 beta = 0.0;                 q = 0.0;                 for (j = 0; j <= k - 1; j++)                 {                     beta = beta + y[j] * t[j + 1];                     q = q + x[j] * t[k - j];                 }






                if (Math.Abs(a) < float.Epsilon)
                {                     return false;                 }

                c = -beta/a;
                s[0] = c * y[k - 1];
                y[k] = y[k - 1];
                if (k != 1)
                {                     for (i = 1; i <= k - 1; i++)                     {                         s[i] = y[i - 1] + c * y[k - i - 1];                     }                 }




                a = a + c * beta;
                if (Math.Abs(a) < float.Epsilon)
                {                     return false;                 }

                h = (pDataConst[k] - q) / a;
                for (i = 0; i <= k - 1; i++)
                {                     x[i] = x[i] + h * s[i];                     y[i] = s[i];                 }


                x[k] = h * y[k];
            }

            retornar verdadeiro;
        }
}

}

 

Acho que você gosta

Origin blog.csdn.net/beijinghorn/article/details/131029621
Recomendado
Clasificación