我有一条原始曲线。我正在开发一个与原始曲线非常匹配的模型曲线。一切正常,但不匹配。如何控制模型曲线的曲率?下面的代码基于answer here。你知道吗
我的代码:
def curve_line(point1, point2):
a = (point2[1] - point1[1])/(np.cosh(point2[0]) - np.cosh(point1[0]))
b = point1[1] - a*np.sinh(point1[0])
x = np.linspace(point1[0], point2[0],100).tolist()
y = (a*np.cosh(x) + b).tolist()
return x,y
###### A sample of my code is given below
point1 = [10,100]
point2 = [20,50]
x,y = curve_line(point1, point2)
plt.plot(point1[0], point1[1], 'o')
plt.plot(point2[0], point2[1], 'o')
plt.plot(x,y) ## len(x)
我目前的产出:
我也尝试了以下功能:
y = (50*np.exp(-x/10) +2.5)
输出为:
不只是猜测模型函数的正确参数,您可以使用curve_fit将模型曲线拟合到数据中。你知道吗
如果密切拟合起点和终点很重要,则可以将不确定性传递给
curve_fit
,将其调整为接近终点的较低值,例如您的另一种方法
a * np.exp(b * x) + c
也会起作用,并给出-0.006 exp(0.21 x + 8.49)
。你知道吗在某些情况下,您必须对系数的初始值提供有根据的猜测,以
curve_fit
(它使用1
作为默认值)。你知道吗相关问题 更多 >
编程相关推荐