NxN matrix with 2s on main diagonal
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
ieva ashmore
am 30 Nov. 2016
Beantwortet: Andrei Bobrov
am 30 Nov. 2016
How do I create NxN matrix which has 2s on main diagonal, -1s on diagonal above and below 2s and -1 last element (Nth) in the first row and first element in Nth row.
1 Kommentar
Akzeptierte Antwort
Guillaume
am 30 Nov. 2016
N = 8; %e.g.
m = full(gallery('tridiag', N));
m([N, (N-1)*N+1]) = -1
3 Kommentare
Sean de Wolski
am 30 Nov. 2016
He's using linear indexing. https://www.mathworks.com/help/releases/R2016b/matlab/math/matrix-indexing.html
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!