I have square matrix of size $n$ filled with the following values
$$ T(i,j) = \begin{cases} 1 & i=j \\ -1 & j=k(i) \\ 0 & \mbox{otherwise} \end{cases} $$
where $k(i)=\{ \ldots \}$ is vector of integers, each one $k(i)
Example with $n=4$ generated from $k=\{ 0, 1, 1, 3 \}$
$$ T = \begin{bmatrix} 1 & 0 & 0 & 0 \\ -1 & 1 & 0 & 0 \\ -1 & 0 & 1 & 0 \\ 0 & 0 & -1 & 1 \end{bmatrix} $$
Notice that for each row $i$ there is only one $-1$ at the $k(i)$ column.
Now I want to find a rule for any $n>1$ that would generate $B=$T^{-1} = \begin{bmatrix} 1 & & & \\ & 1 & & \mbox{all zeros} \\ & \ddots & 1 & \\ \mbox{zeros}& \mbox{or ones}& & 1 \end{bmatrix} $$
For the example $T$ above we have
$$ B=T^{-1} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 1 & 1 & 0 & 0 \\ 1 & 0 & 1 & 0 \\ 1 & 0 & 1 & 1 \end{bmatrix} $$
Please try to include step by step example for the $T$ value above.
Using matlab I initialize $T$ with the following code:
% Parent indices
k = [0,1,1,3] % or [0,1,2,3], [0,1,1,1], [0,1,2,2], ...
% Construct adjacency matrix T
n = size(k,2);
T = eye(n);
for i=2:n
T(i,k(i))=-1;
end
Edit 1
I tried the method of setting $(T^{-1})_{ij}=1$ if $j$ is a multiple of $k(i)$ and it didn't work. Here is the sample matlab code:
%Find B=inv(T)
B = eye(n);
for i=2:n
for j=1:i-1
for u=1:i-1
if j==(k(i))^u
B(i,j) = 1;
break
end
end
end
end
T=
1 0 0 0
-1 1 0 0
-1 0 1 0
0 0 -1 1
B=
1 0 0 0
1 1 0 0
1 0 1 0
0 0 1 1
(not correct)
Edit 2 I tried the following matlab code
%Find B=inv(T)
B = eye(n);
for i=2:n
for j=1:i-1
B(i,j) = -T(i,k(i))*B(k(i),j);
end
end
and it works it seems fine for cases where $k(i)
Edit 3
I have settled with
B=eye(n);
for i=2:n,
j=k(i);
while j>0,
B(i,j)=1;
j=k(j);
end;
end
based on the answer & comments by user1551. Here is the test code for posterity:
% Size
n = 15
% k=Parent indices
k = zeros(1,n);
for i=2:n
k(1,i) = int32(1+rand*(i-2) )
end
% Assemble T
T = eye(n);
for i=2:n
T(i,k(i))=-1;
end
% Generate B=inv(T) with various methods
if(B*T==eye(n))
disp('CORRECT')
else
disp('FAIL')
end