How do I show this matrix in Matlab?

1 vue (au cours des 30 derniers jours)
Zhihao Zhang
Zhihao Zhang le 3 Oct 2021
n=50000

Réponses (1)

the cyclist
the cyclist le 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 https://www.mathworks.com/help/matlab/ref/mldivide.html for details]
x = M\v

Catégories

En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by