# Exponential Matrix Differentiation

I have been struggling with the following question while solving an optimization problem in $\mathbb{R}_{+}^G$. Basically, I have $$\min_{y \in \mathbb{R}_{+}^G} F(y) = y^{T}\mathcal{K} + \exp(-y^{T} \mathcal{A}) \mathcal{P},$$ where $\mathcal{K}$ is a positive vector in $G\times 1$, $\mathcal{A}$ is a positive matrix in $G \times J$ and $\mathcal{P}$ is a positive vector in $J \times 1$.

But when I try to get $\nabla_{y} F(y)$ and $H_{y} F(y)$ Mathematica tells me "the tensor ... and ... have incompatible shapes.". I'm not very familiar with exponential matrices differentiation, so if anybody could give me a little help, it would be great.

{G, J, S} = {2, 2, 1}

\[ScriptCapitalK] = Table[Subscript[k, g, s], {g, 1, G}, {s, 1, S}];
\[ScriptCapitalY] = Table[Subscript[y, g, s], {g, 1, G}, {s, 1, S}];
\[ScriptCapitalA] = Table[Subscript[a, g, j], {g, 1, G}, {j, 1, J}] ;
\[CapitalRho] = Table[Subscript[\[Rho], j, s], {j, 1, J}, {s, 1, S}];

{\[ScriptCapitalY] // MatrixForm,
\[ScriptCapitalK] //    MatrixForm,
\[ScriptCapitalA] // MatrixForm,
\[CapitalRho] // MatrixForm,
E^-\[ScriptCapitalA]\[Transpose].\[ScriptCapitalY] // MatrixForm}

F[y__] :=   y\[Transpose].\[ScriptCapitalK] + E^(-y\[Transpose].\[ScriptCapitalA]).\[CapitalRho]


Grad[F[\[ScriptCapitalY]],Flatten[\[ScriptCapitalY]]]

• Can't execute your code as written, {G,S,J} all need to be defined first – Jason B. Nov 23 '15 at 13:47
• Thank you. I missed the first line: {G, J, S} = {2, 2, 1}, but I'd like it to be general for s=1. – Guilherme Thompson Nov 23 '15 at 13:48