How do I show this matrix in Matlab?

1 view (last 30 days)
Zhihao Zhang
Zhihao Zhang on 3 Oct 2021
Answered: the cyclist on 3 Oct 2021
n=50000

Answers (1)

the cyclist
the cyclist on 3 Oct 2021
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 //www.tatmou.com/help/matlab/ref/mldivide.html for details]
x = M\v

Community Treasure Hunt

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

Start Hunting!