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!