If

The error will be smallest when both

and

This gives you two non linear equations to solve for x1 and x2. You can use Newton's method for a system of equations to get an approximate solution (by approximate I mean the estimation will converge to the true solution but will unlikely every reach the solution so you can get very very close if you repeat the procedure enough times).