Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Solve a system of equation but shown variable is not defined.

I am trying to solve a system of equations as follows.

for i in range(1,4):
for j in range(1,4):
    var('y'+'_'+str(j)+'_'+str(i))
    var('x'+'_'+str(j)+'_'+str(i))
t3=[x_1_1*x_1_2*x_2_3/((x_1_1 + 1)*(x_2_3 + 1)),
x_2_1*(x_3_1 + 1)/(x_1_1*x_2_1*x_3_1 + x_1_1*x_2_1 + x_1_1 + 1),
  (x_1_1 + 1)/(x_1_1*x_2_1*(x_3_1 + 1)),
 1/x_2_3,
 (x_3_1*x_3_2 + x_3_1 + 1)*(x_1_1 + 1)*x_2_2*(x_2_3 + 1)/(x_3_1 + 1),
 (x_1_1*x_2_1*x_3_1 + x_1_1*x_2_1 + x_1_1 + 1)*x_3_2/((x_3_1*x_3_2 + x_3_1 + 1)*(x_1_1 + 1)),
 x_1_3*(x_2_3 + 1),
 x_2_3*x_3_1*x_3_2*x_3_3/((x_3_1*x_3_2 + x_3_1 + 1)*(x_2_3 + 1)),
 (x_3_1 + 1)/(x_3_1*x_3_2)]

Now define

a1=[]
va=[]


for i in range(1,4):
    for j in range(1,4):
        a1.append(y[j,i])
        va.append(x[j,i])
print(va)
print(a1)
#print(len(a1))
a2=[]
a3=[t3[i]-a1[i] for i in range(len(a1))]
print(a3)
solve(a3, va)

But it is shown that ``NameError: name 'y' is not defined''. How to avoid this problem? Thank you very much!