+ Post New Thread
Results 1 to 6 of 6

11th January 2006, 07:41 #1
 Join Date
 Dec 2005
 Location
 india
 Posts
 78
 Helped
 2 / 2
 Points
 1,757
 Level
 9
tridiagonal matrix matlab
hi to all,
what is the syntax used in matlab to form tridiagonal matrix from the available lower,main and upper diagonal elements.
if i use T1=diag(md1)+diag(ld1,1)+diag(ud1,1);,
it is not working for 2×2 tridiagonal matrix.
for 2×2 tridiagonal matrix all elements should present.
is there any matlab program available for this?

Advertisement

11th January 2006, 09:00 #2
 Join Date
 Jan 2006
 Posts
 9
 Helped
 1 / 1
 Points
 1,280
 Level
 8
matlab tridiagonal matrix
I think that statement is OK, if our understanding is the same
example:
diag([1,2])+diag(1,1)+diag(2,1)
ans =
1 2
1 2
?diag([1,2,3])+diag([1,2],1)+diag([1,2],1)
ans =
1 1 0
1 2 2
0 2 3

Advertisement

11th January 2006, 09:34 #3
 Join Date
 Dec 2005
 Location
 india
 Posts
 78
 Helped
 2 / 2
 Points
 1,757
 Level
 9
matlab tridiagonal
but if i use the expression shown below it gives the wrong answer.
diag(1)+diag(1,1)+diag(1,1)
ans =
1 2
2 1

Advertisement

11th January 2006, 17:12 #4
 Join Date
 Jan 2006
 Posts
 9
 Helped
 1 / 1
 Points
 1,280
 Level
 8
tridiagonal matlab
hello
the first diag in your statement just generates a constant 1
which means, it just plus 1 to the sum(diag(1,1), diag(1,1))
you may see it from the following:
diag(1)
ans =
1
?diag(1,1)
ans =
0 0
1 0
?diag(1,1)
ans =
0 1
0 0
so you have to specify the all the diagnal elements in you matrix
just like this
diag([1,1])
or
diag([1,0])
then it will be OK.

5th November 2013, 15:12 #5
 Join Date
 Nov 2013
 Posts
 1
 Helped
 0 / 0
 Points
 13
 Level
 1
Re: tridiagonal matlab
You may also use :
for k=1:20;
for i=2:n1;
for j=1:n
if (j==i1)
M(i,j)= YOUR VALUE;
elseif (j==i)
M(i,j)=YOUR VALUE;
elseif (j==i+1)
M(i,j)=YOUR VALUE;
else
M(i,j)=0;
end
end
end
end
and Eye(n) generate a nxn matrix with ones on its diagonal only.
Hope this helps.
Jack
   Updated   
From older post : on 10/05/2013, 01:30PM, leen87 posted :
You may also use :
for k=1:20;
for i=2:n1;
for j=1:n
if (j==i1)
M(i,j)= YOUR VALUE;
elseif (j==i)
M(i,j)=YOUR VALUE;
elseif (j==i+1)
M(i,j)=YOUR VALUE;
else
M(i,j)=0;
end
end
end
end
and M=Eye(n) generate a nxn matrix with ones on its diagonal only.
Hope this helps.
leen87

Advertisement

24th November 2013, 11:15 #6
Re: how to form tridiagonal matrix in matlab
Hi
You can use sparse matrix to assemble diagonal matrices
Hope this helps you
Rasha
+ Post New Thread
Please login