How to remove list to obtain sequence ?



diag_matrix does not take an n-long list as an argument, but takes n
individual arguments.  (as documented)

Try this:

(%i1) display2d:false;
(%o1) false
(%i2) P: makelist(P[i], i, 1, 3);
(%o2) [P[1],P[2],P[3]]
(%i3) apply('diag_matrix,P);
(%o3) matrix([P[1],0,0],[0,P[2],0],[0,0,P[3]])


On Thu, Jul 28, 2011 at 09:46, Zbigniew Komarnicki <cblasius at gmail.com>wrote:

> Hello,
>
> I have a problem with this
>
> (%i1) P: makelist(P[i], i, 1, 3);
> (%o1)                            [P , P , P ]
>                                   1   2   3
> (%i2) PP: diag_matrix(P);
> (%o2)                          [ [P , P , P ] ]
>                               [   1   2   3  ]
>
> This not create diagonal matrix as I need.
>
> How to pass to "diag_matrix" as sequence with no list but simply as P[1],
> P[2], P[3].
>
> So I need list P without "[" and  "]" i.e.
> P[1], P[2], P[3]
>
> but not in this form
> [ P[1], P[2], P[3] ]
>
> I need such list for e.g. 100 elements, so it is to hard to write it by
> hand
> as
> PP: diag_matrix(P[1], P[2], P[3], .... P[100])
>
> I can use "diag" and it works with list P, but how to pass it to
> diag_matrix
> as no list?
>
> (%i3) load("diag");
> (%o3)           /usr/share/maxima/5.21.1/share/contrib/diag.mac
> (%i4) PP2: diag(P);
>                                [ P   0   0  ]
>                                [  1         ]
>                                [            ]
> (%o4)                           [ 0   P   0  ]
>                                [      2     ]
>                                [            ]
>                                [ 0   0   P  ]
>                                [          3 ]
>
> Thank you in advance,
> Zbigniew
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>