Solve tridiagonal matrix system by thomas algorithm
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
m m
el 8 de Mayo de 2019
Editada: John D'Errico
el 8 de Mayo de 2019
hi
im trying to solve tridiagonal matrix system by thomas algorithm. my question is: it's obligatory to define the matrix elements or not ?
0 comentarios
Respuesta aceptada
John D'Errico
el 8 de Mayo de 2019
Editada: John D'Errico
el 8 de Mayo de 2019
Is it obligatory to create a matrix with those specific elements? Of course not. As long as you know what elements have which value, then nothing is obligatory. You are the one who is writing the code, no?
If your goal is to solve a psecific problem that is not homework, then it is usully simpler to just use sparse matrices and use backslash. The virtue of using sparse matrices is you do not need to write code to solve the problem.
I would also point out that the decomposition function is provided in MATLAB, which allows you to specify a banded matrix. These are things you would need to test and compare the time required. But again, a sparse use of backslash is FAST.
For example, on a 1e6x1e6 tridiagonal problem, the time required for a solve is tiny:
n = 1000000;
A = spdiags(rand(n,3),1:1,n,n) + speye(n)*2;
B = rand(n,1);
timeit(@() A\B)
ans =
0.010033
Why would you want to write a looped code that probably runs more slowly?
Now, maybe your question is if you can apply the Thomas algorithm to a totally general tridiagonal matrix with symbolic coefficients. Well, yes, but why?
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!