2
$\begingroup$

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

$\endgroup$
5
  • 1
    $\begingroup$ Check the warning message given by NSolve. $\endgroup$ May 21, 2014 at 23:45
  • $\begingroup$ 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? $\endgroup$ May 22, 2014 at 0:47
  • $\begingroup$ Offhand I'm not sure. Will give it some thought. $\endgroup$ May 22, 2014 at 1:26
  • $\begingroup$ It's in the documentation for NSolve -- How many solutions do you want (of the infinitely many)? $\endgroup$
    – Michael E2
    May 22, 2014 at 1:27
  • $\begingroup$ A closely related question and an answer can be found here: Issue with NSolve. $\endgroup$
    – Artes
    May 22, 2014 at 8:19

1 Answer 1

5
$\begingroup$

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[21]= {{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[20]= {{p1 -> -(Sqrt[(3/2)]/2) + 1/(2 Sqrt[2]), 
  q1 -> -(Sqrt[(3/2)]/2) - 1/(2 Sqrt[2]), 
  p2 -> -(Sqrt[(3/2)]/2) - 1/(2 Sqrt[2]), 
  q2 -> -(Sqrt[(3/2)]/2) + 1/(2 Sqrt[2]), 
  x -> -Sqrt[(3/2)]}, {p1 -> -(Sqrt[(3/2)]/2) - 1/(2 Sqrt[2]), 
  q1 -> -(Sqrt[(3/2)]/2) + 1/(2 Sqrt[2]), 
  p2 -> -(Sqrt[(3/2)]/2) + 1/(2 Sqrt[2]), 
  q2 -> -(Sqrt[(3/2)]/2) - 1/(2 Sqrt[2]), 
  x -> -Sqrt[(3/2)]}, {p1 -> Sqrt[3/2]/2 + 1/(2 Sqrt[2]), 
  q1 -> Sqrt[3/2]/2 - 1/(2 Sqrt[2]), 
  p2 -> Sqrt[3/2]/2 - 1/(2 Sqrt[2]), 
  q2 -> Sqrt[3/2]/2 + 1/(2 Sqrt[2]), 
  x -> Sqrt[3/2]}, {p1 -> Sqrt[3/2]/2 - 1/(2 Sqrt[2]), 
  q1 -> Sqrt[3/2]/2 + 1/(2 Sqrt[2]), 
  p2 -> Sqrt[3/2]/2 + 1/(2 Sqrt[2]), 
  q2 -> Sqrt[3/2]/2 - 1/(2 Sqrt[2]), x -> Sqrt[3/2]}} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.