private Node GenerateMaclaurinSeriesPolynomial(double x, int order) { if (order == 0) { return(this); } if (order == 1) { return(new PlusSign(new MultiplicationSign(ReturnDerivative(x), new VariableNode()), this)); } VariableNode variableNode = new VariableNode(); NaturalNumberNode orderNode = new NaturalNumberNode(order); CaretSign caretSign = new CaretSign(variableNode, orderNode); Node f0 = ReturnDerivative(x); for (int i = 1; i < order; i++) { f0 = f0.ReturnDerivative(x); } MultiplicationSign multiplicationSign = new MultiplicationSign(caretSign, new RationalNumberNode(f0.Calculate(0))); FactorialFunction factorialFunction = new FactorialFunction(orderNode); DivisionSign divisionSign = new DivisionSign(multiplicationSign, factorialFunction); return(new PlusSign(divisionSign, ReturnMaclaurinSeriesPolynomial(x, order - 1))); }
public double ReturnMaclaurinSeries(double x, int order) { if (order == 0) { return(Calculate(0)); } if (order == 1) { return(ReturnDerivative(x).Calculate(0) * x + Calculate(0)); } VariableNode variableNode = new VariableNode(); NaturalNumberNode orderNode = new NaturalNumberNode(order); CaretSign caretSign = new CaretSign(variableNode, orderNode); Node f0 = ReturnDerivative(x); for (int i = 1; i < order; i++) { f0 = f0.ReturnDerivative(x); } MultiplicationSign multiplicationSign = new MultiplicationSign(caretSign, new RationalNumberNode(f0.Calculate(0))); FactorialFunction factorialFunction = new FactorialFunction(orderNode); DivisionSign divisionSign = new DivisionSign(multiplicationSign, factorialFunction); return(divisionSign.Calculate(x) + ReturnMaclaurinSeries(x, order - 1)); }
public double ReturnNewtonMaclaurinSeries(double x, int order) { if (order == 0) { return(Calculate(0)); } if (order == 1) { return(ReturnNewtonDerivative(0) * x + Calculate(0)); } VariableNode variableNode = new VariableNode(); NaturalNumberNode orderNode = new NaturalNumberNode(order); CaretSign caretSign = new CaretSign(variableNode, orderNode); RationalNumberNode f0 = new RationalNumberNode(CalculatePolynomialDerivative(0, order)); MultiplicationSign multiplicationSign = new MultiplicationSign(caretSign, f0); FactorialFunction factorialFunction = new FactorialFunction(orderNode); DivisionSign divisionSign = new DivisionSign(multiplicationSign, factorialFunction); return(divisionSign.Calculate(x) + ReturnNewtonMaclaurinSeries(x, order - 1)); }