Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

how to form tridiagonal matrix in matlab

Status
Not open for further replies.

ramani

Member level 4
Joined
Dec 21, 2005
Messages
78
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,288
Location
india
Activity points
1,919
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?
 

jacobus

Newbie level 5
Joined
Jan 11, 2006
Messages
9
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,376
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
 

ramani

Member level 4
Joined
Dec 21, 2005
Messages
78
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,288
Location
india
Activity points
1,919
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
 

jacobus

Newbie level 5
Joined
Jan 11, 2006
Messages
9
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,376
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.
 

jack27

Newbie level 1
Joined
Nov 5, 2013
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
8
Re: tridiagonal matlab

You may also use :

for k=1:20;

for i=2:n-1;
for j=1:n
if (j==i-1)
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




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.
- - - Updated - - -

From older post : on 10/05/2013, 01:30PM, leen87 posted :

You may also use :

for k=1:20;

for i=2:n-1;
for j=1:n
if (j==i-1)
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
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top