I am trying to re-implemet a method I have read in a paper but am not sure how to do some aspects of it. It is based upon least squares polynomial fitting and its derivative.
I have my input data such that:
x = [ 421.25571634 426.25279224 431.24986815 436.24694405 441.24401995
446.24109586 451.23817176 .............. 621.13875245 626.13582836
631.13290426 636.12998016 641.12705606 646.12413197]
y = [ 0.02931459 0.03093554 0.03563261 0.03440331 0.03535223 0.03594375
0.03639583 .......... 0.0525954 0.05118096 0.05143359 0.05036936
0.04952418 0.04774826]
I can fit a 5th order least squares polynomial to this using:
coeffs = numpy.polyfit(x, y, 5)
ffit = numpy.poly1d(coeffs)
and can plot this using matplotlib.
ffit returns me:
5 4 3 2
6.267e-12 x - 1.642e-08 x + 1.709e-05 x - 0.008833 x + 2.266 x - 231.1
However, I would like to find the first derivative of this and plot this line also. Is there a pythonic way of doing this? I have a lot of data so it would need to be as automated as possible. I understand differentiation but am unsure how I could do it in python.