Finding the integral: $\int_{0}^{\large\frac{\pi}{4}}\frac{\cos(x)\:dx}{a\cos(x)+b \sin(x)}$

What is
$$\int_{0}^{\large\frac{\pi}{4}}\frac{\cos(x)\:dx}{a\cos(x)+b \sin(x)}?$$

$a,b \in \mathbb{R}$ appropriate fixed numbers.

Solutions Collecting From Web of "Finding the integral: $\int_{0}^{\large\frac{\pi}{4}}\frac{\cos(x)\:dx}{a\cos(x)+b \sin(x)}$"

Hint. We assume $a>0,b>0$. One may observe that
$$
a\int_{0}^{\large \frac{\pi}{4}}\frac{\cos(x)\:dx}{a\cos(x)+b \sin(x)}+b\int_{0}^{\large \frac{\pi}{4}}\frac{\sin(x)\:dx}{a\cos(x)+b \sin(x)}=\int_0^{\large\frac{\pi}{4}}1\:dx=\frac \pi4
$$ and that
$$
b\int_{0}^{\large \frac{\pi}{4}}\frac{\cos(x)\:dx}{a\cos(x)+b \sin(x)}-a\int_{0}^{\large \frac{\pi}{4}}\frac{\sin(x)\:dx}{a\cos(x)+b \sin(x)}=\int_0^{\large\frac{\pi}{4}}\frac{(a\cos(x)+b \sin(x))’}{a\cos(x)+b \sin(x)}dx.
$$ then solving the system

$$\begin{cases}
a I+bJ=\frac \pi4 \\
b I-aJ=\log\left(\frac{a+b}{a \sqrt{2}}\right)
\end{cases}
$$
gives the answer.

The substitution $u=\sin(x)$ will help

$$\mathcal{I}\left(\text{a},\text{b}\right)=\int_0^{\frac{\pi}{4}}\frac{\cos\left(\text{x}\right)}{\text{a}\cos\left(\text{x}\right)+\text{b}\sin\left(\text{x}\right)}\space\text{d}\text{x}=$$
$$\frac{\text{a}}{\text{a}^2+\text{b}^2}\int_0^{\frac{\pi}{4}}1\space\text{d}\text{x}-\frac{\text{b}}{\text{a}^2+\text{b}^2}\int_0^{\frac{\pi}{4}}\frac{\text{a}\sin\left(\text{x}\right)-\text{b}\cos\left(\text{x}\right)}{\text{a}\cos\left(\text{x}\right)+\text{b}\sin\left(\text{x}\right)}\space\text{d}\text{x}$$

Now, use:

$$\int_0^{\frac{\pi}{4}}1\space\text{d}\text{x}=\frac{\pi}{4}$$

So, we get:

$$\mathcal{I}\left(\text{a},\text{b}\right)=\frac{\pi}{4}\cdot\frac{\text{a}}{\text{a}^2+\text{b}^2}-\frac{\text{b}}{\text{a}^2+\text{b}^2}\int_0^{\frac{\pi}{4}}\frac{\text{a}\sin\left(\text{x}\right)-\text{b}\cos\left(\text{x}\right)}{\text{a}\cos\left(\text{x}\right)+\text{b}\sin\left(\text{x}\right)}\space\text{d}\text{x}$$

Now, substitute $\text{u}=\text{a}\cos\left(\text{x}\right)+\text{b}\sin\left(\text{x}\right)$ and $\text{d}\text{u}=\left(\text{b}\cos\left(\text{x}\right)-\text{a}\sin\left(\text{x}\right)\right)\space\text{d}\text{x}$:

$$\int_0^{\frac{\pi}{4}}\frac{\text{a}\sin\left(\text{x}\right)-\text{b}\cos\left(\text{x}\right)}{\text{a}\cos\left(\text{x}\right)+\text{b}\sin\left(\text{x}\right)}\space\text{d}\text{x}=-\int_\text{a}^{\frac{\text{a}+\text{b}}{\sqrt{2}}}\frac{1}{\text{u}}\space\text{d}\text{u}=-\left(\ln\left|\frac{\text{a}+\text{b}}{\sqrt{2}}\right|-\ln\left|\text{a}\right|\right)$$

So, we get:

$$\mathcal{I}\left(\text{a},\text{b}\right)=\frac{\pi}{4}\cdot\frac{\text{a}}{\text{a}^2+\text{b}^2}+\frac{\text{b}}{\text{a}^2+\text{b}^2}\left(\ln\left|\frac{\text{a}+\text{b}}{\sqrt{2}}\right|-\ln\left|\text{a}\right|\right)$$

$\newcommand{\bbx}[1]{\,\bbox[8px,border:1px groove navy]{{#1}}\,}
\newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace}
\newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack}
\newcommand{\dd}{\mathrm{d}}
\newcommand{\ds}[1]{\displaystyle{#1}}
\newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,}
\newcommand{\ic}{\mathrm{i}}
\newcommand{\mc}[1]{\mathcal{#1}}
\newcommand{\mrm}[1]{\mathrm{#1}}
\newcommand{\pars}[1]{\left(\,{#1}\,\right)}
\newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
\newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,}
\newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}}
\newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$
\begin{align}
&\int_{0}^{\pi/4}{\cos\pars{x} \over a\cos\pars{x} + b\sin\pars{x}}\,\dd x
\\[5mm] = &\
{1 \over a}\int_{0}^{\pi/4}
{\cos\pars{x} \over \cos\pars{x} + \tan\pars{\mu}\sin\pars{x}}\,\dd x
\qquad\qquad\qquad\qquad\pars{~\tan\pars{\mu} \equiv {b \over a}~}
\\[5mm] = &\
{\cos\pars{\mu} \over a}\int_{0}^{\pi/4}
{\cos\pars{x} \over \cos\pars{x – \mu}}\,\dd x =
{\cos\pars{\mu} \over a}\int_{-\mu}^{\pi/4 – \mu}
{\cos\pars{x + \mu} \over \cos\pars{x}}\,\dd x
\\[5mm] = &\
{1 \over a\sec^{2}\pars{\mu}}\,{\pi \over 4} –
{\cos\pars{\mu}\sin\pars{\mu} \over a}\int_{-\mu}^{\pi/4 – \mu}
\tan\pars{x}\,\dd x
\\[5mm] = &
{1 \over a\bracks{\tan^{2}\pars{\mu} + 1}}\,{\pi \over 4} –
{\tan\pars{\mu} \over a\bracks{\tan^{2}\pars{\mu} + 1}}\bracks{-\ln\pars{\cos\pars{{\pi \over 4} – \mu}} + \ln\pars{\cos\pars{-\mu}}}
\\[5mm] = &\
{\pi \over 4}\,{a \over a^{2} + b^{2}} –
{b \over a^{2} + b^{2}}\bracks{%
{1 \over 2}\ln\pars{\tan^{2}\pars{\pi/4 – \mu} + 1 \over
\tan^{2}\pars{\mu} + 1}}
\\[5mm] = &\
{\pi \over 4}\,{a \over a^{2} + b^{2}} –
{b \over 2\pars{a^{2} + b^{2}}}
\ln\pars{\braces{\bracks{1 – b/a}/\bracks{1 + b/a}}^{2} + 1 \over
b^{2}/a^{2} + 1}
\\[5mm] = &\
\bbx{\ds{{\pi \over 4}\,{a \over a^{2} + b^{2}} –
{b \over a^{2} + b^{2}}\ln\pars{\root{2}\verts{a \over a + b}}}}
\end{align}