So I am working on a code that requires me to construct a large Matrix M using smaller 'square' matrices J AND M of sizes n x n each, repeated such that:
i.e with the dimensions of M such that M is repeated 'L' times along the diagonal, J' is repeated along the upper second diagonal and J on the lower second diagonal.
Note that I am working on Julia v 1.0.0 and as far as I understand there are no direct ways of assigning Block Matrices in Julia, unlike Mathematica.
I tried to use Kronecker products to solve my problem:
π=Diagonal(ones(L)) #IDENTITY matrix of L x L size
π=kron(π,M)
Doing so, I can make a Block diagonal matrix M with small matrix M repeated along its diagonal. But now how do I place matrices J and J' along its second diagonals as required?
BlockArrays.jl (and maybe BlockBandedMatrices.jl) should be what you are looking for as it makes handling block matrix structures very convenient.
An example (with Strings
s):
julia> using BlockArrays
julia> M = fill("M", 2,2);
julia> J = fill("J", 2,2);
julia> B = BlockArray{String}(undef_blocks, [2,2], [2,2])
4Γ4 BlockArray{String,2,Array{String,2}}:
#undef #undef β #undef #undef
#undef #undef β #undef #undef
βββββββββββββββββΌββββββββββββββββ
#undef #undef β #undef #undef
#undef #undef β #undef #undef
julia> setblock!(B, M, 1,1);
julia> setblock!(B, M, 2,2);
julia> setblock!(B, J, 1,2);
julia> setblock!(B, J, 2,1);
julia> B
4Γ4 BlockArray{String,2,Array{String,2}}:
"M" "M" β "J" "J"
"M" "M" β "J" "J"
βββββββββββΌββββββββββ
"J" "J" β "M" "M"
"J" "J" β "M" "M"
For more information, check out the package's documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With