Posted By:
20 Mar, 2013 6:26 pm PDT

create a tridiagonal 5 x 5 matrix in matlab

I have the elements on the diagonal as [5,7,8,9,10], and elements above and below the diagonal as [2,4,3,2 ,5].

My matrix should look like this:

5 2 0 0 0
2 7 4 0 0
0 4 8 3 0
0 0 3 9 2
0 0 0 2 10

Attachment:None


Type the following:

>>A = [5,7,8,9,10];

>>B = [2,4,3,2];

>>Tri_Matrix=diag(A)+diag(B,-1)+diag(B,1)

Please see the video and attached matlab file for details

Attachment: Tridiagonal_Matrix.m
Was it useful?  




Please login to reply to this problem.