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!
Change
y[j,i]
tovar('y'+'_'+str(j)+'_'+str(1))
as above.@max, thank you very much! Your codes work in a separate file. But when I tried to use the same codes in the original file, it has some error:
----> 3 a1.append(var('y'+'_'+str(j)+'_'+str(i))) 4 va.append(var('x'+'_'+str(j)+'_'+str(i)))
TypeError: 'list' object is not callable
Do you know why this happens? Thank you very much!