Gradient ∇f⁡\nabla \operatorname{f}

The gradient is an extension of the last section. The gradient of a function is a vector containing all its partial derivatives as its components. In the following, we will write all components that the function depends on in a vector x=(x1⋮xn)\mathbf{x} = \begin{pmatrix} x_1 \\ \vdots \\ x_n \end{pmatrix}.

∇f⁡(x)=(∂f⁡(x)∂x1⋮∂f⁡(x)∂xn)\nabla \operatorname{f}(\mathbf{x}) = \begin{pmatrix} \frac{\partial \operatorname{f}(\mathbf{x})}{\partial x_1} \\ \vdots \\ \frac{\partial \operatorname{f}(\mathbf{x})}{\partial x_n} \\ \end{pmatrix}

The implementation is basically the same as in the previous section, just with a loop.

Code: