二次方程式の解法
2次方程式とは
ボールを投げたとき、飛距離は「投げた速度の2乗に比例する」——こういった「2乗が含まれる式」が絡む問題を解くのが2次方程式です。
()の形の方程式を2次方程式と言います。
解法は主に3種類あります——どれを使うかは問題の形によって変わります。
- 因数分解:最もシンプル(使えるときだけ)
- 平方完成:どんな式にも使える本質的な方法
- 解の公式:すべてのケースに対応する万能公式
方法1:因数分解
の場合:
(x + 2)(x + 3) = 0
∴ x = -2 または x = -3
「掛けて6、足して5になる2数」を探せば と が見つかります——「どんな2数を足し算・掛け算したらこの値になるか」という逆算の問題です。
積がゼロ → 少なくとも一方がゼロ という論理を使います。「AかけるBがゼロならAかBのどちらかがゼロ」——これは普通の数でも同じです。
| 方程式 | 因数分解 | 解 |
|---|---|---|
| (重解) | ||
方法2:平方完成
「因数分解できない式はどうするの?」——そこで登場するのが平方完成です。
を の形に変形します。「完全な平方式に変換する」という発想です。
例:
x² + 6x = -7
x² + 6x + 9 = -7 + 9 ← (6/2)² = 9 を両辺に加える
(x + 3)² = 2
x + 3 = ±√2
x = -3 ± √2
「 の係数の半分を2乗した数を足す」のがコツです。 を足すと「」という完全な平方式が完成します。
平方完成の手順:
- 定数項を右辺に移す
- 左辺を にする( を両辺に足す)
- 両辺の平方根を取る( を忘れず——プラスとマイナスの両方)
方法3:解の公式
平方完成を一般の に適用すると解の公式が導けます——「いつでも使える万能の公式」です。
判別式 が解の個数を決定します—— の中がプラスかゼロかマイナスかで答えの種類が変わります。
| の値 | 解の個数 | 放物線の形 |
|---|---|---|
| 2つの実数解 | x軸と2点で交わる | |
| 1つの重解 | x軸に接する | |
| 実数解なし(虚数解) | x軸と交わらない |
インタラクティブ放物線
マウスのX座標で係数 を変化させながら、判別式と解の変化を確認しましょう。 を大きくすると放物線が左右にスライドし、x軸との交わり方が変わります。
function loop() {
ctx.clearRect(0, 0, W, H);
var a = 1, c = 2;
var b = -6 + (mx / W) * 12; // b from -6 to 6
var D = b*b - 4*a*c;
var cx = W/2, cy = 200;
var scaleX = 45, scaleY = 18;
// Grid
ctx.strokeStyle = '#1a2036';
ctx.lineWidth = 1;
for (var gx = -6; gx <= 6; gx++) {
ctx.beginPath(); ctx.moveTo(cx+gx*scaleX,0); ctx.lineTo(cx+gx*scaleX,H); ctx.stroke();
}
// Axes
ctx.strokeStyle = '#334155'; ctx.lineWidth = 1.5;
ctx.beginPath(); ctx.moveTo(0,cy); ctx.lineTo(W,cy); ctx.stroke();
ctx.beginPath(); ctx.moveTo(cx,0); ctx.lineTo(cx,H); ctx.stroke();
ctx.fillStyle = '#475569'; ctx.font = '11px monospace'; ctx.textAlign = 'center';
for (var n = -6; n <= 6; n++) {
if (n===0) continue;
ctx.fillText(n, cx+n*scaleX, cy+14);
}
// Parabola color based on D
var curveColor = D > 0.01 ? '#3b82f6' : (D < -0.01 ? '#ef4444' : '#fbbf24');
ctx.strokeStyle = curveColor;
ctx.lineWidth = 2.5;
ctx.beginPath();
var started = false;
for (var px = 0; px <= W; px += 2) {
var xv = (px - cx) / scaleX;
var yv = a*xv*xv + b*xv + c;
var py = cy - yv * scaleY;
if (py < -100 || py > H + 100) { started = false; continue; }
if (!started) { ctx.moveTo(px, py); started = true; }
else ctx.lineTo(px, py);
}
ctx.stroke();
// Roots
if (D >= 0) {
var r1 = (-b + Math.sqrt(D)) / (2*a);
var r2 = (-b - Math.sqrt(D)) / (2*a);
ctx.fillStyle = '#fbbf24';
ctx.beginPath();
ctx.arc(cx + r1*scaleX, cy, 6, 0, Math.PI*2);
ctx.fill();
if (Math.abs(r1-r2) > 0.01) {
ctx.beginPath();
ctx.arc(cx + r2*scaleX, cy, 6, 0, Math.PI*2);
ctx.fill();
ctx.fillStyle = '#fde68a'; ctx.font = '12px monospace'; ctx.textAlign = 'center';
ctx.fillText('x₁=' + r1.toFixed(2), cx + r1*scaleX, cy - 14);
ctx.fillText('x₂=' + r2.toFixed(2), cx + r2*scaleX, cy - 14);
} else {
ctx.fillStyle = '#fde68a'; ctx.font = '12px monospace'; ctx.textAlign = 'center';
ctx.fillText('x=' + r1.toFixed(2) + '(重解)', cx + r1*scaleX, cy - 14);
}
}
// Info panel
ctx.fillStyle = '#0f172a';
ctx.fillRect(8, 8, 260, 90);
ctx.strokeStyle = '#334155'; ctx.lineWidth = 1; ctx.strokeRect(8, 8, 260, 90);
ctx.font = '13px monospace'; ctx.textAlign = 'left';
ctx.fillStyle = '#e2e8f0';
ctx.fillText('y = x² + (' + b.toFixed(2) + ')x + 2', 18, 28);
ctx.fillStyle = D > 0 ? '#22c55e' : D === 0 ? '#fbbf24' : '#ef4444';
ctx.fillText('D = b²-4ac = ' + D.toFixed(2), 18, 50);
ctx.fillStyle = D > 0.01 ? '#22c55e' : D < -0.01 ? '#ef4444' : '#fbbf24';
ctx.fillText(D > 0.01 ? '→ 2つの実数解' : D < -0.01 ? '→ 実数解なし' : '→ 重解(1つ)', 18, 70);
ctx.fillStyle = '#94a3b8';
ctx.fillText('マウスで b を変える', 18, 88);
requestAnimationFrame(loop);
}
loop(); 解と係数の関係(ビエタの公式)
「解を直接求めなくても、解の和と積がわかる」——これがビエタの公式の便利なところです。
の2解を とすると:
これをビエタの公式と言います。解を直接求めなくても、解の和・積がわかります。
応用例
の2解について:
- ( なので )
- ()
2次方程式の作り方
「解がわかっているとき、逆に方程式を作れる」——答えから問題を作る逆の操作です。
解が と の2次方程式:
(x - 3)(x + 2) = 0
x² - x - 6 = 0
解が と (共役)の2次方程式:
和 = 2, 積 = 1² - (√2)² = -1
x² - 2x - 1 = 0
function loop() {
ctx.clearRect(0, 0, W, H);
// b を連続値にして、D=0 になる b=±2 付近でスナップ
var bRaw = -6 + (mx / W) * 12;
var b = Math.round(bRaw);
// D=0 のスナップ点: b=±2 (c=1 のとき D=b²-4=0)
if (Math.abs(bRaw - 2) < 0.35) b = 2;
if (Math.abs(bRaw + 2) < 0.35) b = -2;
var a = 1, c = 1;
var D = b*b - 4*a*c;
ctx.fillStyle = '#94a3b8';
ctx.font = '15px monospace';
ctx.textAlign = 'center';
ctx.fillText('x² + (' + b + ')x + 1 = 0 の解', W/2, 28);
ctx.fillStyle = '#e2e8f0';
ctx.font = '14px monospace';
ctx.fillText('解の公式:x = ( -(' + b + ') ± √((' + b + ')² - 4·1·1) ) / 2', W/2, 60);
ctx.fillText('= ( ' + (-b) + ' ± √(' + D + ') ) / 2', W/2, 84);
if (D > 0) {
var sqD = Math.sqrt(D);
var x1 = (-b + sqD) / 2, x2 = (-b - sqD) / 2;
ctx.fillStyle = '#22c55e';
ctx.font = 'bold 18px monospace';
ctx.fillText('x = ' + x1.toFixed(3) + ' または x = ' + x2.toFixed(3), W/2, 122);
ctx.fillStyle = '#86efac'; ctx.font = '13px monospace';
ctx.fillText('D = ' + D + ' > 0 → 2つの実数解', W/2, 148);
} else if (D === 0) {
ctx.fillStyle = '#fbbf24';
ctx.font = 'bold 18px monospace';
ctx.fillText('x = ' + (-b/2).toFixed(1) + ' (重解)', W/2, 122);
ctx.fillStyle = '#fde68a'; ctx.font = '13px monospace';
ctx.fillText('D = 0 → 重解', W/2, 148);
} else {
var sqAbsD = Math.sqrt(-D);
ctx.fillStyle = '#ef4444';
ctx.font = 'bold 16px monospace';
ctx.fillText('x = ' + (-b/2).toFixed(1) + ' ± ' + (sqAbsD/2).toFixed(3) + 'i', W/2, 122);
ctx.fillStyle = '#fca5a5'; ctx.font = '13px monospace';
ctx.fillText('D = ' + D + ' < 0 → 虚数解', W/2, 148);
}
ctx.fillStyle = '#fbbf24'; ctx.font = '14px monospace';
ctx.fillText('ビエタ:解の和 = ' + (-b) + ', 解の積 = ' + c, W/2, 188);
ctx.fillStyle = '#64748b'; ctx.font = '12px monospace';
ctx.fillText('マウスを左右に動かして b を変える (b = ' + b + ')', W/2, 240);
requestAnimationFrame(loop);
}
loop(); まとめ
- 因数分解:整数解が見つかるとき最速——「掛けて○、足して○になる2数を探す」
- 平方完成: の形に変形して解く——「 の係数の半分を2乗して足す」
- 解の公式:、——「どんな2次方程式にも使える万能公式」
- 判別式 が正・ゼロ・負で解の個数(2・1・0)が決まる——「 の中の符号で勝負が決まる」
- ビエタの公式:、——「解を求めなくても和と積がわかる」
次回は3次・4次方程式と因数定理を学びます。「ある値を代入してゼロになれば、それが根」という強力な定理です。