示例#1
0
        public List <Point> QuadraticMethod(double h)
        {
            CheckStep(h);
            if (points.Count < 3)
            {
                throw new Exception("Количество точек в заданном интервале недостаточно.");
            }

            List <Point> resultPoints = new List <Point>();

            for (int k = 0; k < points.Count - 2; k++)
            {
                double[,] valuesA = new double[3, 3];
                double[,] valuesB = new double[3, 1];

                for (int i = 0; i < valuesA.GetLength(0); i++)
                {
                    for (int j = 0; j < valuesA.GetLength(1); j++)
                    {
                        valuesA[i, j] = Math.Pow(points[k + i].X, 2 - j);
                    }
                    valuesB[i, 0] = points[k + i].Y;
                }
                Matrix A = new Matrix(valuesA);
                Matrix B = new Matrix(valuesB);

                SystemEquations systemEquations = new SystemEquations(A, B);
                double[,] solution = systemEquations.MatrixMethod();

                double a, b, c;
                a = solution[0, 0];
                b = solution[1, 0];
                c = solution[2, 0];

                if (k == 0)
                {
                    for (double x = points[0].X; x < points[1].X; x += h)
                    {
                        double newX = x;
                        double newY = a * Math.Pow(newX, 2) + b * newX + c;
                        resultPoints.Add(new Point(newX, newY));
                    }
                }
                for (double x = points[k + 1].X; x <= points[k + 2].X; x += h)
                {
                    double newX = x;
                    double newY = a * Math.Pow(newX, 2) + b * newX + c;
                    resultPoints.Add(new Point(newX, newY));
                }
            }
            return(resultPoints);
        }
示例#2
0
        public List <Point> SplineMethod(double step)
        {
            CheckStep(step);

            double[,] A = new double[points.Count, points.Count];
            double[,] B = new double[points.Count, 1];
            double h = points[1].X - points[0].X;

            for (int i = 0; i < A.GetLength(0); i++)
            {
                for (int j = 0; j < A.GetLength(1); j++)
                {
                    if (i == j)
                    {
                        A[i, j] = 4 * h / 3;
                    }
                    else if (i == j + 1 || i == j - 1)
                    {
                        A[i, j] = h / 3;
                    }
                }
            }

            for (int i = 1; i < B.GetLength(0) - 1; i++)
            {
                B[i, 0] = (points[i + 1].Y - 2 * points[i].Y + points[i - 1].Y) / h;
            }

            SystemEquations equations = new SystemEquations(new Matrix(A), new Matrix(B));

            double[,] C = equations.GausGordanMethod();

            List <Point> resultPoints = new List <Point>();

            for (int k = 1; k < points.Count - 1; k++)
            {
                for (double x = points[k].X; x <= points[k + 1].X; x += step)
                {
                    double a = points[k - 1].Y;
                    double b = ((points[k].Y - points[k - 1].Y) / h) - (h / 3) * (2 * C[k, 0] + C[k + 1, 0]);
                    double d = (C[k + 1, 0] - C[k, 0]) / (3 * h);
                    double c = C[k, 0];
                    double y = a + b * (x - points[k].X) + c * Math.Pow(x - points[k].X, 2) + d * Math.Pow(x - points[k].X, 3);
                    resultPoints.Add(new Point(x - h, y));
                }
            }
            return(resultPoints);
        }
示例#3
0
        public DifferentiationResult MethodUndefinedCoefficients(int degreeAccuracy)
        {
            if (degreeAccuracy >= points.Count)
            {
                throw new Exception("Порядок точности не может быть больше кол-ва точек.");
            }

            double[,] matrixC         = new double[points.Count, points.Count];
            double[,] matrixFreeTerms = new double[points.Count, 1];

            for (int i = 0; i < matrixC.GetLength(0); i++)
            {
                for (int j = 0; j < matrixC.GetLength(1); j++)
                {
                    //Заполнение матрицы коэффицентов C
                    if ((j == 0) && (i != 0))
                    {
                        matrixC[i, j] = 0;
                    }
                    else if (i == 0)
                    {
                        matrixC[i, j] = 1;
                    }
                    else
                    {
                        matrixC[i, j] = Math.Pow(j * step, i);
                    }

                    //Заполнение матрицы свободных членов
                    if (j == 0)
                    {
                        if (i == 0)
                        {
                            matrixFreeTerms[i, j] = i;
                        }
                        else if (i == 1)
                        {
                            matrixFreeTerms[i, j] = i;
                        }
                        else
                        {
                            matrixFreeTerms[i, j] = Math.Pow(step, i - 1) * i;
                        }
                    }
                }
            }

            //Решение СЛАУ
            SystemEquations equations = new SystemEquations(new Matrix(matrixC), new Matrix(matrixFreeTerms));

            double[,] res = equations.GausGordanMethod();

            //Вычисление производных
            List <Point> derivativePoints = new List <Point>();

            for (int i = 1; i < res.GetLength(0) - degreeAccuracy; i++)
            {
                double derivate = 0;
                for (int j = 0; j <= degreeAccuracy; j++)
                {
                    derivate += res[j, 0] * points[i - 1 + j].Y;
                }
                derivativePoints.Add(new Point(points[i].X, derivate));
            }

            return(new DifferentiationResult(derivativePoints.ToArray(), AbsoluteDeviation(derivativePoints), StandartDeviation(derivativePoints)));
        }