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]:
In [34]:
pcov
Out[34]:
In [37]:
plt.plot(x,y,'-o')
plt.plot(x,func_model(x,*popt),'-.')
plt.show()
In [ ]:
In [ ]: