如何获得逆向查找的近似方程

问题描述 投票:-1回答:2

[有没有方法或方法可以得到从Y到X的反向查找的近似方程(x = g(y))。以下是简单的y = f(x)及其图。

import numpy as np
import matplotlib.pyplot as plt  
formula = "2*x**6 + x**5 -3*x**4 + 7*x**3 + 9*x**2 + x + 6"
x = np.arange(1, 10)
y = eval(formula)
plt.plot(x, y)
plt.xlabel('X')
plt.ylabel('Y')
plt.show()

Attaching the simple graph here

您能建议使用R或Python的任何可能的方法来以最小的误差范围获得反向查找功能(从Y到X)吗?

python r algebra polynomial-math
2个回答
0
投票

请参阅https://www.geeksforgeeks.org/python-implementation-of-polynomial-regression/以获取代码实现和多项式回归的演练。


0
投票

这里是基本的R解决方案。在要覆盖的范围内选择x,生成f(x),然后将y的函数拟合为x的函数。我计算并绘制一个值的倒数作为确认。

f = function(x) 2*x**6 + x**5 -3*x**4 + 7*x**3 + 9*x**2 + x + 6

## Generate inverse function
x = seq(0,9, 0.1)
y = f(x)
f_inv = approxfun(y, x)

## Plot as a confirmation
plot(f, xlim=c(0,9))
x100K = f_inv(100000)
points(x100K, 100000, pch=16, col="red")

Test of inverse function

© www.soinside.com 2019 - 2024. All rights reserved.