Example #1
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);
        }
Example #2
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)));
        }