How to select only one solution from infinite list

Using NSolveValues on certain equations returns lists of solutions of the following kind:

For each of these rules I want to select only one value, namely the one absolutely closest to $$2\pi/10$$, but without selecting this manually. How would I find this?

Edit:
I have many of these equations which depend on a lot of different parameters, so I won't put all of that here. But the point is that I want to solve a large number of equations iteratively, where each equation depends on the solution of the previous one. However each equation results in a list ofinfinite solutions as above, but I only want to use the solution that is absolutely nearest to $$2\pi/10$$.

f[x_]:=ArcCos[0.5 (-0.00756467 +
0.749491 (0.287778 Cos[45. x] - 0.876915 Sin[45. x]) +
0.503279 (0.457042 Cos[45. x] - 0.227498 Sin[45. x]) +
0.538571 (0.876915 Cos[45. x] + 0.287778 Sin[45. x]) +
0.430085 (0.841604 Cos[45. x] + 0.423397 Sin[45. x]) -
0.0857465 (0.227498 Cos[45. x] + 0.457042 Sin[45. x]) -
0.838206 (-0.423397 Cos[45. x] +
0.841604 Sin[45. x]))] ((0.566265 (0. +
0.503279 (0.287778 Cos[45. x] - 0.876915 Sin[45. x]) -
0.749491 (0.457042 Cos[45. x] - 0.227498 Sin[45. x]) -
0.0857465 (0.876915 Cos[45. x] + 0.287778 Sin[45. x]) -
0.538571 (0.227498 Cos[45. x] +
0.457042 Sin[45. x])))/(\[Sqrt](Abs[
0. + 0.503279 (0.287778 Cos[45. x] - 0.876915 Sin[45. x]) -
0.749491 (0.457042 Cos[45. x] - 0.227498 Sin[45. x]) -
0.0857465 (0.876915 Cos[45. x] + 0.287778 Sin[45. x]) -
0.538571 (0.227498 Cos[45. x] + 0.457042 Sin[45. x])]^2 +
Abs[0.112051 +
0.430085 (0.457042 Cos[45. x] - 0.227498 Sin[45. x]) -
0.503279 (0.841604 Cos[45. x] + 0.423397 Sin[45. x]) -
0.838206 (0.227498 Cos[45. x] + 0.457042 Sin[45. x]) +
0.0857465 (-0.423397 Cos[45. x] + 0.841604 Sin[45. x])]^2 +
Abs[0.050167 -
0.430085 (0.287778 Cos[45. x] - 0.876915 Sin[45. x]) +
0.838206 (0.876915 Cos[45. x] + 0.287778 Sin[45. x]) +
0.749491 (0.841604 Cos[45. x] + 0.423397 Sin[45. x]) +
0.538571 (-0.423397 Cos[45. x] +
0.841604 Sin[45. x])]^2)) + (0.336803 (0.112051 +
0.430085 (0.457042 Cos[45. x] - 0.227498 Sin[45. x]) -
0.503279 (0.841604 Cos[45. x] + 0.423397 Sin[45. x]) -
0.838206 (0.227498 Cos[45. x] + 0.457042 Sin[45. x]) +
0.0857465 (-0.423397 Cos[45. x] +
0.841604 Sin[45. x])))/(\[Sqrt](Abs[
0. + 0.503279 (0.287778 Cos[45. x] - 0.876915 Sin[45. x]) -
0.749491 (0.457042 Cos[45. x] - 0.227498 Sin[45. x]) -
0.0857465 (0.876915 Cos[45. x] + 0.287778 Sin[45. x]) -
0.538571 (0.227498 Cos[45. x] + 0.457042 Sin[45. x])]^2 +
Abs[
0.112051 +
0.430085 (0.457042 Cos[45. x] - 0.227498 Sin[45. x]) -
0.503279 (0.841604 Cos[45. x] + 0.423397 Sin[45. x]) -
0.838206 (0.227498 Cos[45. x] + 0.457042 Sin[45. x]) +
0.0857465 (-0.423397 Cos[45. x] + 0.841604 Sin[45. x])]^2 +
Abs[0.050167 -
0.430085 (0.287778 Cos[45. x] - 0.876915 Sin[45. x]) +
0.838206 (0.876915 Cos[45. x] + 0.287778 Sin[45. x]) +
0.749491 (0.841604 Cos[45. x] + 0.423397 Sin[45. x]) +
0.538571 (-0.423397 Cos[45. x] +
0.841604 Sin[45. x])]^2)) - (0.752268 (0.050167 -
0.430085 (0.287778 Cos[45. x] - 0.876915 Sin[45. x]) +
0.838206 (0.876915 Cos[45. x] + 0.287778 Sin[45. x]) +
0.749491 (0.841604 Cos[45. x] + 0.423397 Sin[45. x]) +
0.538571 (-0.423397 Cos[45. x] +
0.841604 Sin[45. x])))/(\[Sqrt](Abs[
0. + 0.503279 (0.287778 Cos[45. x] - 0.876915 Sin[45. x]) -
0.749491 (0.457042 Cos[45. x] - 0.227498 Sin[45. x]) -
0.0857465 (0.876915 Cos[45. x] + 0.287778 Sin[45. x]) -
0.538571 (0.227498 Cos[45. x] + 0.457042 Sin[45. x])]^2 +
Abs[0.112051 +
0.430085 (0.457042 Cos[45. x] - 0.227498 Sin[45. x]) -
0.503279 (0.841604 Cos[45. x] + 0.423397 Sin[45. x]) -
0.838206 (0.227498 Cos[45. x] + 0.457042 Sin[45. x]) +
0.0857465 (-0.423397 Cos[45. x] + 0.841604 Sin[45. x])]^2 +
Abs[0.050167 -
0.430085 (0.287778 Cos[45. x] - 0.876915 Sin[45. x]) +
0.838206 (0.876915 Cos[45. x] + 0.287778 Sin[45. x]) +
0.749491 (0.841604 Cos[45. x] + 0.423397 Sin[45. x]) +
0.538571 (-0.423397 Cos[45. x] + 0.841604 Sin[45. x])]^2)))

NSolveValues[f[x] == 2 \[Pi]/10, x, Reals]

• Can you put the code that produced this result? Commented Dec 9, 2021 at 9:57
• @polfosol Thank you for your comment, please see my edit. Commented Dec 9, 2021 at 10:04
• Also I was thinking about using something like NearestTo, but that doesn't work for the kind of object that I have from NSolveValues. Commented Dec 9, 2021 at 10:08
• What is the meaning of argument 45. x ? Commented Dec 9, 2021 at 10:28
• You could try to give an additional constrain like: NSolveValues[{f[x] == 2 \[Pi]/10, (x - 2 Pi/10)^2 < .005}, x] Commented Dec 9, 2021 at 10:49

If I understand you right, you are looking for a solution f[x]==2Pi/10 with constraint (x-2Pi/10)^2 minimal?

Try NMinimize

 mini=NMinimize[{(x - 2 Pi/10)^2, f[x] == 2 Pi/10}, x]
(*{0.0327761, {x -> 0.80936}}*)

• Thank you for your answer, I tried it however it as you say it give 0.80936, but there is another solution of f[x]==2Pi/10, which is 0.669734. Shouldn't it return that instead? Commented Dec 9, 2021 at 10:33
• Interessting, don't know why! If you restrict the solution range mini = NMinimize[{(x - 2 Pi/10)^2, f[x] == 2 Pi/10, 0.6 < x < 1 }, x ] the correct result follows Commented Dec 9, 2021 at 10:53
• Or FindRoot[f[x] == 2 Pi/10, {x, 2 Pi/10}]  seems to be more reliable. Commented Dec 9, 2021 at 15:48

Since the desired root is near 2Pi/10 use FindRoot with an initial estimate of 2Pi/10

Clear["Global*"]

f[x_] = ArcCos[
0.5 (-0.00756467 +
0.749491 (0.287778 Cos[45. x] - 0.876915 Sin[45. x]) +
0.503279 (0.457042 Cos[45. x] - 0.227498 Sin[45. x]) +
0.538571 (0.876915 Cos[45. x] + 0.287778 Sin[45. x]) +
0.430085 (0.841604 Cos[45. x] + 0.423397 Sin[45. x]) -
0.0857465 (0.227498 Cos[45. x] + 0.457042 Sin[45. x]) -
0.838206 (-0.423397 Cos[45. x] +
0.841604 Sin[45. x]))] ((0.566265 (0. +
0.503279 (0.287778 Cos[45. x] - 0.876915 Sin[45. x]) -
0.749491 (0.457042 Cos[45. x] - 0.227498 Sin[45. x]) -
0.0857465 (0.876915 Cos[45. x] + 0.287778 Sin[45. x]) -
0.538571 (0.227498 Cos[45. x] +
0.457042 Sin[45. x])))/(\[Sqrt](Abs[
0. + 0.503279 (0.287778 Cos[45. x] - 0.876915 Sin[45. x]) -
0.749491 (0.457042 Cos[45. x] - 0.227498 Sin[45. x]) -
0.0857465 (0.876915 Cos[45. x] + 0.287778 Sin[45. x]) -
0.538571 (0.227498 Cos[45. x] + 0.457042 Sin[45. x])]^2 +
Abs[
0.112051 +
0.430085 (0.457042 Cos[45. x] - 0.227498 Sin[45. x]) -
0.503279 (0.841604 Cos[45. x] + 0.423397 Sin[45. x]) -
0.838206 (0.227498 Cos[45. x] + 0.457042 Sin[45. x]) +
0.0857465 (-0.423397 Cos[45. x] + 0.841604 Sin[45. x])]^2 +
Abs[
0.050167 -
0.430085 (0.287778 Cos[45. x] - 0.876915 Sin[45. x]) +
0.838206 (0.876915 Cos[45. x] + 0.287778 Sin[45. x]) +
0.749491 (0.841604 Cos[45. x] + 0.423397 Sin[45. x]) +
0.538571 (-0.423397 Cos[45. x] +
0.841604 Sin[45. x])]^2)) + (0.336803 (0.112051 +
0.430085 (0.457042 Cos[45. x] - 0.227498 Sin[45. x]) -
0.503279 (0.841604 Cos[45. x] + 0.423397 Sin[45. x]) -
0.838206 (0.227498 Cos[45. x] + 0.457042 Sin[45. x]) +
0.0857465 (-0.423397 Cos[45. x] +
0.841604 Sin[45. x])))/(\[Sqrt](Abs[
0. + 0.503279 (0.287778 Cos[45. x] - 0.876915 Sin[45. x]) -
0.749491 (0.457042 Cos[45. x] - 0.227498 Sin[45. x]) -
0.0857465 (0.876915 Cos[45. x] + 0.287778 Sin[45. x]) -
0.538571 (0.227498 Cos[45. x] + 0.457042 Sin[45. x])]^2 +
Abs[
0.112051 +
0.430085 (0.457042 Cos[45. x] - 0.227498 Sin[45. x]) -
0.503279 (0.841604 Cos[45. x] + 0.423397 Sin[45. x]) -
0.838206 (0.227498 Cos[45. x] + 0.457042 Sin[45. x]) +
0.0857465 (-0.423397 Cos[45. x] + 0.841604 Sin[45. x])]^2 +
Abs[
0.050167 -
0.430085 (0.287778 Cos[45. x] - 0.876915 Sin[45. x]) +
0.838206 (0.876915 Cos[45. x] + 0.287778 Sin[45. x]) +
0.749491 (0.841604 Cos[45. x] + 0.423397 Sin[45. x]) +
0.538571 (-0.423397 Cos[45. x] +
0.841604 Sin[45. x])]^2)) - (0.752268 (0.050167 -
0.430085 (0.287778 Cos[45. x] - 0.876915 Sin[45. x]) +
0.838206 (0.876915 Cos[45. x] + 0.287778 Sin[45. x]) +
0.749491 (0.841604 Cos[45. x] + 0.423397 Sin[45. x]) +
0.538571 (-0.423397 Cos[45. x] +
0.841604 Sin[45. x])))/(\[Sqrt](Abs[
0. + 0.503279 (0.287778 Cos[45. x] - 0.876915 Sin[45. x]) -
0.749491 (0.457042 Cos[45. x] - 0.227498 Sin[45. x]) -
0.0857465 (0.876915 Cos[45. x] + 0.287778 Sin[45. x]) -
0.538571 (0.227498 Cos[45. x] + 0.457042 Sin[45. x])]^2 +
Abs[
0.112051 +
0.430085 (0.457042 Cos[45. x] - 0.227498 Sin[45. x]) -
0.503279 (0.841604 Cos[45. x] + 0.423397 Sin[45. x]) -
0.838206 (0.227498 Cos[45. x] + 0.457042 Sin[45. x]) +
0.0857465 (-0.423397 Cos[45. x] + 0.841604 Sin[45. x])]^2 +
Abs[
0.050167 -
0.430085 (0.287778 Cos[45. x] - 0.876915 Sin[45. x]) +
0.838206 (0.876915 Cos[45. x] + 0.287778 Sin[45. x]) +
0.749491 (0.841604 Cos[45. x] + 0.423397 Sin[45. x]) +
0.538571 (-0.423397 Cos[45. x] + 0.841604 Sin[45. x])]^2))) //
Rationalize[#, 0] & // Simplify

(* -((ArcCos[(1/
2000000000000)(-7564670000 + 1615335655046 Cos[45 x] -
1179276556501 Sin[45 x])] (-84197000000 +
1139633204749573157 Cos[45 x] +
1561033413550243039 Sin[45 x]))/(500000 \[Sqrt](Abs[
224102000000 - 907979420789 Cos[45 x] - 1243722090718 Sin[45 x]]^2 +
Abs[790864917931 Cos[45 x] + 1083301448052 Sin[45 x]]^2 +
4 Abs[
50167000000 + 1014011691237 Cos[45 x] +
1388960982854 Sin[45 x]]^2))) *)


Solving,

sol = FindRoot[f[x] == 2 Pi/10, {x, 2 Pi/10}]

(* {x -> 0.669734} *)


Graphically,

Plot[f[x] - 2 Pi/10, {x, 0.4, 0.9},
PlotPoints -> 200,
MaxRecursion -> 5,
GridLines -> {{2 Pi/10}, None},
GridLinesStyle -> Directive[Gray, Thick, Dashed],
Epilog -> {Red, AbsolutePointSize[4], Point[{x /. sol, 0}]}]
`