using System; namespace Science.Mathematics.VectorCalculus { public class IteratedPartialDerivative { private Function.ToLastType dela; private Function.ToLastType delb; private Function.ToLastType delc; private Function.ToLastType del; private int howMany; public IteratedPartialDerivative(Function.ToLastType func, double[] at, int howManyUpto4) { howMany = howManyUpto4; dela = func; this.at = at; } public void Compute() { switch(howMany) { case 2: { del = new Function.ToLastType(FirstDerivative); PartialDerivative obj = new PartialDerivative(del, at); obj.WithRespectTo = comps; obj.Compute(); result = obj.Result; break; } case 3: { del = new Function.ToLastType(SecondDerivative); PartialDerivative obj = new PartialDerivative(del, at); obj.WithRespectTo = compt; obj.Compute(); result = obj.Result; break; } case 4: { del = new Function.ToLastType(ThirdDerivative); PartialDerivative obj = new PartialDerivative(del, at); obj.WithRespectTo = compfo; obj.Compute(); result = obj.Result; break; } } } private double FirstDerivative(double[] x) { PartialDerivative obj = new PartialDerivative(dela, x); obj.WithRespectTo = compf; obj.Compute(); return obj.Result; } private double SecondDerivative(double[] x) { delb = new Function.ToLastType(FirstDerivative); PartialDerivative obj = new PartialDerivative(delb, x); obj.WithRespectTo = comps; obj.Compute(); return obj.Result; } private double ThirdDerivative(double[] x) { delc = new Function.ToLastType(SecondDerivative); PartialDerivative obj = new PartialDerivative(delc, x); obj.WithRespectTo = compt; obj.Compute(); return obj.Result; } private double[] at; public double[] At { set { at = value; } } private double result; public double Result { get { return result; } } private int compf; public int WithRespectToFirst { get { return compf; } set { compf = value; } } private int comps; public int WithRespectToSecond { get { return comps; } set { comps = value; } } private int compt; public int WithRespectToThird { get { return compt; } set { compt = value; } } private int compfo; public int WithRespectToFourth { get { return compfo; } set { compfo = value; } } } }