Python Forum
Differentiation with exponential functions - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Differentiation with exponential functions (/thread-8190.html)



Differentiation with exponential functions - tyrael69 - Feb-09-2018

i have been writing a python script for work that calculates some figures for me
it's basically two parts, one part is for when the data calls for a polynomial function, the other part is for when the data calls for an exponential function
for the polynomial functions, i've been using numpy polyfit to calcluate f(x) and f'(x), example code below
x = np.array(expg[xtype]) # x-values
y = np.array(expg[ytype]) # y-values 
py = np.polyfit(x,y, 2) # equation from x and y values
py0 = np.polyder(np.poly1d(py)) # 1st derivative of function py
print('Value at zero for first derivative of eq1',py0(0))
is there something similar to polyfit for exponential functions? right now i'm using curve_fit, my code looks like this
x = np.array(expg[xtype]) # x-values
y = np.array(expg[ytype]) #y-values
def f(x, a, b, c):
	return a * np.exp(-b * x) + c 
paramsy, extrasy = curve_fit(f, x, y) # gives me the exponential function equation i'm looking for, i use this to make graphs later
print('1st deriv value at 0', paramsy[0]*paramsy[1]) # basically i just do the chain rule here since i only need the value for f'(0)
Is there a better way to find the first derivative of exponential functions? Ideally, something similar to polyfit