-1

I have six equations and six variables. I am solving it through numpy using np.linalg.solve(a, b). The result gives me 6 values but I don't know which value is x1,x2... unknown variable result satisfies only one equation that is

                          x1+x2+x3+x4+x5+x6=1.

but it does not satisfies other equation. I am considering that x[0] is x1. x[1] is x2 but which is not true because other equation not satisfies when I put according to this format. How can I find which is x1,x2,x3,x4,x5,x6 in returning list? My code is

import numpy as np
a = np.array([[-1,0,0,0.25,1,0.33], [0.33,-1,0,0,0,0.33], [0.33,0.25,-1,0.25,0,0] , [0,0.25,0.5,-1,0,0], [0,0.25,0.5,0.25,-1,0.33], [1,1,1,1,1,1]])
b = np.array([0,0,0,0,0,1])
x = np.linalg.solve(a, b)
print x

answer is:

[ 0.2644666   0.13780854  0.14895903  0.10893165  0.18669913  0.15313504]
Ignacio Vergara Kausel
  • 5,521
  • 4
  • 31
  • 41

1 Answers1

0

If you do

for i in range(6):
    (a[i]*x).sum()

You'll get that the first five elements are of the order of e-17 (basically 0 in float representation) and the last one is 1 as specified by the b vector you provided.

I believe your problem is not understanding the issues concerning float arithmetic. You can refer to this question for more information.

Ignacio Vergara Kausel
  • 5,521
  • 4
  • 31
  • 41