# How to define a matrix with variables in SageMath?

I would like to define a function which produce matrices with variables. It will be something like the following.

```
def MatrixG(x,n,m):
r=Matrix(n,m)
for i in [0..n-1]:
for j in [0..m-1]:
r[i,j]=x[i,j]
return r
```

Here x[i,j]'s are variables. How to write the above correctly in Sage?

I also would like to have LU decomposition of some matrix like r1=MatrixG(3,3), r1 is a symbolic matrix.

Thank you very much.