How to produce an algorithm to solve a tridiagonal matrix?

How do I create an algorithm which solves a tridiagonal matrix for certain conditions, such as the following:
A: aij = {1 if i=j+-1},{4+h if i=j},{0 otherwise}
for when n=10 and h = 1/10

Answers (1)

Solve or create?
To solve a system of equations with that as its coefficient matrix, use backslash, LINSOLVE, one of the sparse iterative solvers like GMRES, etc.
To create the coefficient matrix itself, take a look at the help text for the two functions DIAG and SPDIAGS. Each contains an example that produces a matrix similar to your desired matrix; which to use depends on whether you want the result to be full or sparse, and that will probably be influenced by the value of n.

Categories

Asked:

on 20 Nov 2015

Answered:

on 20 Nov 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!