public void TestSecant() { Entity func = "sec(2x)"; var derived = func.Differentiate("x"); Assert.Equal(2 * MathS.Sec("2x") * MathS.Tan("2x"), derived.Simplify()); }
public void TestInnerComplex() { var expr = MathS.FromString("cotan(x + tan(x))"); var expected = MathS.Cotan(x + MathS.Tan(x)); Assert.IsTrue(expr == expected); }
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); }
/// <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 } })); }
public void TestTan() { var func = MathS.Tan(2 * x); AssertEqEntity(func.Derive(x).Simplify(), 2 / MathS.Pow(MathS.Cos(2 * x), 2)); }
[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)))));
/// <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"); } }
public void TestTan() { var func = MathS.Tan(2 * x); Assert.Equal(2 / MathS.Pow(MathS.Cos(2 * x), 2), func.Differentiate(x).Simplify()); }
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,