Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a tridiagonal matrix that I am trying to simplify into an upper triangular matrix using Mathematica, so I can use back substitution and solve my linear system. I have found the command "RowReduce" but that simplifies the matrix to far and I get an identity matrix since the matrix I am trying to simplify is a square matrix. Is there a way in Mathematica to simplify a matrix into an upper triangular matrix?

Note: I want to solve the linear system by hand. I just want Mathematica to simplify the matrix.

Update: Specifically, I'd like to get an upper triangular matrix by using Gaussian elimination.

share|improve this question
1  
Check UpperTriangularize? –  Öskå Apr 7 at 18:45
    
That just sets all the elements below the diagonal to 0. I actually want the first steps of Gaussian elimination to be applied. –  rioneye Apr 7 at 18:49
4  
LUDecomposition? –  Öskå Apr 7 at 19:13
    
LU decomposition is a bit different than what I am hoping for. I would like to get an upper triangular matrix using Gaussian elimination (mathworld.wolfram.com/GaussianElimination.html). –  rioneye Apr 7 at 20:24
    
Look at RowReduce... –  rasher Apr 7 at 22:02

1 Answer 1

I'll illustrate on a smallish matrix, using exact arithmetic. That should make it relatively easy to verify correctness.

First we create a tridiagonal 5x5 matrix.

n = 5;
SeedRandom[33333];
mat = RandomInteger[{-100, 100}, {n, n}];
Do[mat[[i, j]] = 0; mat[[j, i]] = 0, {i, 3, n}, {j, 1, i - 2}];

mat

(*Out[68]= {{-30, -98, 0, 0, 0}, {12, 72, 29, 0, 0}, {0, -9, -49, 63, 
  0}, {0, 0, -21, 88, -16}, {0, 0, 0, -16, -98}} *)

To make it upper triangular we simply clear below pivots. I'm sure this can be done more slickly with Fold, but I'm more used to procedural methods for this sort of thing.

Do[mat[[i]] -= mat[[i, i - 1]]/mat[[i - 1, i - 1]]*mat[[i - 1]], {i, 2, n}]

mat

(* Out[70]= {
{-30, -98, 0, 0, 0},
{0, 164/5, 29, 0, 0},
{0, 0, -(6731/164), 63, 0},
{0, 0, 0, 375356/6731, -16},
{0, 0, 0, 0, -(9627006/93839)}} *)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.