# DeleteDuplicates in FindRoot with more than one variable

I'm solving a system of 3 non-linear equations with FindRoot for the variables x, y and K, and I'm doing this in a Table so that I can give dfferent initial conditions.

But then, of course I get lots of repeated solutions.

The first thing I'm doing to get rid of imaginary solutions and also of solutions where $$K$$ is negative is

selection1 = Select[myList, ((x /. #) \[Element] Reals) && ((K /. #) \[Element] Reals) && ((y /. #) \[Element] Reals) && ((Kext /. #) > 0) &]


and now I want to eliminate repeated solutions. After doing

DeleteDuplicates[selection1, Equal[##] &]


it doesn't do great thing, so I think the best way would be to do what has been proposed here, i.e., something like

DeleteDuplicates[m, Abs[#1 - #2] < 10^-10 &]


but this only works when there is one variable. However my List selection1 is of the type {{x->1., y->2., z->3.}, {x->1., y->2., z->3.}, ...}, and I want to apply the criterium Abs[#1 - #2] < 10^-10 to x, y and K.

PS: In terms of performance I'm not sure if the way I'm doing the first selection is the appropriate one (maybe I should provide already those conditions in the FindRoot comand? However I think that's only possible when using NSolve though...).

• is this work? DeleteDuplicates[myList, And @@ ((Abs[#1 - #2] < 10^-10 &) @@@ Thread[List[Values@#1, Values@#2]]) &] – Xminer Mar 24 at 19:22

## 1 Answer

Let's say,we have the following data.

myList = Table[
Thread[Rule[{x, y, k},
Table[First@RandomChoice[Range[-3, 3], 1] +
If[RandomReal > 0.9, 1, 0]*I*
RandomChoice[Range[1, 3]], {3}]]], {10}]


{{x -> 1 + 3 I, y -> 0, k -> 2}, {x -> 0, y -> -2, k -> 3}, {x -> -2, y -> 0, k -> 2}, {x -> 0, y -> 3, k -> 3}, {x -> 2, y -> -1 + 2 I,
k -> 0}, {x -> -3, y -> -2, k -> 1}, {x -> 1 + 2 I, y -> -1, k -> 0}, {x -> 2, y -> 1, k -> -1}, {x -> -3, y -> 3, k -> 1}, {x -> -1, y -> 0, k -> 1}}

So Let's fix the way you hope.

selection1 =
Select[myList, (And @@
List @@ (Thread[Element[Values@#, Reals]] &) /@ # &)@# &] //
Select[#, (k /. #) >= 0 &] &

{{x -> 0, y -> -2, k -> 3}, {x -> -2, y -> 0, k -> 2}, {x -> 0,
y -> 3, k -> 3}, {x -> -3, y -> -2, k -> 1}, {x -> -3, y -> 3,
k -> 1}, {x -> -1, y -> 0, k -> 1}}


Finally,Removing duplicated result.

DeleteDuplicates[selection1,
And @@ ((Abs[#1 - #2] < 10^-10 &) @@@
Thread[List[Values@#1, Values@#2]]) &]


{{x -> 0, y -> -2, k -> 3}, {x -> -2, y -> 0, k -> 2}, {x -> 0, y -> 3, k -> 3}, {x -> -3, y -> -2, k -> 1}, {x -> -3, y -> 3, k -> 1}, {x -> -1, y -> 0, k -> 1}}