20260109_163430_quadratic_vertex工具GithubCopilot模型gemini-3-pro-preview

This commit is contained in:
严浩
2026-01-09 16:41:11 +08:00
parent d104910623
commit c2436d3143
6 changed files with 173 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
# /// script
# requires-python = ">=3.11"
# dependencies = ["sympy"]
# ///
import sympy as sp
def solve():
x = sp.symbols('x', real=True)
y = -2*x**2 + 8*x - 3
# Find derivative to find critical points
dy_dx = sp.diff(y, x)
critical_points = sp.solve(dy_dx, x)
print(f"Critical points (x): {critical_points}")
if not critical_points:
print("No critical points found.")
return
vertex_x = critical_points[0]
vertex_y = y.subs(x, vertex_x)
print(f"Vertex: ({vertex_x}, {vertex_y})")
# Check second derivative to confirm maximum
d2y_dx2 = sp.diff(dy_dx, x)
print(f"Second derivative: {d2y_dx2}")
if d2y_dx2 < 0:
print("The vertex is a maximum.")
max_val = vertex_y
else:
print("The vertex is a minimum.")
max_val = vertex_y
print(f"Maximum value: {max_val}")
if __name__ == "__main__":
solve()