How to solve a system of quadratic equations