Search code examples
maxima

Automate creation of large symbolic matrix


Can this matrix be generated in a less manual way? It's okay for 4 x 4, but I need something larger. Thanks

 -->    L : matrix([L11,L12,L13,L14],[L21,L22,L23,L24],[L31,L32,L33,L34],[L41,L42,L43,L44]);
(L) matrix(
        [L11,   L12,    L13,    L14],
        [L21,   L22,    L23,    L24],
        [L31,   L32,    L33,    L34],
        [L41,   L42,    L43,    L44]
    )

Solution

  • Answer to the question and note the noun form for L in the concat function ('L)

    L:genmatrix(lambda([i,j], concat('L,i,j)), 3, 3);
        (L) matrix(
                [L11,   L12,    L13],
                [L21,   L22,    L23],
                [L31,   L32,    L33]
            )
    

    For a diagonal matrix

    R:genmatrix(lambda([i,j], if i=j then concat('R,i) else 0), 3, 3);
    
        (R) matrix(
                [R1, 0, 0],
                [0, R2, 0],
                [0, 0, R3]
            )