It has been a longer project, but I hope it was worth the outcome.
Looking at your matrices M with the "spy" command, you can clearly see a
sparse band structure and create them more efficiently with my function
"createMfast" below.
Your function needs for dimension N = 50 (5100 x 5100 dense matrix)
about 4 seconds and about 200 MB on my machine. From N=100 the
computational cost become too huge.
The function "createMfast" uses sparse banded and boolean matrices (as
your values only deal with {0,1} and for N=500 (501000 x 501000 sparse
banded matrix) only 0.1 seconds creation time are required and it uses
only 17 MB of main memory. Thus you can grow larger if you want.
The following experiment shows a comparison up to dimension 50 and a
small timing benchmark..
HTH,
Kai
Thank you very much! spdiags is the key I'd been missing. spy will also be very useful as I learn to use spdiags and troubleshoot.
... and to say that the runtime comparison was impressive is an understatement.