I need to determine a,b,c value of y=ax2+bx+c
using the set of data point which varies upto 100 points.For Ex (-270,69) (-269,90) (-280,50). I have used Using points to generate quadratic equation to interpolate data url for determine the a,b,c value.but I found the difference between a,b,c value in both method.
Note: I can not use Numpy into production code.
def coefficent(x,y):
x_1 = x[0]
x_2 = x[1]
x_3 = x[2]
y_1 = y[0]
y_2 = y[1]
y_3 = y[2]
a = y_1/((x_1-x_2)*(x_1-x_3)) + y_2/((x_2-x_1)*(x_2-x_3)) + y_3/((x_3-x_1)*(x_3-x_2))
b = -y_1*(x_2+x_3)/((x_1-x_2)*(x_1-x_3))
-y_2*(x_1+x_3)/((x_2-x_1)*(x_2-x_3))
-y_3*(x_1+x_2)/((x_3-x_1)*(x_3-x_2))
c = y_1*x_2*x_3/((x_1-x_2)*(x_1-x_3))
+ y_2*x_1*x_3/((x_2-x_1)*(x_2-x_3))
+ y_3*x_1*x_2/((x_3-x_1)*(x_3-x_2))
return a,b,c
x = [1,2,3]
y = [4,7,12]
a,b,c = coefficent(x, y)
print a,b,c
> import numpy as np
>>> A, B, C = np.polyfit([1,2,3],[4,7,12],2)
>>> print A, B, C
1.0 -4.2727620148e-15 3.0
>>> print A, 'x^2 +', B, 'x +', C
1.0 x^2 + -4.2727620148e-15 x + 3.0
>>>