# Substituting for a matrix of variables

I constructed a matrix of variables in the following way:

```
n = 3
R = PolynomialRing(RR,[['r','t'][cmp(int(i/n),i%n)]+'_'+str(1+int(i/n))+str(1+i%n) for i in range(n^2)])
S = matrix(R,3,R.gens())
show(S)
```

When i tried to substitute one of the variables with zero, it did not work.

```
n = 3
R = PolynomialRing(RR,[['r','t'][cmp(int(i/n),i%n)]+'_'+str(1+int(i/n))+str(1+i%n) for i in range(n^2)])
S = matrix(R,3,R.gens())
f = matrix([[S[i][j] for i in range(n)] for j in range(n)])
f({S[0][0]:0})
```

Interestingly though, the following snippet, decidedly the same to me, works with a similar syntax

```
xx = [var('alpha_%d'% (i+1)) for i in range(n)]
n = 3
R = PolynomialRing(RR,[['r','t'][cmp(int(i/n),i%n)]+'_'+str(1+int(i/n))+str(1+i%n) for i in range(n^2)])
S = matrix(R,3,R.gens())
def kron(i,j):
if i==j: return 1
else: return 0
def func(S,xx):
return [[(-1/2)*xx[i]*S[i][j]*kron(i,j) for i in range(n)]for j in range(n)]
f = matrix(func(S,xx))
diff_S = S*f.conjugate_transpose()*S - f
print diff_S({S[0][0]:0})
```

If you click on the "edit" button you'll see there are HTML tags strewn about. If you clean it up and space things it should work.

@DSM - it actually looks worse now! but i have taken out the tags!

".. and space things". You need linebreaks too.