simple way solve equations form : y_1 = x_00*y_1 + x_01*y_2
Hi
is there a simplest way to get the cleaned solution below ?
startP=[1,2,3,4,5]
endP=[1,4,2,5,3]
n=len(startP)-1
varsX=var(["x_%d%d"%(c,r) for c in [0..n] for r in [0..n]])
varsY=var(["y_%d"%(c) for c in [0..n+1] ] )
#show(varsX)
#show(varsY)
eq0=y_1 == x_00*y_1 + x_01*y_2 + x_02*y_3 + x_03*y_4 + x_04*y_5
S=solve(eq0,varsX[0:5])[0]
for s in S:
print(s)
## get the solution x_00==1,x_01==0,x_02==0,x_03==0,x_04==0
cleanedS=[]
for s in S :
#print(s)
varsR=[]
for v in (s.variables()) :
if v not in varsX+varsY :
#print('r : ',v)
varsR.append(v==0)
#print(varsR)
cleanedS.append(s.subs(varsR))
print('the cleaned solution : ',cleanedS)
why there is error if I add domain='real' , in the code above?
I don't get that. What Sage do you use ?
You can get an error if you re-run code creating assumptions already existing : Sage's assumption system (i. e. Maxima's) dislikes redundancies and abhorrs inconsistencies... Better to
forget
the assumptions ((orreset
the variables).yes I forgot to precise: Sagemath 10.0 ,Ubuntu 22.04.2 LTS ,WSL2 ,W11 sorry for that.
I understand for forget or reset assumption.
Thank you @Emmanuel Charpentier