Creating a sparse tridiagonal matrix (for 2D finite difference second order Laplacian)

Hi,
I'm trying to solve a 2D finite difference problem. I simplified the problem to solving a Ax = B equation. My issue is building the A matrix in Matlab rapidly.
The matrix I need to create is a sparce matrix with 5 diagonal lines. Also, at some lines, the whole line will be filled with 0 except for a 1 at the diagonal for my Dirichlet condition.
How can I write it in Matlab so it can create this matrix rapidly? I'm simulating a 400x400 environment which means a 16000x16000 sparce matrix.
Let's say A is my sparce matrix, is there a way I can call my diagonal matrix with a vector? Like A(1:5) would select the 5 first diagonal values and the same for not centered diagonal.

 採用された回答

msaitta
msaitta 2018 年 8 月 16 日

1 投票

spdiags will do all of those things for you.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSparse Matrices についてさらに検索

タグ

質問済み:

2018 年 8 月 16 日

回答済み:

2018 年 8 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by