260109-test
This commit is contained in:
@@ -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()
|
||||
Reference in New Issue
Block a user