예제 #1
0
        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)));
        }
예제 #2
0
        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));
        }
예제 #3
0
        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));
        }
예제 #4
0
        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));
        }
예제 #5
0
        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));
        }
예제 #6
0
 public static DualNumber Pow(DualNumber a, DualNumber b) => Exp(b * Log(a));
예제 #7
0
 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));
 }
예제 #8
0
        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)));
        }
예제 #9
0
        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)));
        }
예제 #10
0
 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)));
 }
예제 #11
0
 public static DualVector Vec(DualNumber x, DualNumber y, DualNumber z) => new DualVector(x, y, z);
예제 #12
0
 public DualVector(Vector v)
 {
     X = v.X;
     Y = v.Y;
     Z = v.Z;
 }
예제 #13
0
 public DualVector(DualNumber x, DualNumber y, DualNumber z)
 {
     X = x;
     Y = y;
     Z = z;
 }
예제 #14
0
 public static DualNumber Abs(DualNumber a) => a.Value >= 0 ? a : -a;
예제 #15
0
        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)));
        }