# Revision history [back]

A few things. First, I find this

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)])


sage: n = 3
sage: [('r' if i==j else 't') +'_%d%d' % (i,j) for i in [1..n] for j in [1..n]]
['r_11', 't_12', 't_13', 't_21', 'r_22', 't_23', 't_31', 't_32', 'r_33']


instead (or maybe use a CartesianProduct, but with only two it's a toss-up.) I'm not sure what the line

f = matrix([[S[i][j] for i in range(n)] for j in range(n)])


is intended to do. If you simply want the transpose, use .transpose:

sage: S
[r_11 t_12 t_13]
[t_21 r_22 t_23]
[t_31 t_32 r_33]
sage: f0 = matrix([[S[i][j] for i in range(n)] for j in range(n)])
sage: f0
[r_11 t_21 t_31]
[t_12 r_22 t_32]
[t_13 t_23 r_33]
sage: f1 = S.transpose()
sage: f1
[r_11 t_21 t_31]
[t_12 r_22 t_32]
[t_13 t_23 r_33]
sage: f0 == f1
True


To substitute into the matrix, I'd call .subs, so I think my version of your code would look like

sage: n = 3
sage: vnames = [('r' if i==j else 't') +'_%d%d' % (i,j) for i in [1..n] for j in [1..n]]
sage: R = PolynomialRing(RR, vnames)
sage: S = matrix(R, 3, R.gens())
sage: f = S.transpose()
sage: f.subs({S[0][0]: 0})
[   0 t_21 t_31]
[t_12 r_22 t_32]
[t_13 t_23 r_33]