<s>[INST] Help with Maclaurin series of $\cos(\ln(x+1))$? Hi I've almost completed a maths question I am stuck on I just can't seem to get to the final result. The question is:
Find the Maclaurin series of $g(x) = \cos(\ln(x+1))$ up to order 3.
I have used the formulas which I won't type out as I'm not great with Mathjax yet sorry. But I have obtained:
$$ \ln(x+1) = x - \frac{x^2}{2} + \frac{x^3}{3} - \frac{x^4}{4} $$
$$ \cos x =   1 - \frac{x^2}{2} + \frac{x^4}{24} - \frac{x^6}{720} $$
I'm sure what I have done above is correct however I can't seem to get to the final solution shown in the answers and would like some help please. Thanks 
 [/INST] Since you also don't need very high orders, the straightforward calculation of derivatives is tractable, though not preferable computationally.  If $f(x) = \cos \log(1+x)$, then $$f'(x) = -\frac{\sin \log (1+x)}{1+x}, \quad f'(0) = 0.$$  Then $$f''(x) = -\frac{\cos \log (1+x)}{(1+x)^2} + \frac{\sin \log(1+x)}{(1+x)^2}, \quad f''(0) = -1.$$  Finally, $$f'''(x) = \frac{\sin \log(1+x)}{(1+x)^3} + \frac{2\cos \log(1+x)}{(1+x)^3} + \frac{\cos \log(1+x)}{(1+x)^3} - \frac{2 \sin \log (1+x)}{(1+x)^3}, \quad f'''(0) = 3.$$  Then $$f(x) = f(0) + \frac{f'(0)}{1!}x + \frac{f''(0)}{2!}x^2 + \frac{f'''(0)}{3!}x^3 + O(x^4) = 1 - \frac{x^2}{2} + \frac{x^3}{2} + O(x^4).$$
It is worth noting that $$f^{(n)}(x) = \frac{A_n \cos \log (1+x) + B_n \sin \log (1+x)}{(1+x)^n},$$ for suitable constants $A_n$, $B_n$.  A proof by induction is straightforward and yields insight into the recursion relations defining $\{(A_n, B_n)\}_{n \ge 1}$:  $$\begin{align*} f^{(n+1)}(x) &= -A_n \frac{\sin \log (1+x)}{(1+x)^{n+1}} - nA_n \frac{\cos \log (1+x)}{(1+x)^{n+1}} - n B_n \frac{\sin \log(1+x)}{(1+x)^{n+1}} + B_n \frac{\cos \log (1+x)}{(1+x)^{n+1}} \\
&= \frac{(B_n - nA_n) \cos \log(1+x) + (-A_n - nB_n)\sin \log(1+x)}{(1+x)^{n+1}}.
\end{align*}.$$  Therefore, $$\begin{align*} A_{n+1} & = -nA_n + B_n, \\ B_{n+1} &= -A_n - nB_n, \\ A_0 &= 1, \\ B_0 &= 0. \end{align*}$$  In matrix form, this recurrence is equivalent to $$\begin{bmatrix}A_{n+1} \\ B_{n+1}\end{bmatrix} = \begin{bmatrix} -n & 1 \\ -1 & -n \end{bmatrix} \begin{bmatrix} A_n \\ B_n \end{bmatrix},$$ consequently $$\begin{bmatrix}A_n \\ B_n\end{bmatrix} = M_n \begin{bmatrix} 1 \\ 0 \end{bmatrix},$$ where $$M_n = \prod_{k=0}^{n-1} \begin{bmatrix} -k & 1 \\ -1 & -k \end{bmatrix}$$ and $f^{(n)}(0) = A_n$.  This lets us continue our calculation of higher orders with relative ease if we keep track of the matrix product $M_n$, which is always of the form $$M_n = \begin{bmatrix} a & b \\ -b & a \end{bmatrix};$$ for example, $$M_3 = \begin{bmatrix} 3 & 1 \\ -1 & 3\end{bmatrix}, \quad M_4 = \begin{bmatrix} -3 & 1 \\ -1 & -3\end{bmatrix}\begin{bmatrix} 3 & 1 \\ -1 & 3\end{bmatrix} = \begin{bmatrix} -10 & 0 \\ 0 & -10 \end{bmatrix},$$ so that $A_4 = -10$ and the next coefficient is $-10/4! = -5/12$.
</s>