[Jprogramming] Getting the diagonal of a square matrix
Don Guinn
donguinn at gmail.com
Sat Jan 7 21:28:18 HKT 2012
i.3 3 3
0 1 2
3 4 5
6 7 8
9 10 11
12 13 14
15 16 17
18 19 20
21 22 23
24 25 26
(<0 1 2)|:i.3 3 3
0 13 26
(<0 1)|:i.3 3 3
0 12 24
1 13 25
2 14 26
2012/1/7 "Papp Erik Tamás" <Papp.Erik at ybl.szie.hu>
> Hi,
>
> Some example of getting the main diagonal of square matrices:
>
> ]A=:2 2$1 2 3 4
> 1 2
> 3 4
>
> (<0 1)|:A NB. The main diagonal of a square matrix A
> 1 4
>
> ]B=:3 3$1 2 3 4 5 6
> 1 2 3
> 4 5 6
> 1 2 3
>
> (<0 1)|:B NB. The main diagonal of a square matrix B
> 1 5 3
>
> ]N=:4 4$i. 16
> 0 1 2 3
> 4 5 6 7
> 8 9 10 11
> 12 13 14 15
>
> (<0 1)|:N NB. The main diagonal of a square matrix N
> 0 5 10 15
>
> Regards,
>
> Erik
> ----- Eredeti levél (Original Message) -----
> Feladó: Alex Giannakopoulos <aegean at blueyonder.co.uk>
> Dátum: Péntek, Január 6, 2012 9:48 du
> Tárgy: [Jprogramming] Getting the diagonal of a square matrix
> Címzett: Programming forum <programming at jsoftware.com>
>
> > Hi
> >
> > Is there a better (more efficient or whatever) way of getting
> > the diagonal
> > of a matrix than the simple multiplication I use below?
> >
> > Say,
> >
> > randmat=. [: ? 0 $~,~
> > idmat =. [:=i.
> > randiag =. randmat * idmat
> >
> > Many Thanks
> > -----------------------------------------------------------------
> > -----
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
More information about the Programming
mailing list