fork download
  1. # your code goes here
Success #stdin #stdout 0.07s 14080KB
stdin
from sympy import symbols, solve, Eq, sqrt

# 題目1:已知 a + b = 20,求 ab 最大值
a, b, x = symbols('a b x')
ab_expr = 20 * a - a**2
critical_point = solve(ab_expr.diff(a), a)  # 求導並解出 a
ab_max = ab_expr.subs(a, critical_point[0])

# 題目2:解 |3x + 1| ≤ 7
ineq_1 = solve(-7 <= 3*x + 1, x)
ineq_2 = solve(3*x + 1 <= 7, x)

# 題目3:點 (5, 0) 到 (0, 12) 距離
distance = sqrt((0 - 5)**2 + (12 - 0)**2)

# 題目4:化簡 √12 / ((1 + √2)(6 - √3))
expr4 = sqrt(12)/((1 + sqrt(2)) * (6 - sqrt(3)))
simplified_expr4 = expr4.simplify()

# 題目5:點 (5,4) 到 (2,-2) 的距離
dist_5 = sqrt((5 - 2)**2 + (4 - (-2))**2)

# 題目6:檢查哪些點不在拋物線 y = -x^2 + x - 5 上
def is_on_parabola(x_val, y_val):
    return y_val == -x_val**2 + x_val - 5

test_points = [(-1, -7), (0, -5), (1, -6), (2, -7)]
results = [is_on_parabola(xv, yv) for xv, yv in test_points]

# 印出所有結果
print("題目1最大 ab 值:", ab_max)
print("題目2 範圍:", ineq_1, "與", ineq_2)
print("題目3 距離:", distance.evalf())
print("題目4 化簡結果:", simplified_expr4.evalf())
print("題目5 距離:", dist_5.evalf())
print("題目6 哪個點不在拋物線上(False表示不在):", results)
stdout
Standard output is empty