Repository navigation
Expand file tree
/
Copy pathAHalfAngleRationalFunctionOverOneMinusTheSquareIntegralTest.cs
More file actions
50 lines (48 loc) · 2.32 KB
/
Copy pathAHalfAngleRationalFunctionOverOneMinusTheSquareIntegralTest.cs
File metadata and controls
50 lines (48 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// Copyright (c) 2019-2026 Angouri.
// AngouriMath is licensed under MIT.
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
// Website: https://am.angouri.org.
//
using System;
using AngouriMath.Extensions;
using Xunit;
namespace AngouriMath.Tests.Calculus
{
/// <summary>
/// A rational function of the sine over a power of <c>a + b sin(x)</c> with the cosine below the bar: under
/// the half-angle tangent, <c>(1 - u^2)</c> beside <c>a u^2 + 2 b u + a</c>, split by its partial fractions
/// rather than searched for a substitution. Rubi's 4.1.1.2, 4.1.1.3 and 4.1.2.2.
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
/// </summary>
[Trait("Area", "Calculus")]
public sealed class AHalfAngleRationalFunctionOverOneMinusTheSquareIntegralTest
{
[Theory]
[InlineData("sec(x)^2*sin(x)/(a + b*sin(x))^3")]
[InlineData("tan(x)^2/(a + b*sin(x))^3")]
public void ByItsPartialFractions(string integrand)
{
var integral = integrand.ToEntity().Integrate("x");
var text = integral.Stringize();
Assert.DoesNotContain("integral(", text);
Assert.True(text.Length < 20000, $"{text.Length} characters of answer for {integrand}");
Entity Pinned(Entity e) => e.Substitute("a", 2.3).Substitute("b", 0.7);
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
var original = Pinned(integrand.ToEntity());
var compared = 0;
foreach (var at in new[] { -1.2, -0.7, 0.3, 0.8, 1.3, 2.9 })
{
var want = original.Substitute("x", at).EvalNumerical();
var got = derivative.Substitute("x", at).EvalNumerical();
if (want.IsNaN)
continue;
compared++;
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)),
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
}
Assert.True(compared >= 5, $"only {compared} points could be compared for {integrand}");
}
}
}