コード例 #1
0
        public void TestSecant()
        {
            Entity func    = "sec(2x)";
            var    derived = func.Differentiate("x");

            Assert.Equal(2 * MathS.Sec("2x") * MathS.Tan("2x"), derived.Simplify());
        }
コード例 #2
0
        public void TestInnerComplex()
        {
            var expr     = MathS.FromString("cotan(x + tan(x))");
            var expected = MathS.Cotan(x + MathS.Tan(x));

            Assert.IsTrue(expr == expected);
        }
コード例 #3
0
        public void TestComplex()
        {
            var expr     = MathS.FromString("ln(x) + sqrt(x) + tan(x) + sec(x) + cosec(x) + cotan(x)");
            var expected = MathS.Ln(x) + MathS.Sqrt(x) +
                           MathS.Tan(x) + MathS.Sec(x) + MathS.Cosec(x) +
                           MathS.Cotan(x);

            Assert.IsTrue(expr == expected);
        }
コード例 #4
0
ファイル: TransformUtil.cs プロジェクト: SylarLi/SoftPipeline
    /// <summary>
    /// 标准透视相机投影矩阵
    /// </summary>
    /// <param name="fov">arctan2(height / 2, near) * MathS.RadToDeg</param>
    /// <param name="aspect">width / height</param>
    /// <param name="near"></param>
    /// <param name="far"></param>
    /// <returns></returns>
    public static Matrix GetPersp(float fov, float aspect, float near, float far)
    {
        float h2 = MathS.Tan(fov * MathS.DegToRad) * near;
        float w2 = h2 * aspect;

        return(new Matrix(new float[4, 4]
        {
            { near / w2, 0, 0, 0 },
            { 0, near / h2, 0, 0 },
            { 0, 0, (far + near) / (far - near), -2 * far * near / (far - near) },
            { 0, 0, 1, 0 }
        }));
    }
コード例 #5
0
        public void TestTan()
        {
            var func = MathS.Tan(2 * x);

            AssertEqEntity(func.Derive(x).Simplify(), 2 / MathS.Pow(MathS.Cos(2 * x), 2));
        }
コード例 #6
0
 [TestMethod] public void Trig() =>
 TestSimplify(@"\sin\left(\cos\left(\tan\left(\cot\left(x\right)\right)\right)\right)", MathS.Sin(MathS.Cos(MathS.Tan(MathS.Cotan(x)))));
コード例 #7
0
        /// <summary>
        /// Returns a set of possible roots of a function, e. g.
        /// sin(x) = a =>
        /// x = arcsin(a) + 2 pi n
        /// x = pi - arcsin(a) + 2 pi n
        /// </summary>
        /// <param name="func"></param>
        /// <param name="value"></param>
        /// <param name="x"></param>
        /// <returns></returns>
        public static Set InvertFunctionEntity(FunctionEntity func, Entity value, Entity x)
        {
            Entity a   = func.Children[0];
            Entity b   = func.Children.Count == 2 ? func.Children[1] : null;
            int    arg = func.Children.Count == 2 && func.Children[1].FindSubtree(x) != null ? 1 : 0;
            var    n   = Utils.FindNextIndex(func + value, "n");
            var    res = new Set();
            var    pi  = MathS.pi;

            Set GetNotNullEntites(Set set)
            {
                return(set.FiniteWhere(el => el.entType != Entity.EntType.NUMBER || el.GetValue().IsDefinite()));
            }

            switch (func.Name)
            {
            // Consider case when sin(sin(x)) where double-mention of n occures
            case "sinf":
            {
                // sin(x) = value => x = arcsin(value) + 2pi * n
                res.AddRange(GetNotNullEntites(FindInvertExpression(a, MathS.Arcsin(value) + 2 * pi * n, x)));
                // sin(x) = value => x = pi - arcsin(value) + 2pi * n
                res.AddRange(GetNotNullEntites(FindInvertExpression(a, pi - MathS.Arcsin(value) + 2 * pi * n, x)));
                return(res);
            }

            case "cosf":
            {
                // cos(x) = value => x = arccos(value) + 2pi * n
                res.AddRange(GetNotNullEntites(FindInvertExpression(a, MathS.Arccos(value) + 2 * pi * n, x)));
                // cos(x) = value => x = -arccos(value) + 2pi * n
                res.AddRange(GetNotNullEntites(FindInvertExpression(a, -MathS.Arccos(value) - 2 * pi * n, x)));
                return(res);
            }

            case "tanf":
            {
                var inverted = FindInvertExpression(a, MathS.Arctan(value) + pi * n, x);
                // tan(x) = value => x = arctan(value) + pi * n
                res.AddRange(GetNotNullEntites(inverted));
                return(res);
            }

            case "cotanf":
            {
                var inverted = FindInvertExpression(a, MathS.Arccotan(value) + pi * n, x);
                // cotan(x) = value => x = arccotan(value)
                res.AddRange(GetNotNullEntites(inverted));
                return(res);
            }

            case "arcsinf":
                // arcsin(x) = value => x = sin(value)
                if (EntityInBounds(value, ArcsinFrom, ArcsinTo))
                {
                    return(GetNotNullEntites(FindInvertExpression(a, MathS.Sin(value), x)));
                }
                else
                {
                    return(Empty);
                }

            case "arccosf":
                // arccos(x) = value => x = cos(value)
                if (EntityInBounds(value, ArccosFrom, ArccosTo))
                {
                    return(GetNotNullEntites(FindInvertExpression(a, MathS.Cos(value), x)));
                }
                else
                {
                    return(Empty);
                }

            case "arctanf":
                // arctan(x) = value => x = tan(value)
                return(GetNotNullEntites(FindInvertExpression(a, MathS.Tan(value), x)));

            case "arccotanf":
                // arccotan(x) = value => x = cotan(value)
                return(GetNotNullEntites(FindInvertExpression(a, MathS.Cotan(value), x)));

            case "logf":
                if (arg != 0)
                {
                    // log(x, a) = value => x = a ^ value
                    return(GetNotNullEntites(FindInvertExpression(b, MathS.Pow(a, value), x)));
                }
                else
                {
                    // log(a, x) = value => a = x ^ value => x = a ^ (1 / value)
                    return(GetNotNullEntites(FindInvertExpression(a, MathS.Pow(b, 1 / value), x)));
                }

            default:
                throw new SysException("Unknown function");
            }
        }
コード例 #8
0
        public void TestTan()
        {
            var func = MathS.Tan(2 * x);

            Assert.Equal(2 / MathS.Pow(MathS.Cos(2 * x), 2), func.Differentiate(x).Simplify());
        }
コード例 #9
0
        public void TestTan()
        {
            var func = MathS.Tan(2 * x);

            Assert.IsTrue(func.Derive(x).Simplify() == 2 / MathS.Pow(MathS.Cos(2 * x), 2));
        }
 TreeAnalyzer.TryGetPolyLinear(arg, x, out var a, out _) =>
 MathS.Ln(MathS.Tan(0.5 * arg)) / a,