This is how I came up with a solution to your question. First, construct the system of equations so that A %*% x = b
(where x
are the values ββthat need to be solved for those inside T0
):
n <- prod(dim(T0)) b <- c(Tm1, Tm2, Tm3) m <- length(b) Ti <- array(seq_along(T0), dim(T0)) Ti1 <- unlist(apply(Ti, c(1,2), list)) Ti2 <- unlist(apply(Ti, c(1,3), list)) Ti3 <- unlist(apply(Ti, c(2,3), list)) A <- matrix(0, nrow = m, ncol = n) A[cbind(rep(1:m, each = 2), c(Ti1, Ti2, Ti3))] <- 1 cbind(A, b) # b # [1,] 1 0 0 0 1 0 0 0 0.30 # [2,] 0 1 0 0 0 1 0 0 0.20 # [3,] 0 0 1 0 0 0 1 0 0.20 # [4,] 0 0 0 1 0 0 0 1 0.30 # [5,] 1 0 1 0 0 0 0 0 0.35 # [6,] 0 1 0 1 0 0 0 0 0.20 # [7,] 0 0 0 0 1 0 1 0 0.15 # [8,] 0 0 0 0 0 1 0 1 0.30 # [9,] 1 1 0 0 0 0 0 0 0.35 # [10,] 0 0 1 1 0 0 0 0 0.20 # [11,] 0 0 0 0 1 1 0 0 0.15 # [12,] 0 0 0 0 0 0 1 1 0.30
A
is a non-square matrix, so I used the generalized inverse to solve for x
:
library(MASS) xsol <- ginv(A) %*% b Tsol <- array(xsol, dim(T0)) Tsol # , , 1 # # [,1] [,2] # [1,] 0.2375 0.1125 # [2,] 0.1125 0.0875 # # , , 2 # # [,1] [,2] # [1,] 0.0625 0.0875 # [2,] 0.0875 0.2125
This solution does not match your initial T0, however you can verify that
apply(Tsol, c(1,2), sum) # [,1] [,2] # [1,] 0.3 0.2 # [2,] 0.2 0.3 apply(Tsol, c(1,3), sum) # [,1] [,2] # [1,] 0.35 0.15 # [2,] 0.20 0.30 apply(Tsol, c(2,3), sum) # [,1] [,2] # [1,] 0.35 0.15 # [2,] 0.20 0.30
Output? No, it is impossible to restore the original matrix. Another way to show this is that the rank qr(A)$rank
matrix A
is 7
, while you have 8
unknowns. So you need one extra bit of information, for example. that T[1, 1]
is 0.25
to restore the original array:
A <- rbind(A, c(1, rep(0, n - 1))) b <- c(b, 0.25) qr(A)$rank