def approx(x1, y1):
# calculate polynomial
z = np.polyfit(x1, y1, 1)
print(z)
f = np.poly1d(z)
# calculate new x's and y's
x_new = np.linspace(x1[0], x1[-1], len(x1))
y_new = f(x_new)
with open('a.txt', 'a') as f:
for i in range(len(x_new)):
f.write(json.dumps(
{'time': x_new[i],
'acceleration': y_new[i]
})+'\n')
return x_new, y_new
评论列表
文章目录