0

I am really new in Python, hence I am asking a simple question:

I have a sets of data (x1, x2, x3, x4, x5) and corresponding (y1, y2, y3, y4, y5). Now, how can I use Python to find a y value for a given x value? (x lies in between x1 to x5)

As an example: Let say, I want to find a value of Y for X = 0.9 for the following sets of data.

X        Y
0.5     12
1.2     17 
1.3     23
1.6     29
2.1     33

Thanks in advance!!

4

1 回答 1

1

您可以使用polyfit.

from numpy import polyfit


print polyfit([0.5, 1.2, 1.3, 1.6, 2.1],
              [12, 17, 23, 29, 33],
              1)  # Replace this number for the degree of the polinomium

Output degree 1 -> [ 14.02332362   4.00874636]
Output degree 2 -> [  1.17847672  10.98436544   5.64150351]

您获得的是曲线的系数:

  • 1 年级:y = 14.02332362x + 4.00874636
  • 2 级:y = 1.17847672x 2 + 10.98436544x + 5.64150351
于 2014-09-18T15:01:12.280 回答