Various methods to numerically create the inverse function of a certain function Introduction

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

Confirmation of problem

What is an involute function?

The involute function is a function used to determine the shape of the gear teeth, and its definition itself is very simple. f(\alpha) = tan\ \alpha - \alpha In the process of calculating the gears, we need to calculate the inverse function of this function.

What is an inverse function?

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.)

Try plotting the involute function

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)
インボリュート関数.png

The involute inverse function is the one with the vertical and horizontal axes swapped. インボリュート逆関数.png

Source code

The Notebook used for the explanation is uploaded to Gist. Plot of involute function.ipynb

Link to article

Various methods to numerically create the inverse function of a certain function Part 1 Polynomial regression --Qiita

Recommended Posts

Various methods to numerically create the inverse function of a certain function Introduction
Various methods to numerically create the inverse function of a certain function Part 1 Polynomial regression
Create a function to get the contents of the database in Go
How to create a wrapper that preserves the signature of the function to wrap
Create a function to visualize / evaluate the clustering result
I made a function to check the model of DCGAN
[Introduction to Python] How to split a character string with the split function
[Introduction to StyleGAN] I played with "The Life of a Man" ♬
[Go] Create a CLI command to change the extension of the image
[Python3] Define a decorator to measure the execution time of a function
[Python] A simple function to find the center coordinates of a circle
Various ways to create a dictionary (memories)
[Introduction to Python] How to sort the contents of a list efficiently with list sort
[Introduction to Python] How to write a character string with the format function
Python: I want to measure the processing time of a function neatly
I made a function to see the movement of a two-dimensional array (Python)
4 methods to count the number of occurrences of integers in a certain interval (including imos method) [Python implementation]
Various ways to read the last line of a csv file in Python
How to calculate the volatility of a brand
[Python] List Comprehension Various ways to create a list
How to create a function object from a string
[Circuit x Python] How to find the transfer function of a circuit using Lcapy
[python] Create a list of various character types
Use twitter API to get the number of tweets related to a certain keyword
From the introduction of pyethapp to the execution of contract
Create a command to get the work log
I tried to create a model with the sample of Amazon SageMaker Autopilot
[Introduction to Python] How to get the index of data with a for statement
Try to create a battle record table with matplotlib from the data of "Schedule-kun"
Add a function to tell the weather of today to slack bot (made by python)
Read the Python-Markdown source: How to create a parser
Create a dataset of images to use for learning
A quick introduction to the neural machine translation library
A memo to visually understand the axis of pandas.Panel
[Introduction to Python] How to iterate with the range function?
How to create a submenu with the [Blender] plugin
# Function that returns the character code of a string
Steps to calculate the likelihood of a normal distribution
How to hit the document of Magic Function (Line Magic)
[Introduction to Python] Basic usage of the library matplotlib
Create a shape on the trajectory of an object
Python Note: The mystery of assigning a variable to a variable
A super introduction to Django by Python beginners! Part 6 I tried to implement the login function
I tried to create a Python script to get the value of a cell in Microsoft Excel
I made a function to crop the image of python openCV, so please use it.
When a character string of a certain series is in the Key of the dictionary, the character string is converted to the Value of the dictionary.
Create a 2D array by adding a row to the end of an empty array with numpy
Try to get the function list of Python> os package
Create a function to display images like Jupyter / RStudio [Docker]
Create a Mastodon bot with a function to automatically reply with Python
An introduction to object orientation-let's change the internal state of an object
Probably the easiest way to create a pdf with Python3
Introduction to Statistics The University of Tokyo Press Chapter 2 Exercises
How to run the Export function of GCP Datastore automatically
[Introduction to AWS] A memorandum of building a web server on AWS
How to find the scaling factor of a biorthogonal wavelet
I tried a little bit of the behavior of the zip function
Let's create a function to hold down Button in Tkinter
Create a correlation diagram from the conversation history of twitter
I tried to fight the Local Minimum of Goldstein-Price Function
I want to create a Dockerfile for the time being.