I have a function that can be written as follows: $$f(\vec{x},\vec{y}) = f_x(\vec{x}) + f_y(\vec{y}) + k\bigg(f_x(\vec{x})-f_y(\vec{y})\bigg)^2$$
I have to take the first derivative (gradient) and second derivative (hessian) of this function with respect to the combined $\vec{x}$ and $\vec{y}$. By combined, I mean a vector which the concatenation of both $\vec{x}$ and $\vec{y}$ like this: $$\vec{z} = (x_1,x_2,x_3,...,y_1,y_2,y_3,...)$$
So far I have been able to derive the analytic expression for the gradient $\nabla f$, which is simple because $f_x$ depends only on $x$ terms, and $f_y$ depends only on y terms. So, I can simply expand the square expression, collect the gradient terms, and concatenate. However, I am struggling to derive an expression for the Hessian matrix ($\nabla^2 f$) because of the cross-terms.
Note: The gradient and Hessian of each of the $f_x(\vec{x})$ and $f_y(\vec{y})$ with respect to their own vectors are possible to calculate (available). So, I have to write the gradient and Hessian of the composite function in those terms, as I need those for a program I am coding. Both $f_x$ and $f_y$ are functions that produce scalar numbers as ouptut. $k$ is a scalar constant.
I am a chemist, so I am not very familiar with linear algebra. If the Hessian (or gradient) can be calculated quickly with a matrix operation then it would be easier to code for. Any help is appreciated.