Following up on rm's suggestion, and particularly useful if you're going to be creating many such matrices, would be to define a function. For instance
sparseMat[n_, {x_, y_,z_}] := SparseArray[{Band[{1, 1}] -> x, Band[{2, 1}] -> y,Band[{1, 2}] -> z}, {n, n}]
creates an $n$-by-$n$ tridiagonal matrix with (tri)diagonal elements $x$, $y$, and $z$. So for instance,
sparseMat[6,{x,y,z}]
is the general 6-by-6 form with variables $x$, $y$, and $z$. You can give them explicit values by replacing the calling list
sparseMat[6,{1,2,3}]
You will need to use MatrixForm[] to see the results in normal matrix form, for instance,
sparseMat[6,{1,2,3}]//MatrixForm
SparseArray[]andBand[]. If you have more questions, edit your question to say where you're having trouble. If you figure it out on your own, you can answer your own question. – 0x4A4D♦ Oct 28 '12 at 15:11tridiag[n_Integer?Positive] := SparseArray[..., {n, n}]– rm -rf♦ Oct 28 '12 at 15:18{5, 5}in your code to{10, 10}. As an additional note, if you read through the docs forBand[], you can either give a scalar or a list as the right hand side of aBand[{p, q}] -> (* stuff *)rule, which might be useful for your needs. – 0x4A4D♦ Oct 28 '12 at 15:24Read the FAQs! 3) When you see good Q&A, vote them up byclicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. ALSO, remember to accept the answer, if any, that solves your problem,by clicking the checkmark sign` – chris Oct 28 '12 at 15:34