inverser la matrice tri-diagonale

4 Ansichten (letzte 30 Tage)
ABDO
ABDO am 4 Mai 2024
Beantwortet: John D'Errico am 4 Mai 2024
a=3*h -2;
b=1;
c=1;
A=diag(a*ones(1,N)) + diag(b*ones(1,N-1),1)+ diag(c*ones(1,N-1),-1)
inverser A

Antworten (1)

John D'Errico
John D'Errico am 4 Mai 2024
As much as I hate the suggestion, you could trivially use inv. ;-)
Better would be to use sparse matrices. That is, learn to use them.
Better yet? Learn to factorize your matrix, and then how to work with those factors. Or learn to use linsolve.
You don't tell us the value of h or N. So I'll be arbitrary
N = 6;
h = 2;
a=3*h-2;
b=1;
c=1;
A=spdiags([a*ones(N,1), b*ones(N,1), c*ones(N,1)],[0 1 -1],N,N);
A is a sparse matrix, best if n is at all large.
full(A)
ans = 6x6
4 1 0 0 0 0 1 4 1 0 0 0 0 1 4 1 0 0 0 0 1 4 1 0 0 0 0 1 4 1 0 0 0 0 1 4
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Now you could trivially use inv, as I said.
full(inv(A))
ans = 6x6
0.2679 -0.0718 0.0192 -0.0052 0.0014 -0.0003 -0.0718 0.2872 -0.0769 0.0206 -0.0055 0.0014 0.0192 -0.0769 0.2886 -0.0773 0.0206 -0.0052 -0.0052 0.0206 -0.0773 0.2886 -0.0769 0.0192 0.0014 -0.0055 0.0206 -0.0769 0.2872 -0.0718 -0.0003 0.0014 -0.0052 0.0192 -0.0718 0.2679
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
But do you see that the inverse of a tridiagonal matrix is no longer tridiagonal? You don't want to do that.
Instead, you might use tools like linsolve. Or you could factorize A. A cholesky factorization seeems a good choice.
L = chol(A)
L =
(1,1) 2.0000 (1,2) 0.5000 (2,2) 1.9365 (2,3) 0.5164 (3,3) 1.9322 (3,4) 0.5175 (4,4) 1.9319 (4,5) 0.5176 (5,5) 1.9319 (5,6) 0.5176 (6,6) 1.9319
As you can see, L is now bidiagonal.
spy(L)
Or you could use linsolve. Since you are doing this to solve a linear system of equations, that would be appropriate. Or you could use backslash.

Kategorien

Mehr zu Linear Algebra finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by