Fitting Data to a Square-root or Logarithmic Function

3.1k views Asked by At

So I have some data:

ensub = np.array([0, 10, 12, 14, 13.5, 12.3, 14, 13.1, 13, 12.9, 14, 14, 13, 13])
time = np.array([0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39])

and I plot it, I'd like to find a fit. So the natural course of action to take it a poly1d of some sort:

enfit = np.polyfit(time, ensub, 2)
ene = np.poly1d(enfit)
xen = np.linspace(time[0], time[-1], 100)
yen = ene(xen)
plt.plot(time,ensub,'o', xen, yen, color='blue')

which produces following plot:
Plot1

I get something like this, which is fine usually. But I know that this data would fit really well to a different function, like a square-root or logarithmic.

This kind of graph would be preffered: BetterPlot

How can I fit a more accurate equation to this data, show it, and have it be callable?

0

There are 0 answers