Given a matrix of $k \times n$ complex-valued $f_{ij}$ for $1 \leq i \leq k$ and $1 \leq j \leq n$. I would like to minimize the following cost function for real valued $g_i$:
$$ \sum_{j=1}^n \left( \left\vert \sum_{i=1}^k g_i f_{ij} \right\vert - 1 \right)^2. $$
What is the best way to formulate the optimization problem?
For example, in Matlab or Octave: