private static BoundaryConditions GetBoundaryConditions_m_i() { Func fSecondDerivative = LagrangePolynomial.Calculate(X, Y) .FindDerivative() .FindDerivative() .Calculate; double freeElem_1 = 3.0 * (Y[1] - Y[0]) / H(0) - H(0) * fSecondDerivative(X[0]) / 2.0; double freeElem_2 = 3.0 * (Y[X.Length - 1] - Y[X.Length - 2]) / H(X.Length - 2) - H(X.Length - 2) * fSecondDerivative(X[X.Length - 2]) / 2.0; BoundaryConditions boundaryConditions = new BoundaryConditions() { first = new VectorRow(X.Length + 1), second = new VectorRow(X.Length + 1) }; boundaryConditions.first[0] = 2.0; boundaryConditions.first[1] = 1.0; boundaryConditions.first[X.Length] = freeElem_1; boundaryConditions.second[X.Length - 2] = 1.0; boundaryConditions.second[X.Length - 1] = 2.0; boundaryConditions.second[X.Length] = freeElem_2; return(boundaryConditions); }
private static LSystem BuildSystem(Matrix mainEquations, BoundaryConditions boundaryConditions) { if (boundaryConditions.first.Length != X.Length + 1 || boundaryConditions.second.Length != X.Length + 1 || mainEquations.Rows != X.Length - 2 || mainEquations.Columns != X.Length + 1) { throw new ArgumentException(); } SquareMatrix matrix = new SquareMatrix(X.Length); VectorColumn freeElems = new VectorColumn(X.Length); for (int row = 1; row < X.Length - 1; row++) { for (int column = 0; column < X.Length; column++) { matrix[row, column] = mainEquations[row - 1, column]; } freeElems[row] = mainEquations[row - 1, X.Length]; } for (int column = 0; column < X.Length; column++) { matrix[0, column] = boundaryConditions.first[column]; matrix[X.Length - 1, column] = boundaryConditions.second[column]; } freeElems[0] = boundaryConditions.first[X.Length]; freeElems[X.Length - 1] = boundaryConditions.second[X.Length]; return(new LSystem(matrix, freeElems)); }
private static BoundaryConditions GetBoundaryConditions_M_i() { BoundaryConditions boundaryConditions = new BoundaryConditions() { first = new VectorRow(X.Length + 1), second = new VectorRow(X.Length + 1) }; boundaryConditions.first[0] = 1.0; boundaryConditions.second[X.Length - 1] = 1.0; return(boundaryConditions); }
public static Spline Calculate_M_i(double[] x, double[] y) { if (x.Length != y.Length) { throw new ArgumentException("y", "Array of function's values must has same length as array of arguments."); } X = x; Y = y; Matrix mainEquations = PrepareEquations_M_i(); BoundaryConditions boundaryConditions = GetBoundaryConditions_M_i(); LSystem system = BuildSystem(mainEquations, boundaryConditions); VectorColumn solutions = Tridiagonal.Calculate(system); return(new Spline(BuildSpline_M_i(solutions), X)); }