python - Get minimum point(s) of numpy.poly1d curve -
i have numpy.poly1d
polynomial follows:
c = np.poly1d([2,-4,-28,62,122,-256,-196,140,392,240,72])
the curve looks when graphed in range -2.5 <= x <= 2.5
:
how can find minimum point(s) of curve within given range, without using discrete values used graph curve (by mean using continuous poly1d
object)?
ok bit different functions @matiasg aim make more copyable code , use vectorized code possible.
import numpy np matplotlib.pyplot import * c = np.poly1d([2,-4,-28,62,122,-256,-196,140,392,240,72]) crit = c.deriv().r r_crit = crit[crit.imag==0].real test = c.deriv(2)(r_crit) # compute local minima # excluding range boundaries x_min = r_crit[test>0] y_min = c(x_min) plot( x_min, y_min, 'o' ) xc = np.arange(-2.5, 2.6, 0.02) yc = c(xc) plot( xc, yc) xlim([-2.5,2.5]) show()
image 1: result. note there local minima outside bounds ;)
Comments
Post a Comment