コンテンツへスキップ
🛠️ToolsShed

二次方程式ソルバー

ax² + bx + c = 0 をステップごとに解きます。

係数を入力

ax² + bx + c = 0

x = (−b ± √(b² − 4ac)) / 2a

公式

  • 判別式: Δ = b² − 4ac
  • Δ > 0: 2つの異なる実根
  • Δ = 0: 1つの重根
  • Δ < 0: 2つの複素共役根

このツールについて

二次方程式 ax² + bx + c = 0 は代数学の最も基本的な問題の一つであり、物理学、工学、金融、建築など、あらゆる分野で現れます。このツールは瞬時に二次方程式を解き、最終的な答えだけでなく、完全なステップバイステップの計算過程を表示するので、どのようにして解に到達するかを正確に理解することができます。

係数 a、b、c を入力するだけで、判別式を計算して二次方程式の公式を適用し、実数解と複素数解の両方を見つけます。宿題の確認、プロジェクトの計算検証、代数スキルの復習など、どのような場面でも、このツールは明確で体系的な解法を提供し、その背後にある数学を理解するのに役立ちます。

よくある質問

コード実装

import cmath

def solve_quadratic(a: float, b: float, c: float):
    """Solve ax^2 + bx + c = 0. Returns two roots (may be complex)."""
    if a == 0:
        if b == 0:
            raise ValueError("Not an equation (a=0, b=0)")
        return (-c / b,)  # linear case
    disc = b**2 - 4*a*c
    sqrt_disc = cmath.sqrt(disc)
    x1 = (-b + sqrt_disc) / (2 * a)
    x2 = (-b - sqrt_disc) / (2 * a)
    return x1, x2

def format_root(r: complex) -> str:
    if r.imag == 0:
        return f"{r.real:.6g}"
    return f"{r.real:.4g} + {r.imag:.4g}i"

# Two real roots: x^2 - 5x + 6 = 0  ->  x = 3, 2
x1, x2 = solve_quadratic(1, -5, 6)
print(format_root(x1), format_root(x2))  # 3   2

# Complex roots: x^2 + 1 = 0  ->  x = ±i
x1, x2 = solve_quadratic(1, 0, 1)
print(format_root(x1), format_root(x2))  # 0 + 1i   0 + -1i

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.