\(\int \frac {\sin ^2(x)}{a \cos ^2(x)+b \sin ^2(x)} \, dx\) [482]

   Optimal result
   Rubi [A] (verified)
   Mathematica [A] (verified)
   Maple [A] (verified)
   Fricas [A] (verification not implemented)
   Sympy [B] (verification not implemented)
   Maxima [A] (verification not implemented)
   Giac [A] (verification not implemented)
   Mupad [B] (verification not implemented)

Optimal result

Integrand size = 20, antiderivative size = 43 \[ \int \frac {\sin ^2(x)}{a \cos ^2(x)+b \sin ^2(x)} \, dx=-\frac {x}{a-b}+\frac {\sqrt {a} \arctan \left (\frac {\sqrt {b} \tan (x)}{\sqrt {a}}\right )}{(a-b) \sqrt {b}} \]

[Out]

-x/(a-b)+arctan(b^(1/2)*tan(x)/a^(1/2))*a^(1/2)/(a-b)/b^(1/2)

Rubi [A] (verified)

Time = 0.18 (sec) , antiderivative size = 43, normalized size of antiderivative = 1.00, number of steps used = 4, number of rules used = 3, \(\frac {\text {number of rules}}{\text {integrand size}}\) = 0.150, Rules used = {492, 209, 211} \[ \int \frac {\sin ^2(x)}{a \cos ^2(x)+b \sin ^2(x)} \, dx=\frac {\sqrt {a} \arctan \left (\frac {\sqrt {b} \tan (x)}{\sqrt {a}}\right )}{\sqrt {b} (a-b)}-\frac {x}{a-b} \]

[In]

Int[Sin[x]^2/(a*Cos[x]^2 + b*Sin[x]^2),x]

[Out]

-(x/(a - b)) + (Sqrt[a]*ArcTan[(Sqrt[b]*Tan[x])/Sqrt[a]])/((a - b)*Sqrt[b])

Rule 209

Int[((a_) + (b_.)*(x_)^2)^(-1), x_Symbol] :> Simp[(1/(Rt[a, 2]*Rt[b, 2]))*ArcTan[Rt[b, 2]*(x/Rt[a, 2])], x] /;
 FreeQ[{a, b}, x] && PosQ[a/b] && (GtQ[a, 0] || GtQ[b, 0])

Rule 211

Int[((a_) + (b_.)*(x_)^2)^(-1), x_Symbol] :> Simp[(Rt[a/b, 2]/a)*ArcTan[x/Rt[a/b, 2]], x] /; FreeQ[{a, b}, x]
&& PosQ[a/b]

Rule 492

Int[((e_.)*(x_))^(m_.)/(((a_) + (b_.)*(x_)^(n_))*((c_) + (d_.)*(x_)^(n_))), x_Symbol] :> Dist[(-a)*(e^n/(b*c -
 a*d)), Int[(e*x)^(m - n)/(a + b*x^n), x], x] + Dist[c*(e^n/(b*c - a*d)), Int[(e*x)^(m - n)/(c + d*x^n), x], x
] /; FreeQ[{a, b, c, d, e, m}, x] && NeQ[b*c - a*d, 0] && IGtQ[n, 0] && LeQ[n, m, 2*n - 1]

Rubi steps \begin{align*} \text {integral}& = \text {Subst}\left (\int \frac {x^2}{\left (1+x^2\right ) \left (a+b x^2\right )} \, dx,x,\tan (x)\right ) \\ & = -\frac {\text {Subst}\left (\int \frac {1}{1+x^2} \, dx,x,\tan (x)\right )}{a-b}+\frac {a \text {Subst}\left (\int \frac {1}{a+b x^2} \, dx,x,\tan (x)\right )}{a-b} \\ & = -\frac {x}{a-b}+\frac {\sqrt {a} \arctan \left (\frac {\sqrt {b} \tan (x)}{\sqrt {a}}\right )}{(a-b) \sqrt {b}} \\ \end{align*}

Mathematica [A] (verified)

Time = 0.30 (sec) , antiderivative size = 36, normalized size of antiderivative = 0.84 \[ \int \frac {\sin ^2(x)}{a \cos ^2(x)+b \sin ^2(x)} \, dx=\frac {x-\frac {\sqrt {a} \arctan \left (\frac {\sqrt {b} \tan (x)}{\sqrt {a}}\right )}{\sqrt {b}}}{-a+b} \]

[In]

Integrate[Sin[x]^2/(a*Cos[x]^2 + b*Sin[x]^2),x]

[Out]

(x - (Sqrt[a]*ArcTan[(Sqrt[b]*Tan[x])/Sqrt[a]])/Sqrt[b])/(-a + b)

Maple [A] (verified)

Time = 0.53 (sec) , antiderivative size = 38, normalized size of antiderivative = 0.88

method result size
default \(\frac {a \arctan \left (\frac {b \tan \left (x \right )}{\sqrt {a b}}\right )}{\left (a -b \right ) \sqrt {a b}}-\frac {\arctan \left (\tan \left (x \right )\right )}{a -b}\) \(38\)
risch \(-\frac {x}{a -b}-\frac {\sqrt {-a b}\, \ln \left ({\mathrm e}^{2 i x}+\frac {2 i \sqrt {-a b}+a +b}{a -b}\right )}{2 b \left (a -b \right )}+\frac {\sqrt {-a b}\, \ln \left ({\mathrm e}^{2 i x}-\frac {2 i \sqrt {-a b}-a -b}{a -b}\right )}{2 b \left (a -b \right )}\) \(107\)

[In]

int(sin(x)^2/(a*cos(x)^2+sin(x)^2*b),x,method=_RETURNVERBOSE)

[Out]

a/(a-b)/(a*b)^(1/2)*arctan(b*tan(x)/(a*b)^(1/2))-1/(a-b)*arctan(tan(x))

Fricas [A] (verification not implemented)

none

Time = 0.28 (sec) , antiderivative size = 182, normalized size of antiderivative = 4.23 \[ \int \frac {\sin ^2(x)}{a \cos ^2(x)+b \sin ^2(x)} \, dx=\left [-\frac {\sqrt {-\frac {a}{b}} \log \left (\frac {{\left (a^{2} + 6 \, a b + b^{2}\right )} \cos \left (x\right )^{4} - 2 \, {\left (3 \, a b + b^{2}\right )} \cos \left (x\right )^{2} + 4 \, {\left ({\left (a b + b^{2}\right )} \cos \left (x\right )^{3} - b^{2} \cos \left (x\right )\right )} \sqrt {-\frac {a}{b}} \sin \left (x\right ) + b^{2}}{{\left (a^{2} - 2 \, a b + b^{2}\right )} \cos \left (x\right )^{4} + 2 \, {\left (a b - b^{2}\right )} \cos \left (x\right )^{2} + b^{2}}\right ) + 4 \, x}{4 \, {\left (a - b\right )}}, -\frac {\sqrt {\frac {a}{b}} \arctan \left (\frac {{\left ({\left (a + b\right )} \cos \left (x\right )^{2} - b\right )} \sqrt {\frac {a}{b}}}{2 \, a \cos \left (x\right ) \sin \left (x\right )}\right ) + 2 \, x}{2 \, {\left (a - b\right )}}\right ] \]

[In]

integrate(sin(x)^2/(a*cos(x)^2+b*sin(x)^2),x, algorithm="fricas")

[Out]

[-1/4*(sqrt(-a/b)*log(((a^2 + 6*a*b + b^2)*cos(x)^4 - 2*(3*a*b + b^2)*cos(x)^2 + 4*((a*b + b^2)*cos(x)^3 - b^2
*cos(x))*sqrt(-a/b)*sin(x) + b^2)/((a^2 - 2*a*b + b^2)*cos(x)^4 + 2*(a*b - b^2)*cos(x)^2 + b^2)) + 4*x)/(a - b
), -1/2*(sqrt(a/b)*arctan(1/2*((a + b)*cos(x)^2 - b)*sqrt(a/b)/(a*cos(x)*sin(x))) + 2*x)/(a - b)]

Sympy [B] (verification not implemented)

Leaf count of result is larger than twice the leaf count of optimal. 216 vs. \(2 (32) = 64\).

Time = 0.58 (sec) , antiderivative size = 216, normalized size of antiderivative = 5.02 \[ \int \frac {\sin ^2(x)}{a \cos ^2(x)+b \sin ^2(x)} \, dx=\begin {cases} \tilde {\infty } x & \text {for}\: a = 0 \wedge b = 0 \\\frac {- x + \frac {\sin {\left (x \right )}}{\cos {\left (x \right )}}}{a} & \text {for}\: b = 0 \\\frac {x}{b} & \text {for}\: a = 0 \\\frac {x \sin ^{2}{\left (x \right )}}{2 b \sin ^{2}{\left (x \right )} + 2 b \cos ^{2}{\left (x \right )}} + \frac {x \cos ^{2}{\left (x \right )}}{2 b \sin ^{2}{\left (x \right )} + 2 b \cos ^{2}{\left (x \right )}} - \frac {\sin {\left (x \right )} \cos {\left (x \right )}}{2 b \sin ^{2}{\left (x \right )} + 2 b \cos ^{2}{\left (x \right )}} & \text {for}\: a = b \\\frac {a \log {\left (- \sqrt {- \frac {a}{b}} \cos {\left (x \right )} + \sin {\left (x \right )} \right )}}{2 a b \sqrt {- \frac {a}{b}} - 2 b^{2} \sqrt {- \frac {a}{b}}} - \frac {a \log {\left (\sqrt {- \frac {a}{b}} \cos {\left (x \right )} + \sin {\left (x \right )} \right )}}{2 a b \sqrt {- \frac {a}{b}} - 2 b^{2} \sqrt {- \frac {a}{b}}} - \frac {2 b x \sqrt {- \frac {a}{b}}}{2 a b \sqrt {- \frac {a}{b}} - 2 b^{2} \sqrt {- \frac {a}{b}}} & \text {otherwise} \end {cases} \]

[In]

integrate(sin(x)**2/(a*cos(x)**2+b*sin(x)**2),x)

[Out]

Piecewise((zoo*x, Eq(a, 0) & Eq(b, 0)), ((-x + sin(x)/cos(x))/a, Eq(b, 0)), (x/b, Eq(a, 0)), (x*sin(x)**2/(2*b
*sin(x)**2 + 2*b*cos(x)**2) + x*cos(x)**2/(2*b*sin(x)**2 + 2*b*cos(x)**2) - sin(x)*cos(x)/(2*b*sin(x)**2 + 2*b
*cos(x)**2), Eq(a, b)), (a*log(-sqrt(-a/b)*cos(x) + sin(x))/(2*a*b*sqrt(-a/b) - 2*b**2*sqrt(-a/b)) - a*log(sqr
t(-a/b)*cos(x) + sin(x))/(2*a*b*sqrt(-a/b) - 2*b**2*sqrt(-a/b)) - 2*b*x*sqrt(-a/b)/(2*a*b*sqrt(-a/b) - 2*b**2*
sqrt(-a/b)), True))

Maxima [A] (verification not implemented)

none

Time = 0.30 (sec) , antiderivative size = 35, normalized size of antiderivative = 0.81 \[ \int \frac {\sin ^2(x)}{a \cos ^2(x)+b \sin ^2(x)} \, dx=\frac {a \arctan \left (\frac {b \tan \left (x\right )}{\sqrt {a b}}\right )}{\sqrt {a b} {\left (a - b\right )}} - \frac {x}{a - b} \]

[In]

integrate(sin(x)^2/(a*cos(x)^2+b*sin(x)^2),x, algorithm="maxima")

[Out]

a*arctan(b*tan(x)/sqrt(a*b))/(sqrt(a*b)*(a - b)) - x/(a - b)

Giac [A] (verification not implemented)

none

Time = 0.28 (sec) , antiderivative size = 48, normalized size of antiderivative = 1.12 \[ \int \frac {\sin ^2(x)}{a \cos ^2(x)+b \sin ^2(x)} \, dx=\frac {{\left (\pi \left \lfloor \frac {x}{\pi } + \frac {1}{2} \right \rfloor \mathrm {sgn}\left (b\right ) + \arctan \left (\frac {b \tan \left (x\right )}{\sqrt {a b}}\right )\right )} a}{\sqrt {a b} {\left (a - b\right )}} - \frac {x}{a - b} \]

[In]

integrate(sin(x)^2/(a*cos(x)^2+b*sin(x)^2),x, algorithm="giac")

[Out]

(pi*floor(x/pi + 1/2)*sgn(b) + arctan(b*tan(x)/sqrt(a*b)))*a/(sqrt(a*b)*(a - b)) - x/(a - b)

Mupad [B] (verification not implemented)

Time = 27.92 (sec) , antiderivative size = 51, normalized size of antiderivative = 1.19 \[ \int \frac {\sin ^2(x)}{a \cos ^2(x)+b \sin ^2(x)} \, dx=\left \{\begin {array}{cl} \frac {2\,x-\sin \left (2\,x\right )}{4\,b} & \text {\ if\ \ }a=b\\ -\frac {x-\frac {\sqrt {a}\,\mathrm {atan}\left (\frac {\sqrt {b}\,\mathrm {tan}\left (x\right )}{\sqrt {a}}\right )}{\sqrt {b}}}{a-b} & \text {\ if\ \ }a\neq b \end {array}\right . \]

[In]

int(sin(x)^2/(b*sin(x)^2 + a*cos(x)^2),x)

[Out]

piecewise(a == b, (2*x - sin(2*x))/(4*b), a ~= b, -(x - (a^(1/2)*atan((b^(1/2)*tan(x))/a^(1/2)))/b^(1/2))/(a -
 b))