I'm trying to create a Mathematica algorithm creates a matrix f
when given a $n \times n$ square matrix L
If
i = j
, thenf[[i, i]] = 0
If
i != j
, thenf[[i, j]] = d[L, {i, j}] /d[L, {i, i}]
where d[L, {i, j}]
is the determinant of s[L, {i, j}]
, and s[L, {i, j}]
is the sub-matrix of L
which omits all elements of L
that have a row index or a column index that appears in the list {i, j}
, where 1 <= i <= n
and 1 <= j <= n
.
Note that when i != j
. s[L, {i, j}]
has dimensions {n - 2, n - 2}
, because it omits two distinct indices, while s[L, {i, i}]
has dimensions {n - 1, n - 1}
because it omits only one.
My problem is that I'm trying to use Drop
to delete rows and columns, but I get this error when L
is a 4 x 4 matrix.
Drop::drop: Cannot drop positions 4 through 4 in {{3,-1,-1},{-1,3,-1},{-1,-1,3}}.
My code is:
n = Dimensions[L][[1]]
f =
Table[
If[i != j,
Det[Drop[Drop[L, {i}, {i}], {j}, {j}]]/Det[Drop[L, {i}, {i}]],
f[[i, j]] = 0],
{i, n}, {j, n}]
I tried to change j
to j-1,
but doing so changes the concept of my problem and generates an incorrect matrix f
.
Maybe my logic is not good. Could anyone help me?