I am trying to write a program that finds the inverse of an nxn matrix in Mathematica. I've been able to find matrices that don't find the inverse of the matrix but whose product has a determinant of 1, lol. Can you tell me where I went wrong?
m = Input["row"];
n = Input["column"];
mat = Table[Subscript[b, i, j], {i, m}, {j, n}];
mat2 = Table[Subscript[c, i, j], {i, m}, {j, n}];
For[i = 1, i <= m, i++,
For[j = 1, j <= n,
j++, {Subscript[c, i, i] = 1, Subscript[c, i, j] = 0,
Subscript[c, m, n] = 1}]];
For[i = 1, i <= m, i++,
For[j = 1, j <= n, j++,
Subscript[b, i, j] = RandomInteger[{1, 3}]]];
Print[mat // MatrixForm]
For[k = 1, k <= n - 1, k++,
For[l = k + 1, l <= n, l++,
If[Subscript[b, l, k] == 0, continue,
coe = Subscript[b, l, k]/Subscript[b, k, k];
For[t = k, t <= n, t++,
Subscript[b, l, t] = Subscript[b, l, t] - coe*Subscript[b, k, t];
Subscript[c, l, t] =
Subscript[c, l, t] - coe*Subscript[c, k, t]]]]];
For[i = 1, i <= m, i++,
coe2 = 1/Subscript[b, i, i];
For[j = 1, j <= n, j++,
Subscript[b, i, j] = Subscript[b, i, j]*coe2;
Subscript[c, i, j] = Subscript[c, i, j]*coe2]];
For[k = n - 1, k >= 1, k--,
For[l = n, l >= k + 1, l--,
If[Subscript[b, k, l] == 0, continue,
coe3 = Subscript[b, k, l]/Subscript[b, k, k];
For[t = k, t <= n, t++,
Subscript[b, t, l] = Subscript[b, t, l] - coe3*Subscript[b, t, k];
Subscript[c, t, l] =
Subscript[c, t, l] - coe3*Subscript[c, t, k]]]]];
Print[mat // MatrixForm];
Print[mat2 // MatrixForm];
Quit[];