I am trying to solve the equation AX = B
in R.
I have two matrices, A and B:
A = matrix(c(1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,
0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,
0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,
0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,
0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0), byrow = T, nrow = 10, ncol = 16)
B = matrix(c(1900,2799,3096,3297,3782,4272,7783,10881,7259,30551), nrow = 10, ncol = 1)
My question is, how can I solve AX = B
and be guaranteed a non-negative solution? The values I am solving for (X1, X2,...X15, X16
) are population figures so they cannot be negative. Ideally, they would be integer values as well but one thing at a time.
Is there an easy way to do this in R?
I have found one way to do it here but it doesn't yield a positive result for all X
which is what I'm after.