maybe this serves for you:
def symbMatrix(n, m, s='a'):
A = sp.Matrix(n,m, lambda i,j:sp.Symbol( s+'%i%i'%(i+1,j+1)) )
return A
Regards,
Bastian
In [15]: Matrix(3, 3, lambda i, j: Symbol('a%d%d' % (i, j)))
Out[15]:
⎡a₀₀ a₀₁ a₀₂⎤
⎢ ⎥
⎢a₁₀ a₁₁ a₁₂⎥
⎢ ⎥
⎣a₂₀ a₂₁ a₂₂⎦
The third argument to Matrix is a 2 argument lambda function that generates Symbols named ai,j, where i, j is the index of the element. Note that the indices start at 0. You can use any function as the second arg, and it will just plug in the row, col of each element.
If you also want those symbols in your namespace, you can do
In [16]: var(['a%d%d' % (i, j) for i in range(3) for j in range(3)])
Out[16]: [a₀₀, a₀₁, a₀₂, a₁₀, a₁₁, a₁₂, a₂₀, a₂₁, a₂₂]
Aaron Meurer
Actually, the fastest way is to use symarray:
In [1]: symarray("a", (3, 3))
Out[1]:
[[a_0_0 a_0_1 a_0_2]
[a_1_0 a_1_1 a_1_2]
[a_2_0 a_2_1 a_2_2]]
In [2]: Matrix(symarray("a", (3, 3)))
Out[2]:
⎡a₀ ₀ a₀ ₁ a₀ ₂⎤
⎢ ⎥
⎢a₁ ₀ a₁ ₁ a₁ ₂⎥
⎢ ⎥
⎣a₂ ₀ a₂ ₁ a₂ ₂⎦
Ondrej