1
$\begingroup$

I have the following equation:

2 a^2 k^2 Sin[b k] - 6 a (k Cos[b k] - Sin[b k]/b) == 0

I set the value of b to 1, and I want to plot the value of k as it ranges over 0.01 to 6.0 in increments of 0.01.

When the above equation becomes zero for some value of a, I want to print the value of k. Later I will plot k as a function of ratio a/b.

This is a general question, but I am struggling with the logic can to solve this.

Do I put it in a loop?

xxx = 2 a^2 k^2 Sin[b k] - 6 a (k Cos[b k] - Sin[b k]/b)
b = 1;
Do[If[xxx == 0, {Print[k], Print[a]}, Continue[]], {a, 0.01, 6, 0.01}]

Thanks

$\endgroup$
  • 1
    $\begingroup$ Please have a look at Table, possibly together with FindRoot or Solve. $\endgroup$ – Yves Klett Aug 3 '14 at 8:57
4
$\begingroup$

Setting b = 1 from the start, your equation can be rewritten as

(3 k)/(3 + a k^2) == Tan[k]

This has multiple solutions for k for any given value of a. Here's e.g. the plot of the LHS and the RHS for a = 1; the intersections are the solutions:

Plot[
 { (3 k)/(3 + k^2), Tan[k] }, 
 {k, -10, 10}, 
 Exclusions -> Tan[k] == 0, PlotPoints -> 500
]

Mathematica graphics

Assuming you want the smallest solutions for k > 0, we can follow the logic from this answer by Artes and throw in @Yves Klett's suggestion, to obtain

solutions = Table[
  {a, Min[ k /. NSolve[(3 k)/(3 + a k^2) == Tan[k] && 0 < k < 10, k] ]},
  {a, 1/100, 6, 1/100}
]

ListLinePlot[solutions]

Mathematica graphics

Note that the range of Table is given in rationals rather than decimals; this is to prevent Solve from giving warning messages.

$\endgroup$
  • $\begingroup$ I got this error: Solve was unable to solve the system with inexact coefficients. The answer was obtained by solving a corresponding exact system and numericizing the result, which I used Quiet to hide it. Should I be concerned about that? $\endgroup$ – seismatica Aug 3 '14 at 10:04
  • $\begingroup$ @seismatica Good point, I forgot to mention that. No, you shouldn't: mathematica.stackexchange.com/q/6055/5485 . I've updated my answer; thanks for mentioning this! $\endgroup$ – Teake Nutma Aug 3 '14 at 10:15
  • $\begingroup$ Why call Rationalize? Why not solutions = Table[{N[a], Min[k /. NSolve[(3 k)/(3 + a k^2) == Tan[k] && 0 < k < 10, k]]}, {a, 1/100, 6, 1/100}] instead? $\endgroup$ – m_goldberg Aug 3 '14 at 14:34
  • $\begingroup$ @m_goldberg I agree, that's nicer -- I've updated the answer accordingly. $\endgroup$ – Teake Nutma Aug 3 '14 at 16:00

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.