How do I show this matrix in Matlab?
1 次查看(过去 30 天)
显示 更早的评论
回答(1 个)
the cyclist
2021-10-3
N = 5; % Change this to 50000 for your case
a = 3; % The diagonal value
b = -1; % The off-diagonal value
% Create the matrix
M = diag(a*ones(1,N)) + diag(b*ones(1,N-1),1) + diag(b*ones(1,N-1),-1);
% Create the vector
v = [2; ones(N-2,1); 2];
% Solve [See https://www.mathworks.com/help/matlab/ref/mldivide.html for details]
x = M\v
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!