I have an expression
$$ \mathbf{A}\mathbf{s} $$
where $\mathbf{A}$ is an $n \times n$ matrix and $\mathbf{s}$ is a $n \times 1$ vector. The matrix $\mathbf{A}$ is itself a function of $\mathbf{s}$
$$ \mathbf{A} = \mathbf{f}(\mathbf{s})$$
I am wondering how I firstly, compute the derivative of this expression and secondly, numerically estimate the derivative at some vector $\mathbf{s}_0$. My attempt has been to apply the product rule in some way
$$ \frac{d}{d\mathbf{s}} \mathbf{f}(\mathbf{s})\mathbf{s} = \mathbf{f}(\mathbf{s}) + \mathbf{f}'(\mathbf{s})\mathbf{s} $$
noting that $\mathbf{f}'(\mathbf{s})$ is a $(n \times n) \times n$ matrix so that the derivative above is a matrix of dimension $n \times n$ if we consider the term $\mathbf{f}'(\mathbf{s})\mathbf{s}$ as an $n \times n$ matrix expressed with its columns placed below each other.
I am not completely sure whether my approach is correct and additionally, how to proceed from here in terms of numerically evaluating this derivative at a particular vector. I plan to use Matlab to compute a numerical derivative.
Any assistance or input would be greatly appreciated!
Unfortunately, $f'(s)$ is not a matrix, it is a third-order tensor with dimensions $(n\times n\times n)$
Such tensors are awkward to work with. The easiest way to proceed is to vectorize the matrix $$\eqalign{ \def\bbR#1{{\mathbb R}^{#1}} \def\o{{\tt1}} \def\LR#1{\left(#1\right)} \def\op#1{\operatorname{#1}} \def\vecc#1{\op{vec}\LR{#1}} \def\trace#1{\op{Tr}\LR{#1}} \def\frob#1{\left\| #1 \right\|_F} \def\qiq{\quad\implies\quad} \def\p{\partial} \def\grad#1#2{\frac{\p #1}{\p #2}} \def\c#1{\color{red}{#1}} a &= \vecc{A} \:&\in\:&\bbR{n^2} \\\ J &= \grad{a}{s} \:&\in\:&\bbR{n^2\times n}\quad&\{ {\,\rm Jacobian\,} \} \\ da &= J\:ds &&&\{ {\,\rm differential\,} \} \\ }$$ Now the gradient calculation will not involve any tensors $$\eqalign{ y &= As \\ dy &= A\:ds + I_ndA\:s \\ &= A\:ds + \LR{s^T\otimes I_n}da \\ &= \LR{A + \LR{s^T\otimes I_n}J}ds \\ \grad{y}{s} &= A + \LR{s^T\otimes I_n}J \\ }$$ where $I_n$ is the identity matrix and $\otimes$ is the Kronecker product.