using System; namespace Science.Mathematics.VectorCalculus { public class TaylorFormula { private Function.ToLastType dela; public TaylorFormula(Function.ToLastType func, double[] at, double[] smallDeviation) { dela = func; this.at = at; this.h = smallDeviation; } public void Compute() { PartialDerivative obj = new PartialDerivative(dela,at); int n = at.Length; double sum = 0.0; sum += dela(at); for(int i = 0; i < n; i++) { obj.WithRespectTo = i; obj.Compute(); sum += obj.Result*h[i]; } IteratedPartialDerivative obj2 = new IteratedPartialDerivative(dela, at, 2); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { obj2.WithRespectToFirst = i; obj2.WithRespectToSecond = j; obj2.Compute(); sum += 1.0/ 2.0 * h[i] * obj2.Result * h[j]; } } result = sum; } private double result; private double[] at; private double[] h; public double[] At { set { at = value; } } public double[] SmallDeviation { set { h = value; } } public double Result { get { return result; } } } }