# why doesn't NSolve find all the solutions that Solve finds?

Define

d[p1_, p2_] := (p1 - p2).(p1 - p2)


to be the square of the distance between two points. I am trying to solve equations like:

Solve[{d[{p1, q1}, {0, 0}] == 1, d[{p2, q2}, {0, 0}] == 1, d[{p1, q1}, {p2, q2}] == 1,
d[{p2, q2}, {x, x}] == 1, d[{p1, q1}, {x, x}] == 1}, {p1, q1, p2, q2, x}]


I get 12 solutions. But when I approximate these solutions with:

NSolve[{d[{p1, q1}, {0, 0}] == 1, d[{p2, q2}, {0, 0}] == 1, d[{p1, q1}, {p2, q2}] == 1,
d[{p2, q2}, {x, x}] == 1, d[{p1, q1}, {x, x}] == 1}, {p1, q1, p2, q2, x}]


I only get 4 of the solutions.

What gives? For larger number of equations, it takes too long to use Solve[ ] and then N[ ] the result.

Erich

• Check the warning message given by NSolve. May 21, 2014 at 23:45
• The error message is: "NSolve::infsolns: Infinite solution set has dimension at least 1. Returning intersection of solutions with a random hyperplane". So when Solve[] has several solutions, and any one of them is an infinite family, NSolve[] only gives instances of the infinite families? That doesn't seem very useful. How do I get approximations of a system of equations and ignore the infinite families? May 22, 2014 at 0:47
• Offhand I'm not sure. Will give it some thought. May 22, 2014 at 1:26
• It's in the documentation for NSolve -- How many solutions do you want (of the infinitely many)? May 22, 2014 at 1:27
• A closely related question and an answer can be found here: Issue with NSolve. May 22, 2014 at 8:19

I can give a partial answer to this. That is to say, it's not a general approach but the idea could be used in some cases. What is necessary is to notice that we have, in essence (at least when restricting to real values), a gemoetry problem. We have points (p1,q1) and (p2,q2) on the unit circle and one unit apart from one another. So they, with the origin, give an equilateral triangle. Thus far we have two parametrized families of viable values, and they are identical up to swapping the two points. We now add the line y=x, and want to restrict our p's and q's, so to speak, to values that remain one unit from some point on this line. That gives a finite solution set, EXCEPT if we allow x to be zero, because then (x,x) corresponds to the third point on this parametrized family of equalateral triangles.

The way out of this is to add a variable and equation that forces x!=0. The standard approach is indicated in the code below.

NSolve[{d[{p1, q1}, {0, 0}] == 1, d[{p2, q2}, {0, 0}] == 1,
d[{p1, q1}, {p2, q2}] == 1, d[{p2, q2}, {x, x}] == 1,
d[{p1, q1}, {x, x}] == 1, x*xrecip == 1}, {p1, q1, p2, q2,
x}, {xrecip}]

(* Out= {{p1 -> -0.258819045103, q1 -> -0.965925826289,
p2 -> -0.965925826289, q2 -> -0.258819045103,
x -> -1.22474487139}, {p1 -> -0.965925826289, q1 -> -0.258819045103,
p2 -> -0.258819045103, q2 -> -0.965925826289,
x -> -1.22474487139}, {p1 -> 0.965925826289, q1 -> 0.258819045103,
p2 -> 0.258819045103, q2 -> 0.965925826289,
x -> 1.22474487139}, {p1 -> 0.258819045103, q1 -> 0.965925826289,
p2 -> 0.965925826289, q2 -> 0.258819045103, x -> 1.22474487139}} *)


Solve will do similarly with this restricted system.

Solve[{d[{p1, q1}, {0, 0}] == 1, d[{p2, q2}, {0, 0}] == 1,
d[{p1, q1}, {p2, q2}] == 1, d[{p2, q2}, {x, x}] == 1,
d[{p1, q1}, {x, x}] == 1, x*xrecip == 1}, {p1, q1, p2, q2,
x}, {xrecip}]

(* Out= {{p1 -> -(Sqrt[(3/2)]/2) + 1/(2 Sqrt),
q1 -> -(Sqrt[(3/2)]/2) - 1/(2 Sqrt),
p2 -> -(Sqrt[(3/2)]/2) - 1/(2 Sqrt),
q2 -> -(Sqrt[(3/2)]/2) + 1/(2 Sqrt),
x -> -Sqrt[(3/2)]}, {p1 -> -(Sqrt[(3/2)]/2) - 1/(2 Sqrt),
q1 -> -(Sqrt[(3/2)]/2) + 1/(2 Sqrt),
p2 -> -(Sqrt[(3/2)]/2) + 1/(2 Sqrt),
q2 -> -(Sqrt[(3/2)]/2) - 1/(2 Sqrt),
x -> -Sqrt[(3/2)]}, {p1 -> Sqrt[3/2]/2 + 1/(2 Sqrt),
q1 -> Sqrt[3/2]/2 - 1/(2 Sqrt),
p2 -> Sqrt[3/2]/2 - 1/(2 Sqrt),
q2 -> Sqrt[3/2]/2 + 1/(2 Sqrt),
x -> Sqrt[3/2]}, {p1 -> Sqrt[3/2]/2 - 1/(2 Sqrt),
q1 -> Sqrt[3/2]/2 + 1/(2 Sqrt),
p2 -> Sqrt[3/2]/2 + 1/(2 Sqrt),
q2 -> Sqrt[3/2]/2 - 1/(2 Sqrt), x -> Sqrt[3/2]}} *)