1

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?

KernelPanic
  • 2,328
  • 7
  • 47
  • 90
Estif
  • 182
  • 1
  • 10
  • 1
    Look up 'nonlinear regression'. I believe scipy has a function to do it. – Terry Jan Reedy Jan 07 '17 at 05:02
  • you can construct your own x_new = (x, x**2, log(x), exp(x)) etc. and then fit a multi var linear regression for (y, x_new). See this [answer](http://stackoverflow.com/questions/22126229/numpy-polyfit-with-adapted-parameters) for how to do a multi var fit. – tihom Jan 07 '17 at 05:24

0 Answers0