Of course, the simple answer to this question is you are trying to use the wrong algorithm.
If you want to find the vector a, such that a'*inv(M(x))*a is maximized, then you want to work with the eigenvectors of the matrix M. That is, the vector you want to find is simply the eigenvector corresponding to the SMALLEST eigenvalue of M. If M is singular, then ANY eigenvector that lives in the nullspace of M will suffice. (In case there are multiple effectively zero eigenvalues.)
But there is no optimization needed.
