inverser la matrice tri-diagonale
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposte (1)
John D'Errico
il 4 Mag 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)
Now you could trivially use inv, as I said.
full(inv(A))
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)
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.
0 Commenti
Vedere anche
Categorie
Scopri di più su Linear Algebra in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!