def critical_points(cls, self, parameters, variable): """ Return the critical points of this piecewise function. EXAMPLES:: sage: R.<x> = QQ[] sage: f1 = x^0 sage: f2 = 10*x - x^2 sage: f3 = 3*x^4 - 156*x^3 + 3036*x^2 - 26208*x sage: f = piecewise([[(0,3),f1],[(3,10),f2],[(10,20),f3]]) sage: expected = [5, 12, 13, 14] sage: all(abs(e-a) < 0.001 for e,a in zip(expected, f.critical_points())) True TESTS: Use variables other than x (:trac:`13836`):: sage: R.<y> = QQ[] sage: f1 = y^0 sage: f2 = 10*y - y^2 sage: f3 = 3*y^4 - 156*y^3 + 3036*y^2 - 26208*y sage: f = piecewise([[(0,3),f1],[(3,10),f2],[(10,20),f3]]) sage: expected = [5, 12, 13, 14] sage: all(abs(e-a) < 0.001 for e,a in zip(expected, f.critical_points())) True """ from sage.calculus.calculus import maxima x = QQ[self.default_variable()].gen() crit_pts = [] for domain, f in parameters: for interval in domain: a = interval.lower() b = interval.upper() for root in maxima.allroots(SR(f).diff(x)==0): root = float(root.rhs()) if a < root < b: crit_pts.append(root) return crit_pts
def critical_points(cls, self, parameters, variable): """ Return the critical points of this piecewise function. EXAMPLES:: sage: R.<x> = QQ[] sage: f1 = x^0 sage: f2 = 10*x - x^2 sage: f3 = 3*x^4 - 156*x^3 + 3036*x^2 - 26208*x sage: f = piecewise([[(0,3),f1],[(3,10),f2],[(10,20),f3]]) sage: expected = [5, 12, 13, 14] sage: all(abs(e-a) < 0.001 for e,a in zip(expected, f.critical_points())) True TESTS: Use variables other than x (:trac:`13836`):: sage: R.<y> = QQ[] sage: f1 = y^0 sage: f2 = 10*y - y^2 sage: f3 = 3*y^4 - 156*y^3 + 3036*y^2 - 26208*y sage: f = piecewise([[(0,3),f1],[(3,10),f2],[(10,20),f3]]) sage: expected = [5, 12, 13, 14] sage: all(abs(e-a) < 0.001 for e,a in zip(expected, f.critical_points())) True """ from sage.calculus.calculus import maxima x = QQ[self.default_variable()].gen() crit_pts = [] for domain, f in parameters: for interval in domain: a = interval.lower() b = interval.upper() for root in maxima.allroots(SR(f).diff(x) == 0): root = float(root.rhs()) if a < root < b: crit_pts.append(root) return crit_pts