Thomas wrote:
Hello all.
Trying to find slope of function using numpy.
Getting close, but results are a bit off. Hope someone out here can
help.
[snip]
Why are you generating y-coordinates from the x-coordinates [-6, -5, -4,
-3, -2, -1, 0, 1, 2, 3, 4]? If you're going to use the x-coordinates
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] in your function, then use the same
to generate the y-coordinates. Surely, if you have empirical data
(which, for some reason, you know are well fitted by a quadratic
function?) you'd pass both the x and y coordinates to the function?
Maybe (untested),
def deriv(x, y):
z = np.polyfit(x, y, 2)
p = np.poly1d(z)
return p.deriv()
Duncan
--
http://mail.python.org/mailman/listinfo/python-list