public static DualNumber Pow(DualNumber a, double b) { var pow = Math.Pow(a.Value, b); var frac = a.Diff / a.Value; return(new DualNumber(pow, b * pow * frac, b * pow * (a.Diff2 / a.Value + (b - 1) * frac * frac))); }
public static DualNumber Sin(DualNumber a) { var sin = Math.Sin(a.Value); var cos = Math.Cos(a.Value); return(new DualNumber(sin, cos * a.Diff, cos * a.Diff2 - sin * a.Diff * a.Diff)); }
public static DualNumber Cosh(DualNumber a) { var sin = Math.Sinh(a.Value); var cos = Math.Cosh(a.Value); return(new DualNumber(cos, sin * a.Diff, sin * a.Diff2 + cos * a.Diff * a.Diff)); }
public static DualNumber Atan(DualNumber a) { var tmp = 1 / (1 + a.Value * a.Value); var tmpDiff = a.Diff * tmp; return(new DualNumber(Math.Atan(a.Value), tmpDiff, a.Diff2 * tmp - 2 * a.Value * tmpDiff * tmpDiff)); }
public static DualNumber Acos(DualNumber a) { var tmp = 1 / Math.Sqrt(1 - a.Value * a.Value); var tmpDiff = a.Diff * tmp; return(new DualNumber(Math.Acos(a.Value), -tmpDiff, -(a.Diff2 + a.Value * tmpDiff * tmpDiff) * tmp)); }
public static DualNumber Pow(DualNumber a, DualNumber b) => Exp(b * Log(a));
public static DualNumber Log(DualNumber a) { return(new DualNumber(Math.Log(a.Value), a.Diff / a.Value, (a.Diff2 - a.Diff * a.Diff / a.Value) / a.Value)); }
public static DualNumber Exp(DualNumber a) { var exp = Math.Exp(a.Value); return(new DualNumber(exp, exp * a.Diff, exp * (a.Diff2 + a.Diff * a.Diff))); }
public static DualNumber Sqrt(DualNumber a) { var r = Math.Sqrt(a.Value); return(new DualNumber(r, 0.5 * a.Diff / r, 0.5 * a.Diff2 / r - 0.25 * a.Diff * a.Diff / (a.Value * r))); }
public static DualNumber Inverse(DualNumber a) { return(new DualNumber(1 / a.Value, -a.Diff / (a.Value * a.Value), (2 * a.Diff * a.Diff / a.Value - a.Diff2) / (a.Value * a.Value))); }
public static DualVector Vec(DualNumber x, DualNumber y, DualNumber z) => new DualVector(x, y, z);
public DualVector(Vector v) { X = v.X; Y = v.Y; Z = v.Z; }
public DualVector(DualNumber x, DualNumber y, DualNumber z) { X = x; Y = y; Z = z; }
public static DualNumber Abs(DualNumber a) => a.Value >= 0 ? a : -a;
public static DualNumber Tanh(DualNumber a) { var tan = Math.Tanh(a.Value); return(new DualNumber(tan, (1 - tan * tan) * a.Diff, (1 - tan * tan) * (a.Diff2 - 2 * tan * a.Diff * a.Diff))); }