X =
0 0.5000 1.0000 0 0.5000 1.0000 0 0.5000 1.0000
0 0 0 0.5000 0.5000 0.5000 1.0000 1.0000 1.0000
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 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 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
Using X(1,i) and X(2,i) with i=1 uses phiinf=0, phier=0. Maybe you are confusing rows and columns.