No, the first line is not equivalent to what you claim in the text, I believe: that's one linear system containing a subtraction and not two separate linear systems.
In detail, the matrix of this linear system is obtained by concatenating horizontally M = real(A)
and N = imag(A(:,2:n+1))
. If you split the unknown into
$$
c = \begin{bmatrix}
a\\-b
\end{bmatrix}
$$
then this linear system is
$$
f =
\begin{bmatrix}M & N\end{bmatrix}
\begin{bmatrix}
a\\-b
\end{bmatrix}
=
Ma - Nb,
$$
which corresponds to your first formula. But, ultimately, you are solving one linear system with matrix $\begin{bmatrix} M & N\end{bmatrix}$. The instruction [real(A) imag(A(:,2:n+1))]
stacks matrices one next to the another; it is not a "vectorized" syntax to solve two linear systems with different matrices and the same RHS.
I suspect that's the source of the issue (and, also, possibly, not solving the linear system in the least-squares sense.)