I would like to use a function called an involute function as a theme to create an inverse function numerically in various ways. Python has many libraries that can be used for technical calculations, so I would like to utilize those libraries to see the limits of each method. There are five ways to try it. --Polynomial regression (scikit-learn) --Support Vector Machine (scikit-learn) --Newton-Raphson method (SciPy) --Akima Spline (SciPy) --Implementation that does not rely on libraries
The involute function is a function used to determine the shape of the gear teeth, and its definition itself is very simple.
This means that when $ inv \ alpha = f (\ alpha) $ is known, you need to find $ \ alpha $ from $ inv \ alpha $. You can easily express it as $ \ alpha = f ^ {-1} (inv \ alpha) $ using mathematical symbols, but the actual calculation is not so easy. (Note: $ inv \ alpha $ is used to mean $ involute (\ alpha) $. Inv is not an abbreviation for inverse.)
Work will be done with Jupyter Notebook. First, import the required libraries. Import NumPy to work with vector data and Bokeh to plot.
Notebook
import numpy as np
from bokeh.plotting import output_notebook, figure, show
output_notebook()
Define an involute function.
Notebook
def involute_ufunc(α):
return np.tan(α) - α
Here, NumPy is used to simplify the plotting work. NumPy has a feature called broadcast that allows you to apply functions to all the elements of an array (numpy.ndarray) at once. Since the math.tan function does not support broadcast, we are using the numpy.tan function that supports broadcast. The involute_ufunc function takes an array with the argument $ \ alpha $ and applies the involute function to all the elements of the array to return the array.
Notebook
x = np.linspace(- np.pi / 4, np.pi / 4, 1000)
fig = figure(width=400, height=400)
fig.line(np.degrees(x) , involute_ufunc(x))
fig.xaxis.axis_label = 'Pressure angle α(deg)'
fig.yaxis.axis_label = 'invα'
show(fig)
The involute inverse function is the one with the vertical and horizontal axes swapped.
The Notebook used for the explanation is uploaded to Gist. Plot of involute function.ipynb
Recommended Posts