Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

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

1 Answer 1

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 of 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]}} *)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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