|
| 1 | +// |
| 2 | +// Copyright (c) 2019-2026 Angouri. |
| 3 | +// AngouriMath is licensed under MIT. |
| 4 | +// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. |
| 5 | +// Website: https://am.angouri.org. |
| 6 | +// |
| 7 | + |
| 8 | +using System; |
| 9 | +using AngouriMath.Extensions; |
| 10 | +using Xunit; |
| 11 | + |
| 12 | +namespace AngouriMath.Tests.Calculus |
| 13 | +{ |
| 14 | + /// <summary> |
| 15 | + /// The derivative of a sine raised from nothing times powers of the cosine, the secant and sums |
| 16 | + /// in them, or of a cosine beside the sine, alone or beside x by parts: Rubi's 4.2.2.1, 4.5.1.2, |
| 17 | + /// 4.5.4.2 and 4.7.7. |
| 18 | + /// <a href="https://github.com/asc-community/AngouriMath/issues/233">#233</a> |
| 19 | + /// </summary> |
| 20 | + [Trait("Area", "Calculus")] |
| 21 | + public sealed class ASineRaisedFromNothingBesidePowersOfTheCosineIntegralTest |
| 22 | + { |
| 23 | + // Points where the cosine is negative too, where the integrand is complex and the answer's |
| 24 | + // principal powers still differentiate to it. |
| 25 | + [Theory] |
| 26 | + [InlineData("(a+a*cos(c+d*x))^(3/2)/cos(c+d*x)^(5/4)")] |
| 27 | + [InlineData("(a+a*cos(c+d*x))^(3/2)*sec(c+d*x)^(5/4)")] |
| 28 | + [InlineData("(a+a*sec(c+d*x))^(3/2)/sec(c+d*x)^(1/4)")] |
| 29 | + [InlineData("(a+a*sec(c+d*x))^n*(-a*A*n-a*Q*(1+n)*sec(c+d*x))/(a*(1+n)*sec(c+d*x)^n)+sec(c+d*x)^(-1-n)*(a+a*sec(c+d*x))^n*(A+Q*sec(c+d*x)^2)")] |
| 30 | + [InlineData("x*(b+a*sin(x))/(a+b*sin(x))^2")] |
| 31 | + [InlineData("x*(b+a*cos(c+d*x))/(a+b*cos(c+d*x))^2")] |
| 32 | + public void IsAnsweredAndDifferentiatesBack(string integrand) |
| 33 | + { |
| 34 | + var integral = integrand.ToEntity().Integrate("x"); |
| 35 | + var text = integral.Stringize(); |
| 36 | + Assert.DoesNotContain("integral(", text); |
| 37 | + Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("b", 0.7).Substitute("c", 0.3).Substitute("d", 0.75) |
| 38 | + .Substitute("A", 0.6).Substitute("Q", 1.25).Substitute("n", 0.4); |
| 39 | + var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x"); |
| 40 | + var original = Pinned(integrand.ToEntity()); |
| 41 | + var compared = 0; |
| 42 | + foreach (var at in new[] { -2.3, -1.1, -0.7, 0.4, 1.9, 2.8 }) |
| 43 | + { |
| 44 | + var want = original.Substitute("x", at).EvalNumerical(); |
| 45 | + var got = derivative.Substitute("x", at).EvalNumerical(); |
| 46 | + if (want.IsNaN) |
| 47 | + continue; |
| 48 | + compared++; |
| 49 | + Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart) |
| 50 | + < 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart) + Math.Abs((double)want.ImaginaryPart)), |
| 51 | + $"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}"); |
| 52 | + } |
| 53 | + Assert.True(compared >= 5, $"only {compared} points could be compared for {integrand}"); |
| 54 | + } |
| 55 | + |
| 56 | + [Fact] |
| 57 | + public void IsTheRaisedProductInClosedForm() |
| 58 | + { |
| 59 | + // 4 a^2 sin/(cos^(1/4) sqrt(a + a cos)), Rubi's, with no half angle in it. |
| 60 | + var integral = "(a+a*cos(x))^(3/2)/cos(x)^(5/4)".ToEntity().Integrate("x").Stringize(); |
| 61 | + Assert.DoesNotContain("x / 2", integral); |
| 62 | + Assert.Contains("cos(x) ^ (-1/4)", integral); |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments