2
$\begingroup$

I have the following transcendental equation:

$$2 \cot(x)=\frac{kx}{h(L/N)}-\frac{h(L/N)}{kx}$$

I use the following code to solve it

roots = 
  Sort[x /. 
    NSolve[
      {2*Cot[x] == Rationalize[k/(h (L/N))] x - Rationalize[h (L/N)/k]/x, 60 > x > 0}, 
      x, Reals]]

Typical values for the constants are $L=0.25,N=20,k=16,h=0.1$:

Is there an alternative way to solve this equation and check whether the answers from both the methods match?


FindInstance[2*Cot[x] == (k x)/(h (L/Nd)) - h (L/Nd)/(k x), {x}, Reals, 10]

leads to

{{x -> -0.0124999}, {x -> -0.0124999}, {x -> 0.0124999}, {x -> 0.0124999}, 
{x -> 0.0124999}, {x -> -0.0124999}, {x -> -0.0124999}, {x -> 0.0124999}, 
{x -> -0.0124999}, {x -> 0.0124999}}
$\endgroup$
  • 1
    $\begingroup$ FindInstance $\endgroup$ – LouisB Dec 27 '19 at 8:20
  • $\begingroup$ @LouisB I tried FindInstance but it manages to find only one root. This root matches with theNSolve result. Is there a workaround to this ? Like if I only want positive roots. Giving the argument to FindInstance for 10 roots leads to repeated roots. I have added my attempt to the original question. $\endgroup$ – Indrasis Mitra Dec 27 '19 at 9:56
  • 2
    $\begingroup$ Try it this way FindInstance[ { 2*Cot[x] == k/(h (L/Nd)) x - h (L/Nd)/k/x, 60 > x > 0 }, x, Reals, 30] $\endgroup$ – LouisB Dec 27 '19 at 10:12
  • $\begingroup$ @LouisB Thanks. It works perfectly. If you can add this as an answer, I am willing to accept it. It solves my problem. $\endgroup$ – Indrasis Mitra Dec 27 '19 at 10:15
1
$\begingroup$
Clear["Global`*"]

roots[Lv_?NumericQ, nv_?NumericQ, kv_?NumericQ, hv_?NumericQ] := 
 Module[{L, n, k, h},
  {L, n, k, h} = Rationalize[{Lv, nv, kv, hv}, 0]; Solve[{
    2*Cot[x] == k/(h (L/n)) x - h (L/n)/k/x,
    60 > x > 0}, x, Reals]]

The exact solutions are Root objects

sol1 = roots[0.25, 20, 16, 0.1]

enter image description here

These are approximately

sol1 // N

(* {{x -> 0.0124999}, {x -> 3.14164}, {x -> 6.28321}, {x -> 9.42479}, {x -> 
   12.5664}, {x -> 15.708}, {x -> 18.8496}, {x -> 21.9912}, {x -> 
   25.1327}, {x -> 28.2743}, {x -> 31.4159}, {x -> 34.5575}, {x -> 
   37.6991}, {x -> 40.8407}, {x -> 43.9823}, {x -> 47.1239}, {x -> 
   50.2655}, {x -> 53.4071}, {x -> 56.5487}, {x -> 59.6903}} *)

You can verify the solutions by substituting back into the equations

2*Cot[x] == k/(h (L/n)) x - h (L/n)/k/x &&
    60 > x > 0 /. 
   Thread[{L, n, k, h} ->
     Rationalize[{0.25, 20, 16, 0.1}]] /.
  sol1 // FullSimplify

(* {True, True, True, True, True, True, True, True, True, True, True, True, \
True, True, True, True, True, True, True, True} *)

Using FindInstance as the second method

roots2[Lv_?NumericQ, nv_?NumericQ, kv_?NumericQ, hv_?NumericQ, 
  nmbr_Integer?Positive] := Module[{L, n, k, h},
  {L, n, k, h} = Rationalize[{Lv, nv, kv, hv}, 0];
  FindInstance[
   2*Cot[x] == k/(h (L/n)) x - h (L/n)/k/x &&
    60 > x > 0, x, Reals, nmbr]]

sol2 = roots2[0.25, 20, 16, 0.1, Length[sol1]];

Verifying that the exact solutions are identical

sol1 === sol2

(* True *)
$\endgroup$
  • $\begingroup$ Thanks. This was very descriptive. $\endgroup$ – Indrasis Mitra Dec 28 '19 at 4:40
4
$\begingroup$

Your equation might be transformed to 2 Cot[x] == x/p - p/x with a new parameter p= (h (L/n) )/k

With

p0=(h (L/n) )/k /. {L -> 0.25, n -> 20, k -> 16, h -> 0.1};
(*0.000078125*)

you might visualize the solution with ContourPlot

ContourPlot[ContourPlot[1/(2 Cot[x]) == 1/((x/p) - p/x), {x, 0, 60}, {p, 0, 2 p0},FrameLabel -> {x,"p=\!\(\*FractionBox[\(\(h\)\(\\\ \)\((L/n)\)\(\\\ \)\), \\(k\)]\)"}], {x, 0, .01 Pi /2}, {p, 0, 2 p0}, 
FrameLabel -> {x,"p=\!\(\*FractionBox[\(\(h\)\(\\\ \)\((L/n)\)\(\\\ \)\), \\(k\)]\)"}]

enter image description here

The solution for given p=p0follow to

NSolve[{2 Cot[x] == x/p0 - p0/x, 0 < x < 60}, x, Reals]
(*{{x -> 0.0124999}, {x -> 3.14164}, {x -> 6.28321}, {x ->9.42479}, {x -> 12.5664}, {x -> 15.708}, {x -> 18.8496}, {x ->21.9912}, {x -> 25.1327}, {x -> 28.2743}, {x -> 31.4159}, {x ->34.5575}, {x -> 37.6991}, {x -> 40.8407}, {x -> 43.9823}, {x ->47.1239}, {x -> 50.2655}, {x -> 53.4071}, {x -> 56.5487}, {x ->59.6903}}*)  
$\endgroup$
  • $\begingroup$ Thanks for the visualizations. I was already using NSolve to find the roots and was looking for an alternative. $\endgroup$ – Indrasis Mitra Dec 28 '19 at 3:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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