using System; namespace Science.Mathematics.VectorCalculus { public class Divergence { private Function.ToLastType func; private double res = 0.0; private double[] at1; private int n; public Divergence(Function.ToLastType f, double[] x) { n = f(x).Length; func = f; at1 = x; } public double[] At { set { at1 = value; } } private int cp; public void Compute() { res = 0.0; Function.ToLastType part = new Function.ToLastType(comp); PartialDerivative obj; for (int j = 0; j < n; j++) { cp = j; obj = new PartialDerivative(part, at1); obj.WithRespectTo = j; obj.Compute(); res += obj.Result; } } private double comp(double[] x) { return func(x)[cp]; } public double Result { get { return res; } } } }