2
$\begingroup$

I was trying to solve a polarization problem where I needed to solve this transcendental equation.

NSolve[(Cos[\[Pi]/n])^(2 n) == 0.90, n]

I don't know why but Mathematica is taking a very long time trying to solve it while Desmos gives the answer instantly. What should I do to speed it up?

$\endgroup$

2 Answers 2

6
$\begingroup$

If you give a range for n NSolve evaluates all solutions immediately:

NSolve[{(Cos[\[Pi]/n])^(2 n) == 0.90, 0 < n < 1}, n, Reals]

{{n -> 0.000444741}, {n -> 0.000460511}, {n -> 0.00134138}, {n -> 0.00169924}, {n -> 0.00223964}, {n -> 0.00294551}, {n -> 0.00330579}, {n -> 0.00391389}, {n -> 0.004158}, {n -> 0.00468384}, {n -> 0.00519481}, {n -> 0.0056338}, {n -> 0.00573066}, {n -> 0.00677965}, {n -> 0.00754719}, {n -> 0.0079681}, {n -> 0.0081633}, {n -> 0.00947856}, {n -> 0.00995041}, {n -> 0.0102562}, {n -> 0.0112998}, {n -> 0.0114282}, {n -> 0.0130729}, {n -> 0.013244}, {n -> 0.0146004}, {n -> 0.0152648}, {n -> 0.016003}, {n -> 0.0162569}, {n -> 0.0165325}, {n -> 0.0168028}, {n -> 0.0173867}, {n -> 0.0177042}, {n -> 0.0180125}, {n -> 0.0183547}, {n -> 0.018685}, {n -> 0.0190549}, {n -> 0.0194095}, {n -> 0.0198107}, {n -> 0.0201925}, {n -> 0.0206291}, {n -> 0.0210411}, {n -> 0.0215181}, {n -> 0.021964}, {n -> 0.0224874}, {n -> 0.0229715}, {n -> 0.0235483}, {n -> 0.0240756}, {n -> 0.0247145}, {n -> 0.025291}, {n -> 0.0260025}, {n -> 0.0266353}, {n -> 0.0274324}, {n -> 0.0281301}, {n -> 0.0290293}, {n -> 0.0298022}, {n -> 0.0308242}, {n -> 0.0316849}, {n -> 0.0328564}, {n -> 0.0338209}, {n -> 0.0351763}, {n -> 0.0362645}, {n -> 0.0378501}, {n -> 0.0390874}, {n -> 0.0409654}, {n -> 0.0423851}, {n -> 0.0446417}, {n -> 0.0462881}, {n -> 0.049046}, {n -> 0.0509793}, {n -> 0.0544189}, {n -> 0.0567238}, {n -> 0.0611202}, {n -> 0.0639201}, {n -> 0.0697138}, {n -> 0.0731964}, {n -> 0.0811357}, {n -> 0.0856037}, {n -> 0.0970629}, {n -> 0.103043}, {n -> 0.120829}, {n -> 0.129337}, {n -> 0.160146}, {n -> 0.173482}, {n -> 0.237862}, {n -> 0.262804}, {n -> 0.465417}, {n -> 0.53725}}

$\endgroup$
4
  • $\begingroup$ Nice. There is one more solution at n == 93.6922 you can get with NSolve[{(Cos[\[Pi]/n])^(2 n)==0.90,n>1},n,Reals]. It looks like there are none for n<0 $\endgroup$ Commented Jul 30, 2020 at 8:43
  • $\begingroup$ Thanks for your hint. Probably there are more solutions near n->0 $\endgroup$ Commented Jul 30, 2020 at 9:03
  • $\begingroup$ Actually, I don't think this is all solutions. If you do, e.g., 0 < n < 0.1 you get even more solutions. There's probably an infinite number of them. $\endgroup$ Commented Jul 30, 2020 at 14:38
  • $\begingroup$ Indeed, LogLinearPlot[Cos[\[Pi]/x]^(2 x), {x, 0, 10}] shows that there is an infinite number of solutions, which shouldn't be surprising, as Cos[π/x] has an essential singularity. $\endgroup$
    – evanb
    Commented Jul 30, 2020 at 15:52
4
$\begingroup$

Re Ulrich's comment that there are probably more solutions as n approaches zero.

Length[sol = Join[
   NSolve[{(Cos[π/n])^(2 n) == 9/10, 0 <= n <= 1}, n, Reals, 
    WorkingPrecision -> 40],
   NSolve[{(Cos[π/n])^(2 n) == 9/10, n > 1}, n, Reals, 
    WorkingPrecision -> 40]]]

(* 86 *)

({min, max} = MinMax[sol[[All, 1, -1]]]) // N

(* {0.00134138, 93.6922} *)

Looking in the region {0, min}

Length[sol2 = 
  NSolve[{(Cos[π/n])^(2 n) == 9/10, 0 <= n <= min}, n, Reals, 
   WorkingPrecision -> 40]]

(* 967 *)

({min2, max2} = MinMax[sol2[[All, 1, -1]]]) // N

(* {2.40645*10^-6, 0.00134138} *)

Zooming in again,

Length[sol3 = 
  NSolve[{(Cos[π/n])^(2 n) == 9/10, 0 <= n <= min2}, n, Reals, 
   WorkingPrecision -> 40]]

(* 831 *)

and so on ...

$\endgroup$

Your Answer

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

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