I have a function of a single variable $ g \left( f \right) : \mathbb{R} \to \mathbb{R} $ with the following form:
$$ g \left( f \right) = \frac{1}{2} {\left\| \boldsymbol{X} {\left( \boldsymbol{X}^{T} \boldsymbol{X} \right)}^{-1} \boldsymbol{X}^{T} \boldsymbol{y} - \boldsymbol{y} \right\|}_{2}^{2} $$
Where
- The matrix $ \boldsymbol{X} \in \mathbb{R}^{N \times 2} $ is defined as $ \boldsymbol{X} \left( f \right) = \begin{bmatrix} \sin \left[ 2 \pi f 0 \right] & \cos \left[ 2 \pi f 0 \right] \\ \sin \left[ 2 \pi f 1 \right] & \cos \left[ 2 \pi f 1 \right] \\ \sin \left[ 2 \pi f 2 \right] & \cos \left[ 2 \pi f 2 \right] \\ \vdots & \vdots \\ \sin \left[ 2 \pi f \left( N - 1 \right) \right] & \cos \left[ 2 \pi f \left( N - 1 \right) \right] \end{bmatrix} $ (Namely the argument of the harmonic signal is $ 2 \pi f n, \; n \in \left\{ 0, 1, 2, \ldots, N - 1 \right\} $.
- The vector $ \boldsymbol{y} \in \mathbb{R}^{N} $ is given.
I am looking for a closed form expression of the 1st and 2nd derivative in order to optimize it using the Newton method.
How can it be derived efficiently?
Solution for the 1st Derivative
By the chain rule:
$$ \frac{\mathrm{d} g }{\mathrm{d} f} = \left \langle \frac{\mathrm{d} g }{\mathrm{d} \boldsymbol{X}}, \frac{\mathrm{d} \boldsymbol{X} }{\mathrm{d} f} \right \rangle $$
Calculating $ \frac{\mathrm{d} \boldsymbol{X} }{\mathrm{d} f} $ is straight forward as:
$$ \frac{\mathrm{d} \boldsymbol{X} }{\mathrm{d} f} = \begin{bmatrix} 2 \pi 0 \cos \left[ 2 \pi f 0 \right] & -2 \pi 0 \sin \left[ 2 \pi f 0 \right] \\ 2 \pi 1 \cos \left[ 2 \pi f 1 \right] & -2 \pi 1 \sin \left[ 2 \pi f 1 \right] \\ 2 \pi 2 \cos \left[ 2 \pi f 2 \right] & -2 \pi 2 \sin \left[ 2 \pi f 2 \right] \\ \vdots & \vdots \\ 2 \pi \left( N - 1 \right) \cos \left[ 2 \pi f \left( N - 1 \right) \right] & -2 \pi \left( N - 1 \right) \sin \left[ 2 \pi f \left( N - 1 \right) \right] \end{bmatrix} $$
The other derivative:
$$ \frac{\mathrm{d} g }{\mathrm{d} \boldsymbol{X}} = \boldsymbol{T}_{3} \boldsymbol{T}_{2} - \boldsymbol{T}_{1} \boldsymbol{T}_{4} + \boldsymbol{X} \boldsymbol{T}_{0} \boldsymbol{X}^{T} \boldsymbol{T}_{3} \boldsymbol{T}_{2} + \boldsymbol{y} \boldsymbol{T}_{4} $$
Where
I am still looking for the 2nd derivative.