How can I express nonlinear function in matrix? Let the vector $\ell = \begin{pmatrix} \ell_1 \\ \ell_2 \\ \vdots \\ \ell_p \end{pmatrix}$, and the goal is to find a matrix which returns $\psi = \dfrac{\ell_1+\ell_2+\cdots+\ell_q}{\ell_1+\ell_2+\cdots+\ell_p}$, where $q \leq p.$
Is there any matrix $M$ such that $\ell M = \psi$?
 A: Multiplying a vector by a matrix, you perform some linear transformation. From linearity it follows that
$$
A(b+c)=Ab+Ac,
$$
where $A$ is a matrix and $b,c$ are vectors of the corresponding size.
Let $$ b = \begin{bmatrix} x_1 \\ y_1 \end{bmatrix}, \quad c = \begin{bmatrix} x_2 \\ y_2 \end{bmatrix}
$$
and the desired function $$\psi \left( \begin{bmatrix} x \\ y \end{bmatrix} \right) = \frac{x}{x+y}\;.$$
Then you have 
$$
\psi(b) = \frac{x_1}{x_1+y_1}, \quad \psi(c) = \frac{x_2}{x_2+y_2}, \quad \psi(b+c) = \frac{x_1+x_2}{x_1+x_2+y_1+y_2}.\\
$$
And in general
$$
\psi(b+c) \neq \psi(b)+\psi(c),$$
because the function $\psi$ is not linear. This means that this function cannot be represented as a one-side matrix multiplication.
A: Of course not, a matrix/vector product is always linear.
Using dot products with vector $1_k$ of $k$ ones followed by $p-k$ zeroes,
$$\psi=\frac{1_q\cdot\ell}{1_p\cdot\ell}.$$
Anyway, you can work with homogeneous coordinates, i.e. pairs $(u,v)$ such that $(u,v)\equiv(\lambda u,\lambda v)$ for any $\lambda\ne0$ and write
$$(u,v)=\ell\,[1_q\ 1_p]^T$$ and
$$(u,v)\equiv(\psi,1).$$
