Putting John's suggestion of using LAPACK into practice.
LAPACK is available in the J9.03 Package Manager via the math/lapack2 addon.
Once installed (you also need to follow the simple steps to install the
binary library for your OS)
Then I think the following should calculate the matrix rank using SVD:


require 'numeric' require 'math/lapack2/example/dgesvd'

NB. this will run an example and display results. For our purposes the key
is that it has also defined the verb do_dgesvd which we can use to define a
verb to calculate rank as follows:

calcMatrixRank_svd =: +/@(0 ~: [: clean 0 {:: do_dgesvd)

calcMatrixRank_svd _3 ]\ 1 2 3 5 4 6 9 7 8

3

calcMatrixRank_svd _3 ]\ 1 2 3 2 4 6 9 7 8

2


Or using the "less expensive" QR factorisation:

require 'math/lapack2/example/dgeqrf'

calcMatrixRank_qr=: #@(] -. 0 #~ #)@clean@(_1 {:: do_dgeqrf)

calcMatrixRank_qr _3 ]\ 1 2 3 5 4 6 9 7 8

3

calcMatrixRank_qr _3 ]\ 1 2 3 2 4 6 9 7 8

2







On Fri, Jan 14, 2022 at 10:06 AM John Randall <[email protected]>
wrote:

> The rank of a matrix (in the linear algebra, not J sense) is tricky to
> determine numerically because of stability issues: an arbitrarily small
> perturbation may increase the rank.  A good practical start is the singular
> value decomposition, available through the LAPACK extension.  This reduces
> the problem to finding the rank of a diagonal matrix.
>
> Best wishes,
>
> John
>
> > On Jan 13, 2022, at 2:53 PM, Pawel Jakubas <[email protected]>
> wrote:
> >
> > Dear J enthusiasts,
> >
> > I am wondering what is the preferable way to determine the rank of a
> matrix
> > in J.
> > I would expect here below
> >
> >   ]m=: 3 3 $ 1 2 3 5 4 6 9 7 8
> > 1 2 3
> > 5 4 6
> > 9 7 8
> >  rank m
> > 3
> >
> >   ]m=: 3 3 $ 1 2 3 2 4 6 9 7 8
> > 1 2 3
> > 2 4 6
> > 9 7 8
> >  rank m
> > 2
> >
> > Thanks and cheers
> > Pawel Jakubas
> > ----------------------------------------------------------------------
> > For information about J forums see
> https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.jsoftware.com%2Fforums.htm&amp;data=04%7C01%7Crandall%40newark.rutgers.edu%7C880d6cd5d64e4e90976208d9d6ce1893%7Cb92d2b234d35447093ff69aca6632ffe%7C1%7C0%7C637777003825756175%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&amp;sdata=pwibQz9Jk2T4mmkbJ%2FTVp6YgUGhZRVCZx8KUTVEppIc%3D&amp;reserved=0
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to