How to make the main diagonal and the diagonal above and below the main diagonal equal to -2 and 1 respectively
2 views (last 30 days)
Show older comments
Answers (1)
Andrei Bobrov
on 19 Mar 2019
Edited: Andrei Bobrov
on 19 Mar 2019
A = gallery('tridiag',100,-1,2,-1);
or
n = 100;
A = spdiags(ones(n,1)*[-1 2 -1],-1:1,n,n);
0 Comments
See Also
Categories
Find more on Operating on Diagonal Matrices 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!