# create a tridiagonal matrix

In MATLAB, we can produce a tridiagonal matrix of order 2*m+1.

```
matlab: m = 5;
matlab: diag(-m:m) + diag(ones(2*m,1),1) + diag(ones(2*m,1),-1)
```

In SAGE, do I have to write a function, two for-loops, or is there a convenient way? Perhaps it's already defined in one package, scipy/numpy, maxima, ....

Thanks in advance!

define a my_function, here are two example codes

I don't think we have this built-in, but it would be a useful enhancement... I've opened http://trac.sagemath.org/ticket/15406 for the diag of the sort mentioned with offset.