Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Using Python to Find Angles Where Graphs of Bessel Functions Cross

DZone 's Guide to

Using Python to Find Angles Where Graphs of Bessel Functions Cross

We explore the mathematical and scientific power of Python and its libraries (like SciPy) by using them to calculate and visualize Bessel functions.

· Big Data Zone ·
Free Resource

A previous post of mine looked at the angles that graphs make when they cross. For example, sin() and cos(x) always cross with the same angle. The same holds for sin() and cos(kx) since the k simply rescales the x-axis.

The post ended with wondering about functions analogous to sine and cosine, such as Bessel functions. This post will look at that question in more detail. Specifically we'll look at the functions Jν and Yν.

Because these two Bessel functions satisfy the same second order linear homogeneous differential equation, the Strum separation theorem says that their zeros are interlaced: between each pair of consecutive zeros of Jν is exactly one zero of Yν, and between each pair of consecutive zeros of Yν there is exactly one zero of

In the following Python code, we find zeros of Jν, then look in between for places where Jν and Yν cross. Next we find the angle the two curves make at each intersection and plot the angles.

    from scipy.special import jn_zeros, jv, yv
    from scipy.optimize import bisect
    from numpy import empty, linspace, arccos
    import matplotlib.pyplot as plt

    n = 3 # bessel function order
    N = 100 # number of zeros

    z = jn_zeros(n, N) # Zeros of J_n
    crossings = empty(N-1)

    f = lambda x: jv(n,x) - yv(n,x)    
    for i in range(N-1):
        crossings[i] = bisect(f, z[i], z[i+1])

    def angle(n, x):
        # Derivatives of J_nu and Y_nu
        dj = 0.5*(jv(n-1,x) - jv(n+1,x))
        dy = 0.5*(yv(n-1,x) - yv(n+1,x))

        top = 1 + dj*dy
        bottom = ((1 + dj**2)*(1 + dy**2))**0.5
        return arccos(top/bottom)

    y = angle(n, crossings)
    plt.plot(y)
    plt.xlabel("Crossing number")
    plt.ylabel("Angle in radians")
    plt.show()

This shows that the angles steadily decrease, apparently quadratically.

This quadratic behavior is what we should expect from the asymptotics of Jν and Yν: For large arguments they act like shifted and rescaled versions of sin(x)/√x. So if we looked at √xJν and √xYν rather than Jν and Yν we'd expect the angles to reach some positive asymptote, and they do, as shown below.

Topics:
scipy ,special functions ,python tutorial ,big data ,data visualization python

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}