how to found bandes matrix

25 views (last 30 days)
alize beemiel
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]
  1 Comment
Image Analyst
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.

Sign in to comment.

Answers (1)

John D'Errico
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.
  3 Comments
John D'Errico
John D'Errico on 7 Oct 2020
Edited: John D'Errico on 7 Oct 2020
So your question has absolutely nothing to do with what you asked, which was apparently how to create a banded matrix? You did say you did not know how to use sparse.
Instead, your problem seems to be the singularity of a matrix, maybe?
Why in the name of god and little green apples are you writing your own cholesky algorithm? Well written, bug free code is not good enough for you, so you decided to write your own vastly slower running and possibly buggy code?
Seriously, it is literally impossible for me to know where the problem is, because I still have no real clue what is the problem. You don't want or need to write your own Cholesky code. This is just actively a bad idea. A 2kx2k matrix is relatively small, especially a banded one. For example...
n = 2000;
A = spdiags(repmat([-2 -2 9 -2 -2],[n 1]),[-3 -1 0 1 3],n,n);
condest(A)
ans = 17.0000
timeit(@() chol(A))
ans = 5.5138e-04
So the 5-banded matrix I created as a 2000x2000 matrix is well conditioned and symmetric. A Cholesky factor will exist. Is that a slow thing to compute using chol? NOOOOOO!!!!!! It required a tiny fraction of a second to compute the cholesky factorization.
So the very first things you need to learn are:
  1. How to build and manipulate sparse matrices. That means to use sparse and spdiags to start.
  2. How to use the EXISTING tools in MATLAB to work with sparse matrices. Your own code, written to factorize such a matrix will almost certainly be SLOWER then the existing tools in MATLAB. Don't write your own code to perform basic operations.
  3. Since it seems like you have issues with what you THINK is a singular matrix, then learn about tools in MATLAB to determine if a matrix is singular. In terms of sparse matrices, that might be condest as your first choice. However, these are NOT large matrices you are working with, but in fact relatively small matrices. So you could as easly use tools such as full, cond and rank, even svd to learn about your matrices.
Learn these things BEFORE you proceed any further. Don't worry about what is wrong with the code you wrote. THROW IT OUT. Then start over. Use the proper tools to build and factorize your matrices.
alize beemiel
alize beemiel on 7 Oct 2020
thanks sir,
merci pour votre patience ! .

Sign in to comment.

Categories

Find more on Sparse Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!