First row is actually the last row, because reduceStep works with the
reversd matrix
On 22-04-12 11:49, I wrote:
> (Ugly) improvement to handle matrix_3:
>
> (testing if first row consists of only zero's)
>
> RREF matrix_3
> 1 2 0 0 3 4
> 0 0 1 0 0 _1
> 0 0 0 1 0 0
> 0 0 0 0 0 0
> 0 0 0 0 0 0
>
>
> REF=: 3 :0
> if. *./0={.y do. y return. end.
> if. 0=#y do. i.0 0 return. end.
> if. 0~:k=.{.ks=.{.y do.
> r1=. k%~}.ks
> (1,r1),0,. REF r1 (}.@]-(*{.))"1 }.y
> else. if. 0=#z=. (#~0~:{."1) }.y do.
> 0,. REF (}. ks),}."1 }.y
> else. REF (}.y),~ks+{.z
> end.
> end.
> )
>
> reduceStep=: 3 :0
> if. *./0={.y do. y return. end.
> select. {.ks=.{.y
> case. 1 do. ks, 0,. (}.-(}.ks)*{.)"1 }.y
> case. 0 do. ({."1 y),"_1 reduceStep }."1 y
> case. do. y
> end.
> )
>
> RREF =: ([:{.&> (reduceStep@}.&.>^:(1<#&>)^:a:@ <@reduceStep))&.|. @ REF
>
>
>
>>> matrix_3
>>> 1 2 3 4 3 1
>>> 2 4 6 2 6 2
>>> 3 6 18 9 9 _6
>>> 4 8 12 10 12 4
>>> 5 10 24 11 15 _4
>
--
Met vriendelijke groet,
@@i = Arie Groeneveld
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm