示例#1
0
文件: SqrtTest.cs 项目: sys27/xFunc
        public void ComplexExecuteTest()
        {
            var complex = new Complex(5, 3);
            var exp = new Sqrt(new ComplexNumber(complex));

            Assert.Equal(Complex.Sqrt(complex), exp.Execute());
        }
示例#2
0
文件: SqrtTest.cs 项目: sys27/xFunc
        public void NegativeComplexNumberExecuteTest()
        {
            var complex = new Complex(-25, 13);
            var exp = new Sqrt(new ComplexNumber(complex));

            Assert.Equal(Complex.Sqrt(complex), exp.Execute());
        }
示例#3
0
文件: SqrtTest.cs 项目: sys27/xFunc
        public void NegativeNumberExecuteTest2()
        {
            var exp = new Sqrt(new Number(-1));

            Assert.Equal(new Complex(0, 1), exp.Execute());
        }
示例#4
0
文件: SqrtTest.cs 项目: sys27/xFunc
        public void ExecuteTest1()
        {
            var exp = new Sqrt(new Number(4));

            Assert.Equal(Math.Sqrt(4), exp.Execute());
        }
示例#5
0
        public void SqrtDerivativeTest2()
        {
            Number num = new Number(2);
            Variable x = new Variable("x");
            Mul mul = new Mul(num, x);

            IExpression exp = new Sqrt(mul);
            IExpression deriv = Differentiate(exp);

            Assert.AreEqual("(2 * 1) / (2 * sqrt(2 * x))", deriv.ToString());

            num.Value = 3;
            Assert.AreEqual("sqrt(3 * x)", exp.ToString());
            Assert.AreEqual("(2 * 1) / (2 * sqrt(2 * x))", deriv.ToString());
        }
示例#6
0
        public void SqrtDerivativeTest1()
        {
            var exp = new Sqrt(new Mul(new Number(2), new Variable("x")));
            var deriv = Differentiate(exp);

            Assert.Equal("(2 * 1) / (2 * sqrt(2 * x))", deriv.ToString());
        }
示例#7
0
 public void SqrtPartialDerivativeTest1()
 {
     // sqrt(2xy)
     var exp = new Sqrt(new Mul(new Mul(new Number(2), new Variable("x")), new Variable("y")));
     var deriv = Differentiate(exp);
     Assert.Equal("(2 * 1 * y) / (2 * sqrt(2 * x * y))", deriv.ToString());
 }
示例#8
0
        /// <summary>
        /// Differentiates the specified expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="variable">The variable.</param>
        /// <returns>Returns the derivative.</returns>
        protected virtual IExpression Arcsec(Arcsec expression, Variable variable)
        {
            var abs = new Abs(expression.Argument.Clone());
            var sqr = new Pow(expression.Argument.Clone(), new Number(2));
            var sub = new Sub(sqr, new Number(1));
            var sqrt = new Sqrt(sub);
            var mul = new Mul(abs, sqrt);
            var div = new Div(_Differentiate(expression.Argument.Clone(), variable), mul);

            return div;
        }
示例#9
0
        /// <summary>
        /// Differentiates the specified expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="variable">The variable.</param>
        /// <returns>Returns the derivative.</returns>
        protected virtual IExpression Arcsin(Arcsin expression, Variable variable)
        {
            var involution = new Pow(expression.Argument.Clone(), new Number(2));
            var sub = new Sub(new Number(1), involution);
            var sqrt = new Sqrt(sub);
            var division = new Div(_Differentiate(expression.Argument.Clone(), variable), sqrt);

            return division;
        }
示例#10
0
        /// <summary>
        /// Differentiates the specified expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="variable">The variable.</param>
        /// <returns>Returns the derivative.</returns>
        protected virtual IExpression Arcosh(Arcosh expression, Variable variable)
        {
            var sqr = new Pow(expression.Argument.Clone(), new Number(2));
            var sub = new Sub(sqr, new Number(1));
            var sqrt = new Sqrt(sub);
            var div = new Div(_Differentiate(expression.Argument.Clone(), variable), sqrt);

            return div;
        }
示例#11
0
        /// <summary>
        /// Differentiates the specified expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="variable">The variable.</param>
        /// <returns>Returns the derivative.</returns>
        protected virtual IExpression Arcsch(Arcsch expression, Variable variable)
        {
            var inv = new Pow(expression.Argument.Clone(), new Number(2));
            var add = new Add(new Number(1), inv);
            var sqrt = new Sqrt(add);
            var abs = new Abs(expression.Argument.Clone());
            var mul = new Mul(abs, sqrt);
            var div = new Div(_Differentiate(expression.Argument.Clone(), variable), mul);
            var unMinus = new UnaryMinus(div);

            return unMinus;
        }
示例#12
0
        /// <summary>
        /// Differentiates the specified expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="variable">The variable.</param>
        /// <returns>Returns the derivative.</returns>
        protected virtual IExpression Arccos(Arccos expression, Variable variable)
        {
            var pow = new Pow(expression.Argument.Clone(), new Number(2));
            var sub = new Sub(new Number(1), pow);
            var sqrt = new Sqrt(sub);
            var division = new Div(_Differentiate(expression.Argument.Clone(), variable), sqrt);
            var unMinus = new UnaryMinus(division);

            return unMinus;
        }
示例#13
0
 public void SqrtPartialDerivativeTest2()
 {
     IExpression exp = new Sqrt(new Variable("y"));
     IExpression deriv = Differentiate(exp);
     Assert.AreEqual("0", deriv.ToString());
 }
示例#14
0
 public void SqrtPartialDerivativeTest1()
 {
     // sqrt(2xy)
     IExpression exp = new Sqrt(new Mul(new Mul(new Number(2), new Variable("x")), new Variable("y")));
     IExpression deriv = Differentiate(exp);
     Assert.AreEqual("((2 * 1) * y) / (2 * sqrt((2 * x) * y))", deriv.ToString());
 }
示例#15
0
        public void CalculateTest()
        {
            IExpression exp = new Sqrt(new Number(4));

            Assert.AreEqual(Math.Sqrt(4), exp.Calculate());
        }
示例#16
0
        /// <summary>
        /// Differentiates the specified expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="variable">The variable.</param>
        /// <returns>Returns the derivative.</returns>
        protected virtual IExpression Arsech(Arsech expression, Variable variable)
        {
            var inv = new Pow(expression.Argument.Clone(), new Number(2));
            var sub = new Sub(new Number(1), inv);
            var sqrt = new Sqrt(sub);
            var mul = new Mul(expression.Argument.Clone(), sqrt);
            var div = new Div(_Differentiate(expression.Argument.Clone(), variable), mul);
            var unMinus = new UnaryMinus(div);

            return unMinus;
        }
示例#17
0
        public void NegativeNumberCalculateTest()
        {
            var exp = new Sqrt(new Number(-25));

            Assert.AreEqual(double.NaN, exp.Calculate());
        }
示例#18
0
        /// <summary>
        /// Differentiates the specified expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="variable">The variable.</param>
        /// <returns>Returns the derivative.</returns>
        protected virtual IExpression Arsinh(Arsinh expression, Variable variable)
        {
            var sqr = new Pow(expression.Argument.Clone(), new Number(2));
            var add = new Add(sqr, new Number(1));
            var sqrt = new Sqrt(add);
            var div = new Div(_Differentiate(expression.Argument.Clone(), variable), sqrt);

            return div;
        }
示例#19
0
        public void SqrtDerivativeTest2()
        {
            var num = new Number(2);
            var x = new Variable("x");
            var mul = new Mul(num, x);

            var exp = new Sqrt(mul);
            var deriv = Differentiate(exp);

            Assert.Equal("(2 * 1) / (2 * sqrt(2 * x))", deriv.ToString());

            num.Value = 3;
            Assert.Equal("sqrt(3 * x)", exp.ToString());
            Assert.Equal("(2 * 1) / (2 * sqrt(2 * x))", deriv.ToString());
        }
示例#20
0
        /// <summary>
        /// Differentiates the specified expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="variable">The variable.</param>
        /// <returns>Returns the derivative.</returns>
        protected virtual IExpression Sqrt(Sqrt expression, Variable variable)
        {
            var mul = new Mul(new Number(2), expression.Clone());
            var div = new Div(_Differentiate(expression.Argument.Clone(), variable), mul);

            return div;
        }
示例#21
0
 public void SqrtPartialDerivativeTest2()
 {
     var exp = new Sqrt(new Variable("y"));
     var deriv = Differentiate(exp);
     Assert.Equal("0", deriv.ToString());
 }
示例#22
0
        /// <summary>
        /// Creates an expression object from <see cref="FunctionToken"/>.
        /// </summary>
        /// <param name="token">The function token.</param>
        /// <returns>An expression.</returns>
        protected virtual IExpression CreateFunction(FunctionToken token)
        {
            IExpression exp;

            switch (token.Function)
            {
                case Functions.Add:
                    exp = new Add(); break;
                case Functions.Sub:
                    exp = new Sub(); break;
                case Functions.Mul:
                    exp = new Mul(); break;
                case Functions.Div:
                    exp = new Div(); break;
                case Functions.Pow:
                    exp = new Pow(); break;
                case Functions.Absolute:
                    exp = new Abs(); break;
                case Functions.Sine:
                    exp = new Sin(); break;
                case Functions.Cosine:
                    exp = new Cos(); break;
                case Functions.Tangent:
                    exp = new Tan(); break;
                case Functions.Cotangent:
                    exp = new Cot(); break;
                case Functions.Secant:
                    exp = new Sec(); break;
                case Functions.Cosecant:
                    exp = new Csc(); break;
                case Functions.Arcsine:
                    exp = new Arcsin(); break;
                case Functions.Arccosine:
                    exp = new Arccos(); break;
                case Functions.Arctangent:
                    exp = new Arctan(); break;
                case Functions.Arccotangent:
                    exp = new Arccot(); break;
                case Functions.Arcsecant:
                    exp = new Arcsec(); break;
                case Functions.Arccosecant:
                    exp = new Arccsc(); break;
                case Functions.Sqrt:
                    exp = new Sqrt(); break;
                case Functions.Root:
                    exp = new Root(); break;
                case Functions.Ln:
                    exp = new Ln(); break;
                case Functions.Lg:
                    exp = new Lg(); break;
                case Functions.Lb:
                    exp = new Lb(); break;
                case Functions.Log:
                    exp = new Log(); break;
                case Functions.Sineh:
                    exp = new Sinh(); break;
                case Functions.Cosineh:
                    exp = new Cosh(); break;
                case Functions.Tangenth:
                    exp = new Tanh(); break;
                case Functions.Cotangenth:
                    exp = new Coth(); break;
                case Functions.Secanth:
                    exp = new Sech(); break;
                case Functions.Cosecanth:
                    exp = new Csch(); break;
                case Functions.Arsineh:
                    exp = new Arsinh(); break;
                case Functions.Arcosineh:
                    exp = new Arcosh(); break;
                case Functions.Artangenth:
                    exp = new Artanh(); break;
                case Functions.Arcotangenth:
                    exp = new Arcoth(); break;
                case Functions.Arsecanth:
                    exp = new Arsech(); break;
                case Functions.Arcosecanth:
                    exp = new Arcsch(); break;
                case Functions.Exp:
                    exp = new Exp(); break;
                case Functions.GCD:
                    exp = new GCD(); break;
                case Functions.LCM:
                    exp = new LCM(); break;
                case Functions.Factorial:
                    exp = new Fact(); break;
                case Functions.Sum:
                    exp = new Sum(); break;
                case Functions.Product:
                    exp = new Product(); break;
                case Functions.Round:
                    exp = new Round(); break;
                case Functions.Floor:
                    exp = new Floor(); break;
                case Functions.Ceil:
                    exp = new Ceil(); break;
                case Functions.Derivative:
                    exp = new Derivative(); break;
                case Functions.Simplify:
                    exp = new Simplify(); break;
                case Functions.Del:
                    exp = new Del(); break;
                case Functions.Define:
                    exp = new Define(); break;
                case Functions.Vector:
                    exp = new Vector(); break;
                case Functions.Matrix:
                    exp = new Matrix(); break;
                case Functions.Transpose:
                    exp = new Transpose(); break;
                case Functions.Determinant:
                    exp = new Determinant(); break;
                case Functions.Inverse:
                    exp = new Inverse(); break;
                case Functions.If:
                    exp = new If(); break;
                case Functions.For:
                    exp = new For(); break;
                case Functions.While:
                    exp = new While(); break;
                case Functions.Undefine:
                    exp = new Undefine(); break;
                case Functions.Im:
                    exp = new Im(); break;
                case Functions.Re:
                    exp = new Re(); break;
                case Functions.Phase:
                    exp = new Phase(); break;
                case Functions.Conjugate:
                    exp = new Conjugate(); break;
                case Functions.Reciprocal:
                    exp = new Reciprocal(); break;
                case Functions.Min:
                    exp = new Min(); break;
                case Functions.Max:
                    exp = new Max(); break;
                case Functions.Avg:
                    exp = new Avg(); break;
                case Functions.Count:
                    exp = new Count(); break;
                case Functions.Var:
                    exp = new Var(); break;
                case Functions.Varp:
                    exp = new Varp(); break;
                case Functions.Stdev:
                    exp = new Stdev(); break;
                case Functions.Stdevp:
                    exp = new Stdevp(); break;
                default:
                    exp = null; break;
            }

            var diff = exp as DifferentParametersExpression;
            if (diff != null)
                diff.ParametersCount = token.CountOfParams;

            return exp;
        }