Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I have two Bessel functions, and I need to be able to count the number of intersections if both functions are plotted dependent upon the same variable. I can use FindRoot or FindInstance to get one specific intersection, but because these are not polynomials I can't use Solve or NSolve to find all solutions at one time and then simply CountInstance the list.

What I really want to do is have a full script that will count and sum the number of instances for every n-value of the Bessel function in a given range (the variable "l" in my script). For small values of constants at the beginning of my script (specifically, "a"), the total number of intersections for all values "l" will be in the dozens at most, so I can simply plot and count manually. However, for larger values, the number of counts will be closer to 1 million. Additionally, I'd like to be able to plot the number of counts versus the value of some of the inputs eventually, so it would be really nice to have this part automated.

Any ideas? Even if I can just get a script or Mathematica function that can list all of the intersections that would be a big help. I've pasted my code so far below- please forgive and advise any incorrect formatting, as I've never posted here before. Thanks! enter image description here

a = 2000;

n1 = 1.76;

n2 = 1.0;

λ = 1450;

NA = (n1^2 - n2^2)^(1/2);

V = 2*Pi*a/λ*NA

k0 = (2*Pi)/λ;

kT = (n1^2*k0^2 - Β^2)^(1/2);

γ = (Β^2 - n2^2*k0^2)^(1/2);

Y = (V^2 - X^2)^(1/2);

l = 0;

LHS = X*(BesselJ[l + 1, X]/BesselJ[l, X]);

RHS = Y*(BesselK[l + 1, Y]/BesselK[l, Y]);

Plot[{LHS, RHS}, {X, 0, V}]
share|improve this question

marked as duplicate by gpap, bobthechemist, Öskå, Yves Klett, Dr. belisarius plotting Nov 17 '14 at 19:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Also, I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – gpap Nov 17 '14 at 14:40
closely related Q/A: Marking points of intersection between two curves – kglr Nov 17 '14 at 15:42
up vote 1 down vote accepted
a = 2000;
n1 = 176/100;
n2 = 1;
\[Lambda] = 1450;
NA = (n1^2 - n2^2)^(1/2);
V = 2*Pi*a/\[Lambda]*NA;
k0 = (2*Pi)/\[Lambda];
kT = (n1^2*k0^2 - \[CapitalBeta]^2)^(1/2);
\[Gamma] = (\[CapitalBeta]^2 - n2^2*k0^2)^(1/2);
Y = (V^2 - X^2)^(1/2);
l = 0;
LHS = X*(BesselJ[l + 1, X]/BesselJ[l, X]);
RHS = Y*(BesselK[l + 1, Y]/BesselK[l, Y]);

intersections = {X, LHS} /.
  NSolve[{LHS == RHS, 0 <= X <= V}, X]

{{2.22646, 12.8433}, {5.10142, 11.9582}, {7.96595, 10.1882}, {10.7609, 6.94436}}

Plot[{LHS, RHS}, {X, 0, V},
 PlotLegends -> "Expressions",
 Exclusions -> {Denominator[LHS] == 0},
 Epilog -> {Red, AbsolutePointSize[6],
   Tooltip[Point[#], #] & /@ intersections}]

enter image description here

share|improve this answer

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