# how to found bandes matrix

5 views (last 30 days)
alize beemiel on 7 Oct 2020
Commented: alize beemiel on 7 Oct 2020
i have a big matrix with 2000x2000
to solve this equation
i need to use only a bandes matrix or half of bandes
i need te have only a bandes matrix without aij equal zero
i found sparse but i dont inderstand how to use it
i need to found this
for exemple
a=[
9 -2 0 -2 0 0 0 0
-2 9 -2 0 -2 0 0 0
0 -2 9 -2 0 -2 0 0
-2 0 -2 9 -2 0 -2 0
0 -2 0 -2 9 -2 0 -2
0 0 -2 0 -2 9 -2 0
0 0 0 -2 0 -2 9 -2
0 0 0 0 -2 0 -2 9]
Image Analyst on 7 Oct 2020
Not sure what you want.
1. Do you want a new a where the value is 1 inside your boundaries, essentially a binary map or image of what elements are inside the shape you drew?
2. Or do you want to "erase" (replace by 0) half the "bande"? If so, which half: the lower or upper half of that shape should be zeroed out?
3. Or do you want a list of (row, column) coordinates of inside the shape?
Please define exactly what "half of bandes" means to you.

John D'Errico on 7 Oct 2020
Edited: John D'Errico on 7 Oct 2020
You have 5 non-zero bands. Use spdiags. Yes, you could use sparse. But since it is a banded matrix, use a tool to breate a banded matrix.
n = 2000;
A = spdiags(repmat([-2 -2 9 -2 -2],[n 1]),[-3 -1 0 1 3],n,n);
Did it work?
full(A(1:10,1:10))
ans = 10×10
9 -2 0 -2 0 0 0 0 0 0 -2 9 -2 0 -2 0 0 0 0 0 0 -2 9 -2 0 -2 0 0 0 0 -2 0 -2 9 -2 0 -2 0 0 0 0 -2 0 -2 9 -2 0 -2 0 0 0 0 -2 0 -2 9 -2 0 -2 0 0 0 0 -2 0 -2 9 -2 0 -2 0 0 0 0 -2 0 -2 9 -2 0 0 0 0 0 0 -2 0 -2 9 -2 0 0 0 0 0 0 -2 0 -2 9
So the 10x10 square in the upper left corner looks right.
spy(A(1:50,1:50))
And it is indeed banded properly.
You will need to learn to use tools like sparse, and I hope, learn them quickly if you are working with sparse matrices to any extent. But learn to use the proper tools to solve your problem.
alize beemiel on 7 Oct 2020
thanks sir,
merci pour votre patience ! .