How to define the following expression as matrix multiplication?
$$-\sum_{i=1}^n\left[\mid e_i\mid-\exp(\sum_{j=0}^p \gamma_j X_{ij})\right]\exp(\sum_{j=0}^p \gamma_j X_{ij})X_{i.}$$
X is a matrix, e and γ are vectors
$$X_{n,p+1}$$ $$e_{n,1}$$ $$\gamma_{p+1,1}$$
For typing convenience, define the vectors $$\eqalign{ &u\in{\mathbb R}^{n},\qquad &v\in{\mathbb R}^{p+1},\qquad &y=\gamma \\ &a=|e|,\qquad &b=\exp(Xy),\qquad &c=(b-a)\odot b \\ }$$ where $\odot$ denotes the elementwise product, the exponential function is applied elementwise, and $(u,v)$ are vectors with all elements equal to ${\tt1}$.
Write the function in terms of these new vectors, then reduce. $$\eqalign{ f^T &= u^T\Big(cv^T\odot X\Big) \\ &= u^T\Big(\operatorname{Diag}(c)\,X\,\operatorname{Diag}(v)\Big) \\ &= c^TX\,I \\ f&= X^Tc \\ &= X^T\Big[(b-a)\odot b\Big] \\ &= X^T\Big[\big(\exp(Xy)-|e|\big)\odot\exp(Xy)\Big] \\ }$$ where $I\in{\mathbb R}^{(p+1)\times(p+1)}$ is the identity matrix and $f\in{\mathbb R}^{p+1}$.
Update
Based on your comments, you have the scalar function $$\eqalign{\phi &= \tfrac{1}{2}(b-a):(b-a)\qquad\big({\rm Frobenius\,Product}\big)}$$ and you wish to calculate its gradient and hessian. So let's do that. $$\eqalign{ d\phi &= (b-a):db \\ &= (b-a):(b\odot X\,dy) \\ &= b\odot(b-a):X\,dy \\ &= c:X\,dy \\ &= X^Tc:dy \\ g=\frac{\partial\phi}{\partial y} &= X^Tc \qquad\big({\rm Gradient}\big) \\ }$$ Now let's calculate the hessian. $$\eqalign{ dg &= X^Tdc \\ &= X^T\big((2b-a)\odot db\big) \\ &= X^T\big((2b-a)\odot b\odot X\,dy\big) \\ &= X^T(2B-A)BX\,dy \\ H=\frac{\partial g}{\partial y} &= X^T(2B-A)BX \qquad\big({\rm Hessian}\big) \\ }$$ where $\,A=\operatorname{Diag}(a),\,B=\operatorname{Diag}(b)$.