# Revision history [back]

### 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, ....

define a my_function, here are two example codes http://sage.math.canterbury.ac.nz/home/pub/222/ http://sage.math.canterbury.ac.nz/home/pub/223/

### 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, ....