From: Lukas on
I have a large square band matrix, which I can create as a banded matrix myself. In essence I can create a matrix like:

1 6 11
2 7 12
3 8 13
4 9 14
2 7 12

which represents something like:

6 0 13 0 0
0 7 0 14 0
1 0 8 0 15
0 2 0 9 0
0 0 3 0 10

My question is: Are there any efficent ways to solve an equation X = A/B where A is the banded matrix I already have? That is, can I force matlab to recognize my matrix as a banded matrix without making it full first?

I hope this makes sense, any suggestions are appreciated.

Cheers
From: Steven Lord on

"Lukas " <lukas.bystricky(a)afcc-auto.com> wrote in message
news:i10fuc$b5q$1(a)fred.mathworks.com...
>I have a large square band matrix, which I can create as a banded matrix
>myself. In essence I can create a matrix like:
>
> 1 6 11 2 7 12 3 8 13 4 9
> 14 2 7 12
> which represents something like: 6 0 13 0 0
> 0 7 0 14 0
> 1 0 8 0 15
> 0 2 0 9 0
> 0 0 3 0 10
>
> My question is: Are there any efficent ways to solve an equation X = A/B
> where A is the banded matrix I already have? That is, can I force matlab
> to recognize my matrix as a banded matrix without making it full first?

MATLAB will not recognize your N-by-3 matrix as a banded matrix, but you can
convert it to a banded matrix without making it full by using SPDIAGS to
create a sparse banded matrix.

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/spdiags.html

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com


From: Lukas on
"Steven Lord" <slord(a)mathworks.com> wrote in message <i10rih$qqv$1(a)fred.mathworks.com>...
>
> "Lukas " <lukas.bystricky(a)afcc-auto.com> wrote in message
> news:i10fuc$b5q$1(a)fred.mathworks.com...
> >I have a large square band matrix, which I can create as a banded matrix
> >myself. In essence I can create a matrix like:
> >
> > 1 6 11 2 7 12 3 8 13 4 9
> > 14 2 7 12
> > which represents something like: 6 0 13 0 0
> > 0 7 0 14 0
> > 1 0 8 0 15
> > 0 2 0 9 0
> > 0 0 3 0 10
> >
> > My question is: Are there any efficent ways to solve an equation X = A/B
> > where A is the banded matrix I already have? That is, can I force matlab
> > to recognize my matrix as a banded matrix without making it full first?
>
> MATLAB will not recognize your N-by-3 matrix as a banded matrix, but you can
> convert it to a banded matrix without making it full by using SPDIAGS to
> create a sparse banded matrix.
>
> http://www.mathworks.com/access/helpdesk/help/techdoc/ref/spdiags.html
>
> --
> Steve Lord
> slord(a)mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com
>

Thanks Steve.

That definatly will work quite well, however I think it should be possible to make it a bit better.

Correct me if I'm wrong, but since I already know a lot about the structure of the matrix, I think I'm losing some information when I convert it to sparse. Are there any methods that work well with banded matrices? This may not be entirely useful for this example since I still have to make Matlab recognize my matrix as banded, but any info would still be appreciated.

Cheers.
From: John D'Errico on
"Lukas " <lukas.bystricky(a)afcc-auto.com> wrote in message <i12bhc$53h$1(a)fred.mathworks.com>...
> "Steven Lord" <slord(a)mathworks.com> wrote in message <i10rih$qqv$1(a)fred.mathworks.com>...
> >
> > "Lukas " <lukas.bystricky(a)afcc-auto.com> wrote in message
> > news:i10fuc$b5q$1(a)fred.mathworks.com...
> > >I have a large square band matrix, which I can create as a banded matrix
> > >myself. In essence I can create a matrix like:
> > >
> > > 1 6 11 2 7 12 3 8 13 4 9
> > > 14 2 7 12
> > > which represents something like: 6 0 13 0 0
> > > 0 7 0 14 0
> > > 1 0 8 0 15
> > > 0 2 0 9 0
> > > 0 0 3 0 10
> > >
> > > My question is: Are there any efficent ways to solve an equation X = A/B
> > > where A is the banded matrix I already have? That is, can I force matlab
> > > to recognize my matrix as a banded matrix without making it full first?
> >
> > MATLAB will not recognize your N-by-3 matrix as a banded matrix, but you can
> > convert it to a banded matrix without making it full by using SPDIAGS to
> > create a sparse banded matrix.
> >
> > http://www.mathworks.com/access/helpdesk/help/techdoc/ref/spdiags.html
> >
> > --
> > Steve Lord
> > slord(a)mathworks.com
> > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> > To contact Technical Support use the Contact Us link on
> > http://www.mathworks.com
> >
>
> Thanks Steve.
>
> That definatly will work quite well, however I think it should be possible to make it a bit better.
>
> Correct me if I'm wrong, but since I already know a lot about the structure of the matrix, I think I'm losing some information when I convert it to sparse. Are there any methods that work well with banded matrices? This may not be entirely useful for this example since I still have to make Matlab recognize my matrix as banded, but any info would still be appreciated.
>

Try this:

A = sparse(diag(ones(10,1)) + diag(rand(5,1),5) + diag(rand(5,1),-5));
[L,U] = lu(A)

spy(A)
spy(L)
spy(U)

Thus, A is a banded matrix. I could have made it directly
using spdiags, but well, I was feeling lazy.

See that the sparse form in matlab stores only the non-zeros.
No information is lost, and the spase lu form is also neatly
banded.

John
From: Lukas on
"John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <i12dh3$etc$1(a)fred.mathworks.com>...
> "Lukas " <lukas.bystricky(a)afcc-auto.com> wrote in message <i12bhc$53h$1(a)fred.mathworks.com>...
> > "Steven Lord" <slord(a)mathworks.com> wrote in message <i10rih$qqv$1(a)fred.mathworks.com>...
> > >
> > > "Lukas " <lukas.bystricky(a)afcc-auto.com> wrote in message
> > > news:i10fuc$b5q$1(a)fred.mathworks.com...
> > > >I have a large square band matrix, which I can create as a banded matrix
> > > >myself. In essence I can create a matrix like:
> > > >
> > > > 1 6 11 2 7 12 3 8 13 4 9
> > > > 14 2 7 12
> > > > which represents something like: 6 0 13 0 0
> > > > 0 7 0 14 0
> > > > 1 0 8 0 15
> > > > 0 2 0 9 0
> > > > 0 0 3 0 10
> > > >
> > > > My question is: Are there any efficent ways to solve an equation X = A/B
> > > > where A is the banded matrix I already have? That is, can I force matlab
> > > > to recognize my matrix as a banded matrix without making it full first?
> > >
> > > MATLAB will not recognize your N-by-3 matrix as a banded matrix, but you can
> > > convert it to a banded matrix without making it full by using SPDIAGS to
> > > create a sparse banded matrix.
> > >
> > > http://www.mathworks.com/access/helpdesk/help/techdoc/ref/spdiags.html
> > >
> > > --
> > > Steve Lord
> > > slord(a)mathworks.com
> > > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> > > To contact Technical Support use the Contact Us link on
> > > http://www.mathworks.com
> > >
> >
> > Thanks Steve.
> >
> > That definatly will work quite well, however I think it should be possible to make it a bit better.
> >
> > Correct me if I'm wrong, but since I already know a lot about the structure of the matrix, I think I'm losing some information when I convert it to sparse. Are there any methods that work well with banded matrices? This may not be entirely useful for this example since I still have to make Matlab recognize my matrix as banded, but any info would still be appreciated.
> >
>
> Try this:
>
> A = sparse(diag(ones(10,1)) + diag(rand(5,1),5) + diag(rand(5,1),-5));
> [L,U] = lu(A)
>
> spy(A)
> spy(L)
> spy(U)
>
> Thus, A is a banded matrix. I could have made it directly
> using spdiags, but well, I was feeling lazy.
>
> See that the sparse form in matlab stores only the non-zeros.
> No information is lost, and the spase lu form is also neatly
> banded.
>
> John

Thanks John.

I should probably clairify what I meant when I said some information might be lost when converting to sparse. I realize that all the values stored in the matrix are still going to be there, so accuracy won't be affected. What I meant is that I think there's a better way to exploit the banded structure of the matrix, i.e. a way to solve it quicker than a generic sparse matrix.

Cheers.
Lukas