First and second order derivation of multi-dimensional function

34 Views Asked by At

My professor told me to implement Newtons Method to find the minimum of this function:

$$f(x) = \frac{1}{2}x^TAx + b^Tx$$

given

$$A = \begin{bmatrix}0.78 & -0.02 & -0.12 & -0.14\\-0.02 & 0.86 & -0.04 & 0.06\\-0.12 & -0.04 & 0.72 & -0.08\\-0.14 & 0.06 & -0.08 & 0.74\end{bmatrix}$$

and

$$b = \begin{bmatrix}-0.76\\-0.08\\-1.12\\-0.68 \end{bmatrix}$$

Newtons Method requires analytical first ($\nabla f$) and second order ($H_f$) derivative. How am I supposed to calculate these of a 4-th dimensional function (without going crazy while doing it by hand)?

Edit: Writing everything down by hand, I get

$$f(x_1, x_2, x_3, x_4) = 0.39\cdot x_1^2 + 0.43\cdot x_2^2 + 0.36\cdot x_3^2 + 0.37\cdot x_4^2 - 0.02x_1x_2 - 0.12x_1x_3 - 0.14x_1x_4 + 0.06x_2x_4 - 0.08x_3x_4 - 0.04x_2x_3 - 0.76x_1 - 0.08x_2 - 1.12x_3 - 0.68x_4$$

and

$$\nabla f(x_1, x_2, x_3, x_4) = \begin{bmatrix}0.78x_1 - 0.02x_2 - 0.12x_3 - 0.14x_4 - 0.76\\0.86x_2 - 0.02x_1 - 0.04x_3 + 0.06x_4 - 0.08\\0.72x_3 - 0.12x_1 - 0.08x_4 - 0.04x_2 - 1.12\\0.74x_4 - 0.14x_1 + 0.06x_2 - 0.08x_3 -0.68 \end{bmatrix}$$

and

$$H_f = \begin{bmatrix}0.78 & -0.02 & -0.12 & -0.14\\-0.02 & 0.86 & -0.04 & 0.06\\-0.12 & -0.04 & 0.72 & -0.08\\-0.14 & 0.06 & -0.08 & 0.74\end{bmatrix}$$