Linear least squares with quadratic equality constraint I would like to use linear least squares to solve for $x \in \mathbb{R}^5$ where
$$ Ax = b \rightarrow x = (A^TA)^{-1}A^Tb $$
but would like to include the constraint
$$ x_1^2 + x_2^2 = 1 $$
I looked around and found a few examples of how to solve using linear constraints of the form
$$ Cx = d$$
but unsure how to continue with quadratic constraints. Thanks!
 A: Quadratic optimization over a single quadratic constraint is a classical problem. One way to address it in a global fashion is to employ a semidefinite relaxation, which can be shown to be tight in this special case (also called a lossless application of the S-procedure)
One reference out of many
http://arxiv.org/abs/1312.1400
Here is some MATLAB reference code to setup and solve the semidefinite relaxation (called moment relaxation sometimes). It assumues you have the modelling toolbox YALMIP installed (disclaimer, developed by me), and a semidefinite solver, such as sedumi, sdpt3, mosek.
A = randn(10,5);
b = rand(10,1);
x = sdpvar(5,1);

p = (A*x-b)'*(A*x-b);
h = 1-x(1)^2-x(2)^2;

[diagnostics,xhat] = solvemoment(h == 0,p)
xhat{1}

The semidefinite relaxation boils down to a generalized eigenvalue problem in this case, so a general semidefinite programming approach might be a bit of an overkill, but it is convenient and fast enough (~0.1s) unless you have to solve many of these.
Having said that, this problem is also small enough to be easily solved using a standard global nonlinear solver, such as baron, scip or bmibnb in YALMIP.
 optimize(h == 0,p,sdpsettings('solver','bmibnb'))
 value(x)

