Index error while trying to fit a order>1 polynomial to the data :
import numpy as np
from scipy.optimize import curve_fit
x = b #1D array for X Axis
y = c #1D array for Y Axis
def func(x, a, b,c):
return ((a*(x**2)) + b*x + c)
iniguess = [0,0.038,13.99]
param, pcov = curve_fit(func, x, y, p0=iniguess)
print (param[0],param[1],param[2])
import matplotlib.pyplot as plt
plt.plot(x,y,'bo ')
xfit = b
yfit = func(xfit, param[0], param[1], param[3])
plt.plot(xfit,yfit,'r-')
plt.legend(['data','fit'],loc='best')
This gives me an error code when I try to calculate my predicted Y values. The error is "index 3 is out of bounds for axis 0 with size 3"