1
$\begingroup$
l1 = 0.167;
l2 = 0.078596;
θ = π/18;

NSolve[θ == ArcTan[(1/Sqrt[k] Sin[Sqrt[k] l1] + 
            l2 Cos[Sqrt[k] l1])/(-l2 Sqrt[k] Sin[Sqrt[k] l1] + 
            Cos[Sqrt[k] l1])], k]

How to get the solution of the following above?

$\endgroup$
  • $\begingroup$ suggest you plot θ - ArcTan, you'll see you have many roots. FindRoot gives you one at a time. $\endgroup$ – george2079 Jul 14 '15 at 21:01
2
$\begingroup$

There may infinitely many solutions. This will find some, if you limit the range on k:

Block[{θ = π/18, l1 = 0.167, l2 = 0.078596},
 NSolve[θ == 
    ArcTan[(1/Sqrt[k] Sin[Sqrt[k] l1] + 
        l2 Cos[Sqrt[k] l1])/(-l2 Sqrt[k] Sin[Sqrt[k] l1] + 
        Cos[Sqrt[k] l1])] && 0 < k < 10000, k]
 ]

Solve::ratnz: Solve was unable to solve the system with inexact coefficients. The answer was obtained by solving a corresponding exact system and numericizing the result. >>

(* {{k -> 421.101}, {k -> 1494.26}, {k -> 3266.71}, {k -> 5745.09}, {k -> 8930.65}} *)

There is a negative root that is hard for NSolve to find. If we use FindRoot, it's simple:

Block[{θ = π/18, l1 = 0.167, l2 = 0.078596},
 FindRoot[θ == 
   ArcTan[(1/Sqrt[k] Sin[Sqrt[k] l1] + 
       l2 Cos[Sqrt[k] l1])/(-l2 Sqrt[k] Sin[Sqrt[k] l1] + 
       Cos[Sqrt[k] l1])], {k, -50}]
 ]
(*  {k -> -21.7265 + 0. I}  *)

You can see one problem is that negative values of k make the function values complex. Note that I killed the corresponding NSolve command with the restriction -50 < k < 0 after several minutes when it had reached 6+GB of memory usage.

$\endgroup$
  • 1
    $\begingroup$ In FindRoot use l1 = 0.167`15, l2 = 0.078596`15 and WorkingPrecision->15 to remove complex result. $\endgroup$ – Bob Hanlon Jul 14 '15 at 23:48
  • $\begingroup$ @BobHanlon Neat. I didn't expect that. Usually once complex numbers arise, the stick around, even if the imaginary part comes out zero. $\endgroup$ – Michael E2 Jul 14 '15 at 23:52
  • $\begingroup$ I just ran your codes,but a problem occurred when I plug theta = pi/18 *10. Basically, I want to get the array of K value when theta is from pi/18*1, pi/18*2, ..., pi/18*18. $\endgroup$ – Lawerance Jul 16 '15 at 1:56
  • $\begingroup$ @Lawerance Since ArcTan for real arguments is "always in the range -Pi/2 to Pi/2" (docs), there should be no solutions when theta is Pi/18 * 10, which is what I get. $\endgroup$ – Michael E2 Jul 16 '15 at 3:32

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.