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

Chemical Equation Balancer

化学方程式を自動的にバランスします。

→ または = を使用して反応物と生成物を分離します。複合物の間に + を使用してください。

このツールについて

化学方程式バランサーは、化学反応を正確に表現するために方程式の両側に同じ数の原子が存在することを確認する必要がある化学者、学生、教育者にとって不可欠なツールです。手作業で方程式を平衡させることは、特に複数の反応物と生成物を含む複雑な反応では時間がかかり、エラーが起きやすくなります。このツールはそのプロセスを自動化し、正しい化学量論係数を即座に見つけるので、算術と戦うのではなく化学の理解に集中できます。

バランサーを使用するには、標準的な化学記号を使って入力フィールドに平衡していない化学方程式を入力するだけです。例えば、水素の燃焼なら H2 + O2 → H2O のように入力します。ツールはあなたの方程式を解析し、すべての一意の要素とその数を識別し、それを平衡させるために必要な最小の整数係数を計算します。鉄が錆びるような単純な反応から複雑な有機合成まで、ツールは単一ステップの方程式を迅速かつ正確に処理します。

このツールは、試験の準備や宿題を完成させる高校と大学の化学学生、および彼らの仕事を確認したり例題を生成したい教育者にとって最も有用です。このツールが平衡させるのは個々の方程式であることに注意してください。反応生成物を予測したり、反応メカニズムを説明したりすることはできません。非常に大きな方程式や通常でない方程式の場合は、常に結果を化学原理と照らし合わせて、あなたの特定の文脈で出力が意味をなすことを確認してください。

よくある質問

コード実装

# Chemical equation balancing using linear algebra
import numpy as np
from fractions import Fraction

def parse_formula(formula):
    """Parse a chemical formula like H2O into {'H': 2, 'O': 1}"""
    import re
    pattern = r"([A-Z][a-z]?)([0-9]*)"
    counts = {}
    for element, count in re.findall(pattern, formula):
        counts[element] = counts.get(element, 0) + int(count or 1)
    return counts

def balance_equation(reactants, products):
    """
    Balance a chemical equation.
    reactants: list of formula strings, e.g. ["H2", "O2"]
    products:  list of formula strings, e.g. ["H2O"]
    Returns coefficients for [reactants..., products...]
    """
    # Collect all elements
    all_compounds = reactants + products
    all_elements = set()
    for compound in all_compounds:
        all_elements.update(parse_formula(compound).keys())
    elements = sorted(all_elements)

    # Build matrix: rows=elements, cols=compounds
    # Reactants are positive, products are negative
    n = len(all_compounds)
    m = len(elements)
    matrix = [[Fraction(0)] * n for _ in range(m)]

    for j, compound in enumerate(all_compounds):
        parsed = parse_formula(compound)
        sign = 1 if j < len(reactants) else -1
        for i, element in enumerate(elements):
            matrix[i][j] = Fraction(sign * parsed.get(element, 0))

    # Gaussian elimination to find null space
    # (simplified — works for most single-reaction equations)
    # For production use, consider sympy:
    # from sympy import Matrix
    # M = Matrix(matrix)
    # coeffs = M.nullspace()[0]
    return "Use sympy for robust balancing"

# Example with sympy (recommended)
from sympy import Matrix, lcm
from functools import reduce

def balance_sympy(reactants, products):
    import re
    all_compounds = reactants + products
    elements = sorted(set(
        e for f in all_compounds
        for e, _ in re.findall(r"([A-Z][a-z]?)([0-9]*)", f)
    ))

    rows = []
    for elem in elements:
        row = []
        for i, f in enumerate(all_compounds):
            counts = {e: int(n or 1) for e, n in
                      re.findall(r"([A-Z][a-z]?)([0-9]*)", f)}
            sign = 1 if i < len(reactants) else -1
            row.append(sign * counts.get(elem, 0))
        rows.append(row)

    M = Matrix(rows)
    null = M.nullspace()[0]
    denom = reduce(lcm, [v.q for v in null])
    coeffs = [int(v * denom) for v in null]
    return coeffs

coeffs = balance_sympy(["H2", "O2"], ["H2O"])
print(coeffs)  # [2, 1, 2] -> 2H2 + O2 -> 2H2O

Comments & Feedback

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