# Count intersections of two non-polynomial functions [duplicate]

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!

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}]

-

## marked as duplicate by gpap, bobthechemist, Öskå, Yves Klett, Dr. belisarius plotting StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Nov 17 '14 at 19:37

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

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}]


-