逆行列と連立方程式——行列で「割り算」をする
逆行列とは
「 の逆数は で、 になる」——行列でも同じように、「掛けると単位行列になる相手」が存在する場合があります。これが逆行列です。
行列 に対して、(単位行列)を満たす行列 を の逆行列(inverse matrix)といい、 と書きます。
スカラーでいえば「」に相当する関係です——「掛けると元に戻る行列」。
逆行列が存在する行列を正則行列(invertible / non-singular matrix)といいます。
行列式(determinant)
「逆行列が存在するかどうかを一つの数で判定できる」——その数が行列式です。
行列 の行列式を:
と定義します。記号: または
| 意味 | |
|---|---|
| 逆行列が存在する(正則) | |
| 逆行列が存在しない(退化) |
幾何学的意味:行列 が の単位正方形を変換したときの面積の拡大率(符号はorientation)——「行列式 は面積が潰れてゼロになる、つまり次元が下がる」。
2×2 逆行列の公式
「対角を入れ替えて、非対角の符号を反転させて、行列式で割る」——手順さえ覚えれば機械的に求められます:
のとき:
覚え方:
- 対角成分を入れ替え()——「左上と右下を交換する」
- 非対角成分の符号を反転(、)
- 全体を で割る
検証: になることを確認してみましょう。
連立方程式を行列で解く
「連立方程式を行列で書くと、解き方がスッキリする」——2本の式を1つの行列の式にまとめて考えます。
連立方程式を行列の言葉で書き直すと:
が正則なら、両辺に左から を掛ければ解が求まります——「両辺を で割る」:
計算:
直線の交点として可視化
「2元連立方程式は『2本の直線が交わる点を求める』問題」——グラフで見ると、直感的に理解できます。マウスを動かして定数ベクトル を変えながら、交点の移動を観察しましょう。
var b1, b2, detA, invA00, invA01, invA10, invA11, solX, solY;
var ox, oy, scale, a11, a12, a21, a22;
a11 = 2; a12 = 1; a21 = 1; a22 = -2;
function worldToScreen(wx, wy) {
return [ox + wx * scale, oy - wy * scale];
}
function loop() {
ctx.clearRect(0, 0, W, H);
b1 = Math.round((mx / W) * 12 - 2);
b2 = 1;
detA = a11 * a22 - a12 * a21;
ox = W / 2; oy = H / 2; scale = 40;
// axes
ctx.strokeStyle = '#1e293b';
ctx.lineWidth = 1;
for (var g = -6; g <= 6; g++) {
var sp = worldToScreen(g, -6), ep = worldToScreen(g, 6);
ctx.beginPath(); ctx.moveTo(sp[0], sp[1]); ctx.lineTo(ep[0], ep[1]); ctx.stroke();
sp = worldToScreen(-6, g); ep = worldToScreen(6, g);
ctx.beginPath(); ctx.moveTo(sp[0], sp[1]); ctx.lineTo(ep[0], ep[1]); ctx.stroke();
}
ctx.strokeStyle = '#334155';
ctx.lineWidth = 2;
var axH = worldToScreen(-6, 0), axHe = worldToScreen(6, 0);
ctx.beginPath(); ctx.moveTo(axH[0],axH[1]); ctx.lineTo(axHe[0],axHe[1]); ctx.stroke();
var axV = worldToScreen(0, -6), axVe = worldToScreen(0, 6);
ctx.beginPath(); ctx.moveTo(axV[0],axV[1]); ctx.lineTo(axVe[0],axVe[1]); ctx.stroke();
// line 1: a11*x + a12*y = b1 => y = (b1 - a11*x)/a12
ctx.strokeStyle = '#60a5fa';
ctx.lineWidth = 2.5;
ctx.beginPath();
for (var xi = -6; xi <= 6; xi += 0.1) {
var yi1 = (b1 - a11 * xi) / a12;
var pt = worldToScreen(xi, yi1);
if (xi === -6) ctx.moveTo(pt[0], pt[1]); else ctx.lineTo(pt[0], pt[1]);
}
ctx.stroke();
// line 2: a21*x + a22*y = b2 => y = (b2 - a21*x)/a22
ctx.strokeStyle = '#f97316';
ctx.lineWidth = 2.5;
ctx.beginPath();
for (var xj = -6; xj <= 6; xj += 0.1) {
var yi2 = (b2 - a21 * xj) / a22;
var pt2 = worldToScreen(xj, yi2);
if (xj === -6) ctx.moveTo(pt2[0], pt2[1]); else ctx.lineTo(pt2[0], pt2[1]);
}
ctx.stroke();
// solution point
if (Math.abs(detA) > 0.001) {
invA00 = a22 / detA; invA01 = -a12 / detA;
invA10 = -a21 / detA; invA11 = a11 / detA;
solX = invA00 * b1 + invA01 * b2;
solY = invA10 * b1 + invA11 * b2;
var sp2 = worldToScreen(solX, solY);
ctx.fillStyle = '#22c55e';
ctx.beginPath();
ctx.arc(sp2[0], sp2[1], 7, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = '#e2e8f0';
ctx.font = '12px monospace';
ctx.textAlign = 'left';
ctx.fillText('解: x=' + solX.toFixed(2) + ', y=' + solY.toFixed(2), sp2[0]+10, sp2[1]-8);
}
ctx.fillStyle = '#60a5fa';
ctx.font = '13px monospace';
ctx.textAlign = 'left';
ctx.fillText(a11 + 'x + ' + a12 + 'y = ' + b1, 14, 20);
ctx.fillStyle = '#f97316';
ctx.fillText(a21 + 'x + (' + a22 + ')y = ' + b2, 14, 38);
ctx.fillStyle = '#94a3b8';
ctx.fillText('det(A) = ' + detA, 14, 56);
requestAnimationFrame(loop);
}
loop(); クラメルの公式
「行列式だけを使って解を直接求める方法」—— 連立方程式 の解はクラメルの公式でも求められます:
ここで は の第1列を で置換した行列、 は第2列を置換した行列——「分子の行列式が変わるだけで、計算の構造は同じ」。
逆行列が存在しない場合
「行列式がゼロのとき、連立方程式は特別な状況になる」:
のとき:
- 2本の直線が平行(解なし)または同一直線(解が無限にある)
- 行列式 は「変換が面積を に潰す」こと、つまり次元が下がることを意味する——「平面の情報が失われてしまい、元に戻せない」
まとめ
- :逆行列の存在判定と変換の拡大率——「ゼロかどうかで逆行列の有無が決まる」
- 逆行列:対角入れ替え・非対角符号反転・ 倍——「3ステップで求まる」
- の解:——「行列の『割り算』で連立方程式が解ける」
- 幾何的には:2本の直線の交点を求める操作——「グラフで見ると交点が解」
- のとき逆行列は存在しない——「次元が潰れると元に戻せない」
次回は行列の固有値・固有ベクトル——行列が「引き伸ばすだけ」の特別な方向を探します。