Need Help making a nxn symmetric matrix
Mostrar comentarios más antiguos
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 comentario
James Tursa
el 13 de Nov. de 2015
Editada: James Tursa
el 13 de Nov. de 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)
Respuesta aceptada
Más respuestas (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 comentario
Nitesh Panchal
el 14 de Nov. de 2015
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!