Finding gradient of matrix functions

68 Views Asked by At

I have a function $g(x) = f(Ax-b)$ where $f(x) = \sin(x_1)+ \sin(x_2)$. I need to express the gradient of $g$ in terms of $x$.

I say that $g(x) = f(Ax - b) = \sin(Ax_1 - b) + \sin(A x_2 - b)$

$\text{gradient}(g) = \left[\frac {\partial g(x)} {\partial x}\right] = \left[\frac {\partial f(Ax-b)} {\partial x_1}, \frac {\partial f(Ax-b)} {\partial x_2}\right] = \left[A \cos(Ax_1-b) \: A \cos(Ax_2-b) \right]^T$

Now to find the value of this gradient at $\hat{x} = [1 \: 1]^T$ is where I am having the issue. To me it makes sense that $x_1 = x_2 = 1$ and,

$\text{gradient}(g) = \left[A \cos(Ax_1-b) \: A \cos(Ax_2-b) \right]^T = \left[A \cos(A*1-b) \: A \cos(A * 1-b) \right]^T$

but this does not make sense because $A$ and $b$ are different sizes. So this means I am making a mistake somewhere - can anyone help? I feel dumb

1

There are 1 best solutions below

1
On

Just because $f(x) = \sin(x_1)+ \sin(x_2)$ doesn't mean $$\color{red}{f(Ax - b) = \sin(Ax_1 - b) + \sin(A x_2 - b)}$$ Matrix notation can be troublesome, so I'll break it down. \begin{align} g(x) &= f(Ax-b)=f\left(\begin{bmatrix}a_{11}&a_{12} \\ a_{21}&a_{22}\end{bmatrix}\begin{bmatrix}x_1 \\ x_2\end{bmatrix}-\begin{bmatrix}b_1 \\ b_2\end{bmatrix}\right)\\&=f\left(\begin{bmatrix}a_{11}x_1+a_{12}x_2-b_1 \\ a_{21}x_1+a_{22}x_2-b_2\end{bmatrix}\right)\\&=\sin(a_{11}x_1+a_{12}x_2-b_1)+\sin(a_{21}x_1+a_{22}x_2-b_2) \\ \nabla g(x) &= \left[\frac {\partial g(x)} {\partial x_1}, \frac {\partial g(x)} {\partial x_2}\right]^T \\&= \begin{bmatrix}a_{11}\cos(a_{11}x_1+a_{12}x_2-b_1)+a_{21}\cos(a_{21}x_1+a_{22}x_2-b_2) \\ a_{12}\cos(a_{11}x_1+a_{12}x_2-b_1)+a_{22}\cos(a_{21}x_1+a_{22}x_2-b_2)\end{bmatrix} \end{align}