Exemplo n.º 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)));
        }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 6
0
 public static DualNumber Pow(DualNumber a, DualNumber b) => Exp(b * Log(a));
Exemplo n.º 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));
 }
Exemplo n.º 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)));
        }
Exemplo n.º 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)));
        }
Exemplo n.º 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)));
 }
Exemplo n.º 11
0
 public static DualVector Vec(DualNumber x, DualNumber y, DualNumber z) => new DualVector(x, y, z);
Exemplo n.º 12
0
 public DualVector(Vector v)
 {
     X = v.X;
     Y = v.Y;
     Z = v.Z;
 }
Exemplo n.º 13
0
 public DualVector(DualNumber x, DualNumber y, DualNumber z)
 {
     X = x;
     Y = y;
     Z = z;
 }
Exemplo n.º 14
0
 public static DualNumber Abs(DualNumber a) => a.Value >= 0 ? a : -a;
Exemplo n.º 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)));
        }