polynomial equation parameters

心不动则不痛 提交于 2019-12-13 20:32:30

问题


I have some 2D sampling points for which I need the polynomial equation. I only found something like this:

from scipy.interpolate import barycentric_interpolate
// x and y are given as lists
yi = barycentric_interpolate(x, y, xi)

But in this case I can only get the y-values belonging to certain xi-values - that's not what I want. I need the equation (the parameter for the polynomial equation). How can I receive this?


回答1:


numpy.polyfit

Fit a polynomial p(x) = p[0] * x**deg + ... + p[deg] of degree deg to points (x, y). Returns a vector of coefficients p that minimises the squared error.

Example from the docs:

>>> x = np.array([0.0, 1.0, 2.0, 3.0,  4.0,  5.0])
>>> y = np.array([0.0, 0.8, 0.9, 0.1, -0.8, -1.0])
>>> z = np.polyfit(x, y, 3)
>>> z
array([ 0.08703704, -0.81349206,  1.69312169, -0.03968254])



回答2:


with scipy.optimize.curve_fit one can fit arbitrary functions and obtain its coefficients



来源:https://stackoverflow.com/questions/21973740/polynomial-equation-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!