Example #1
0
        public Min(Expression left, Expression right)
        {
            Symbol = "min";
            Left   = left;
            Right  = right;
            _expr  = 0.5 * (Left + Right - Sym.Abs(Left - Right));

            EvalFunctional = (c) => Math.Min(Left.Eval(c), Right.Eval(c));
            DiffFunctional = (c, var) =>
            {
                // var diffExpr = _expr.SymbolicDiff(var);
                //  return diffExpr.Eval(c);

                //  var u = Left.Diff(c, var);
                // var v = Right.Diff(c, var);

                if (Left.Eval(c) < Right.Eval(c))
                {
                    return(Left.Diff(c, var));
                }
                else if (Left.Eval(c) > Right.Eval(c))
                {
                    return(Right.Diff(c, var));
                }
                else
                {
                    return(0.5 * (Left.Diff(c, var) + Right.Diff(c, var)));
                }
            };
        }
Example #2
0
        public override Expression SymbolicDiff(Variable var)
        {
            var u    = Parameter;
            var dudx = Parameter.SymbolicDiff(var);

            return(Sym.Cosh(u) * dudx);
        }
Example #3
0
        public Max(Expression left, Expression right)
        {
            Symbol         = "max";
            Left           = left;
            Right          = right;
            _expr          = 0.5 * (Left + Right + Sym.Abs(Left - Right));
            EvalFunctional = (c) => Math.Max(Left.Eval(c), Right.Eval(c));
            DiffFunctional = (c, var) =>
            {
                // var u = Left.Diff(c, var);
                // var v = Right.Diff(c, var);

                if (Left.Eval(c) > Right.Eval(c))
                {
                    return(Left.Diff(c, var));
                }
                else if (Left.Eval(c) < Right.Eval(c))
                {
                    return(Right.Diff(c, var));
                }
                else
                {
                    return(0.5 * (Left.Diff(c, var) + Right.Diff(c, var)));
                }


                /* if (Left.Eval(c) > Right.Eval(c))
                 *   return Left.Diff(c, var);
                 * else
                 *   return Right.Diff(c, var);*/
            };
        }
Example #4
0
        public override Expression SymbolicDiff(Variable var)
        {
            var u    = Left;
            var v    = Right;
            var dudx = Left.SymbolicDiff(var);
            var dvdx = Right.SymbolicDiff(var);

            return((v * dudx - u * dvdx) / Sym.Pow(v, 2));
        }
Example #5
0
        public override Expression SymbolicDiff(Variable var)
        {
            var u    = Left;
            var v    = Right;
            var dudx = Left.SymbolicDiff(var);
            var dvdx = Right.SymbolicDiff(var);

            return(v * Sym.Pow(u, v - 1) * dudx + Sym.Pow(u, v) * Sym.Ln(u) * dvdx);
        }
Example #6
0
        public SmoothMin(Expression left, Expression right, double k = 10)
        {
            Symbol = "smin";
            Left   = left;
            Right  = right;
            //_expr = 0.5 * (Left + Right + Sym.Abs(Left - Right));
            _expr = Sym.Ln(Sym.Exp(-k * left) + Sym.Exp(-k * right)) / -k;

            EvalFunctional = (c) => Math.Min(Left.Eval(c), Right.Eval(c));
            DiffFunctional = (c, var) => _expr.Diff(c, var);
        }
Example #7
0
 public override Expression SymbolicDiff(Variable var)
 {
     return(Sym.Sqrt(Sym.Pow(Child, 2) + 1e-12).SymbolicDiff(var));
 }