Need Help making a nxn symmetric matrix
Show older comments
My symmetric matrix should look like
[1 0 0 0 0..n no. of zeroes;
1 -2 1 0 0 0..n;
0 1 -2 1 0 0 ..;
for n no of rows]
1 Comment
James Tursa
on 13 Nov 2015
Edited: James Tursa
on 13 Nov 2015
Are the last two rows this?
0 ... 0 1 -2 1;
0 ... 0 0 0 1];
Or this?
0 ... 0 1 -2 1;
0 ... 0 0 1 -2];
Is this an n X n matrix or an n X n+1 matrix? It is not clear from your example what the matrix should really look like since your example is not symmetric (e.g., the (2,1) spot is not equal to the (1,2) spot)
Accepted Answer
More Answers (1)
>> n = 6;
>> M = toeplitz([-2,1,zeros(1,n-2)]);
>> M(1) = 1; M(end) = 1
M =
1 1 0 0 0 0
1 -2 1 0 0 0
0 1 -2 1 0 0
0 0 1 -2 1 0
0 0 0 1 -2 1
0 0 0 0 1 1
1 Comment
Nitesh Panchal
on 14 Nov 2015
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!