How do I show this matrix in Matlab?

조회 수: 1 (최근 30일)
Zhihao Zhang
Zhihao Zhang 2021년 10월 3일
답변: the cyclist 2021년 10월 3일
n=50000

답변 (1개)

the cyclist
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

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by