Skip to main content
2 of 2
deleted 867 characters in body
Henrik Schumacher
  • 109.5k
  • 7
  • 186
  • 323

How to choose elements of a matrix with internally generated variables and rank them with real coefficients

I have a Code (a long one), part of it is below. The following piece basically multiplies an adjacency matrix with a vector of equilibrium values. Then tries to pick non-zero elements to be used in other sections of the Code. The entire Code is in DynamicModule with a Manipulate inside since I wanted to simulate the model with different random numbers.

My question is that, although I know my matrix a exists with positive numbers, I cannot extract those numbers and hence the entire Code fails.

The matrix a is given as follows:

a = {{0, 0, 0, 7.55596 FE`alfa$$1563[4] FE`tao$$1563[1], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7.55596 FE`alfa$$1563[19] FE`tao$$1563[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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.461227 FE`alfa$$1563[14] FE`tao$$1563[3], 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.665655 FE`alfa$$1563[17] FE`tao$$1563[4], 0, 0, 0}, {0, 0, 0, 0, 0, 3.14909 FE`alfa$$1563[6] FE`tao$$1563[5], 0, 0, 0, 0, 3.14909 FE`alfa$$1563[11] FE`tao$$1563[5], 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.34426 FE`alfa$$1563[11] FE`tao$$1563[6], 0, 0, 0, 0, 0, 0, 0, 0, 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.66264 FE`alfa$$1563[4] FE`tao$$1563[8], .66264 FE`alfa$$1563[5] FE`tao$$1563[8], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0., 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0., 0, 0, 0, 0.}, {0, 0, 0, 0, 0, 0, 0, 4.32564 FE`alfa$$1563[8] FE`tao$$1563[10], 0, 0, 0, 4.32564 FE`alfa$$1563[12] FE`tao$$1563[10], 0, 0, 0, 0, 4.32564 FE`alfa$$1563[17] FE`tao$$1563[10], 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.02967 FE`alfa$$1563[14] FE`tao$$1563[11], 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 154.893 FE`alfa$$1563[7] FE`tao$$1563[13], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0.152293 FE`alfa$$1563[6] FE`tao$$1563[14], 0, 0, 0, 0, 0, 0, 0.152293 FE`alfa$$1563[13] FE`tao$$1563[14], 0, 0, 0, 0, 0.152293 FE`alfa$$1563[18] FE`tao$$1563[14], 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0., 0, 0, 0, 0, 0, 0., 0., 0, 0., 0., 0, 0, 0, 0., 0, 0, 0.}, {5.96944 FE`alfa$$1563[1] FE`tao$$1563[17], 0, 0, 0, 0, 0, 0, 0, 0, 5.96944 FE`alfa$$1563[10] FE`tao$$1563[17], 0, 0, 0, 0, 0, 0, 0, 5.96944 FE`alfa$$1563[18] FE`tao$$1563[17], 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.93381 FE`alfa$$1563[3] FE`tao$$1563[19], 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.93381 FE`alfa$$1563[13] FE`tao$$1563[19], 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0., 0, 0, 0, 0., 0., 0., 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};

Now I try to extract all nonzero values with

nonzeroes = Reap[Sow[#, # > 0] & /@ Flatten[a];, True][[2]] // Flatten;

But for some reason, this does evaluate to the empty list {}.

Hope to receive some guidance. Thanks.

Tugrul Temel
  • 6.4k
  • 3
  • 14
  • 33