Ejemplo n.º 1
0
        public static double [] PolynomialRegression(double[] X, double[] Y, int degree_of_a_polynomial)
        {
            var quantity = X.Length;

            double[][] A = Matrix.MatrixCreate(degree_of_a_polynomial, degree_of_a_polynomial);
            double[]   C = new double[degree_of_a_polynomial];
            for (int i = 1; i <= degree_of_a_polynomial; i++)
            {
                for (int j = 1; j <= degree_of_a_polynomial; j++)
                {
                    double Sum = 0;
                    for (int r = 1; r <= quantity; r++)
                    {
                        Sum += 1.00 / quantity * Math.Pow(X[r - 1], i + j - 2);
                    }
                    A[i - 1][j - 1] = Sum;
                }
            }

            for (int j = 1; j <= degree_of_a_polynomial; j++)
            {
                double Sum = 0;
                for (int r = 1; r <= quantity; r++)
                {
                    Sum += 1.00 / quantity * Math.Pow(X[r - 1], j - 1) * Y[r - 1];
                }
                C[j - 1] = Sum;
            }

            var XX = CrautMethod.LU(A, C);


            return(XX);
        }
Ejemplo n.º 2
0
        public static double[] TranscendentalRegression(double[] X, double[] Y, Func <double, double>   [] functions)
        {
            var functionsLength = functions.Length;
            var quantity        = X.Length;

            double[][] A = Matrix.MatrixCreate(functionsLength, functionsLength);
            double[]   C = new double[functionsLength];
            for (int i = 1; i <= functionsLength; i++)
            {
                for (int j = 1; j <= functionsLength; j++)
                {
                    double Sum = 0;
                    for (int r = 1; r <= quantity; r++)
                    {
                        //!!!
                        Sum += 1.00 / quantity * functions[i - 1](X[r - 1]) * functions[j - 1](X[r - 1]);
                    }
                    A[i - 1][j - 1] = Sum;
                }
            }

            for (int j = 1; j <= functionsLength; j++)
            {
                double Sum = 0;
                for (int r = 1; r <= quantity; r++)
                {
                    Sum += 1.00 / quantity * functions[j - 1](X[r - 1]) * Y[r - 1];
                }
                C[j - 1] = Sum;
            }

            var XX = CrautMethod.LU(A, C);


            return(XX);
        }