- 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?
- 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?
- Or do you want a list of (row, column) coordinates of inside the shape?
how to found bandes matrix
8 ビュー (過去 30 日間)
古いコメントを表示
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]
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/373956/image.jpeg)
1 件のコメント
Image Analyst
2020 年 10 月 7 日
Not sure what you want.
Please define exactly what "half of bandes" means to you.
回答 (1 件)
John D'Errico
2020 年 10 月 7 日
編集済み: John D'Errico
2020 年 10 月 7 日
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))
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 件のコメント
John D'Errico
2020 年 10 月 7 日
編集済み: John D'Errico
2020 年 10 月 7 日
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)
timeit(@() chol(A))
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:
- How to build and manipulate sparse matrices. That means to use sparse and spdiags to start.
- 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.
- 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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!