Last active
May 6, 2018 14:11
-
-
Save Foadsf/da7dab3a75f8a9cab275473230264a4c to your computer and use it in GitHub Desktop.
custom functionfit in libreoffice calc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x | y | |
---|---|---|
10 | 0.197084039 | |
30 | 0.182641149 | |
50 | 0.179242834 | |
100 | 0.203031108 | |
150 | 0.180092409 | |
200 | 0.163100779 | |
300 | 0.163100779 | |
400 | 0.169897437 | |
600 | 0.169897437 | |
800 | 0.14186123 | |
1000 | 0.172446176 | |
1400 | 0.152905792 | |
1800 | 0.155454546 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set datafile separator "," | |
set xrange [0:1800] | |
set yrange [0.14:0.2] | |
a=0.0633 | |
b=0.005092 | |
c=0.155 | |
f(x)=a*exp(-b*x)+c | |
fit f(x) 'data.csv' u 1:2 via a,b,c | |
plot 'data.csv' using 1:2 title 'data' with lines,\ | |
f(x) title sprintf('%.2f *e^(- %.2f x)+%.2f', a,b,c) | |
pause -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
data=np.loadtxt(open("data.csv", "rb"), delimiter=",", skiprows=1) | |
from scipy.optimize import curve_fit | |
def func(x, a, b, c): | |
return a * np.exp(-b * x) + c | |
popt, pcov = curve_fit(func, data[:,0], data[:,1],p0=[0.0633,0.005092,0.155]) | |
import matplotlib.pyplot as plt | |
plt.plot(data[:,0],data[:,1],label='data') | |
plt.plot(data[:,0], func(data[:,0], *popt), 'r-', label='fit: a=%5.3f, b=%5.3f, c=%5.3f' % tuple(popt)) | |
plt.legend() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment