Let
$f\left(x\right)= \begin{cases}
x+a\sqrt{2} \sin x, & 0\leq x < \dfrac{\pi}{4} \\
& \\
2x \cot x +b, & \dfrac{\pi}{4}\leq x < \dfrac{\pi}{2} \\
& \\
a \cos 2x - b \sin x, & \dfrac{\pi}{2}\leq x \leq \pi
\end{cases}$
If $f\left(x\right)$ is continuous for $0 \leq x \leq \pi$, find a and b.
Since $f\left(x\right)$ is continuous for $0 \leq x \leq \pi$, therefore $f\left(x\right)$ must be continuous at $\dfrac{\pi}{4}$ and $\dfrac{\pi}{2}$
$\therefore$ $f\left(\dfrac{\pi}{4}\right) = \lim\limits_{x \to \frac{\pi}{4}^-} f\left(x\right) = \lim\limits_{x \to \frac{\pi}{4}^+} f\left(x\right)$ $\;\;$ $\cdots$ (1)
and $f\left(\dfrac{\pi}{2}\right) = \lim\limits_{x \to \frac{\pi}{2}^-} f\left(x\right) = \lim\limits_{x \to \frac{\pi}{2}^+} f\left(x\right)$ $\;\;$ $\cdots$ (2)
$\therefore$ Equation (1) gives
$2 \times \dfrac{\pi}{4} \times \cot \left(\dfrac{\pi}{4}\right)+b = \lim\limits_{x \to \frac{\pi}{4}^-} \; x+a\sqrt{2} \sin x = \lim\limits_{x \to \frac{\pi}{4}^+} \; 2x \cot x + b$
i.e. $\dfrac{\pi}{2}+b= \dfrac{\pi}{4}+a \sqrt{2} \sin \left(\dfrac{\pi}{4}\right)= 2 \times \dfrac{\pi}{4} \times \cot \left(\dfrac{\pi}{4}\right)+b$
i.e. $\dfrac{\pi}{2}+b= \dfrac{\pi}{4}+a\sqrt{2}\times \dfrac{1}{\sqrt{2}}=\dfrac{\pi}{2}+b$
i.e. $\dfrac{\pi}{4}+a = \dfrac{\pi}{2}+b$
i.e. $a-b=\dfrac{\pi}{4}$ $\cdots$ (3)
Equation (2) gives
$a \cos \left(2 \times \dfrac{\pi}{2}\right) - b\sin \left(\dfrac{\pi}{2}\right) = \lim\limits_{x \to \frac{\pi}{2}^-} \; 2x \cot x +b = \lim\limits_{x \to \frac{\pi}{2}^+} \; a \cos 2x - b\sin x$
i.e. $-a-b = 2 \times \dfrac{\pi}{2} \times \cot \left(\dfrac{\pi}{2}\right)+b = a \cos \left(2 \times \dfrac{\pi}{2}\right)- b\sin\left(\dfrac{\pi}{2}\right)$
i.e. $-a-b = b = -a-b$
i.e. $-a-b = b$
i.e. $a = -2b$ $\cdots$ (4)
Substituting the value of a from equation (4) in equation (3) gives
$-2b-b=\dfrac{\pi}{4}$ $\implies$ $b=-\dfrac{\pi}{12}$
$\therefore$ From equation (4), $a=2 \times \dfrac{\pi}{12}=\dfrac{\pi}{6}$