In [2]:
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import pandas as pd

In [28]:
def func_model(x, a, b, c):
    return a/(x*x+b*x+c)

In [29]:
df = pd.read_csv('proximity_horizontal.csv')

In [30]:
x = df['distance (cm)'].loc[1:]
y = df['reading'].loc[1:]

In [31]:
plt.plot(x,y)
plt.show()



In [32]:
popt, pcov = curve_fit(func_model, x, y)

In [33]:
popt


Out[33]:
array([  4.76569216e+05,   4.14625464e+00,   9.67661270e+01])

In [34]:
pcov


Out[34]:
array([[  3.95116208e+09,   1.27540161e+05,   6.03260767e+05],
       [  1.27540161e+05,   4.28101196e+00,   1.88156463e+01],
       [  6.03260767e+05,   1.88156463e+01,   9.55496719e+01]])

In [37]:
plt.plot(x,y,'-o')
plt.plot(x,func_model(x,*popt),'-.')
plt.show()



In [ ]:


In [ ]: