Skip to content

Instantly share code, notes, and snippets.

@caotic123
Forked from luksamuk/escalona.apl
Created August 23, 2019 20:33
Show Gist options
  • Save caotic123/8c04cdfc592e6c44aa5c3125b830ca04 to your computer and use it in GitHub Desktop.
Save caotic123/8c04cdfc592e6c44aa5c3125b830ca04 to your computer and use it in GitHub Desktop.
Escalonando Matrizes em APL: Código
∇R←IDENTITY N
R←(N N)⍴(1,N⍴0)
∇R←EXTENDBOTTOM MAT
R←(((↑⍴MAT)⍴1),0)\[1]MAT
∇R←EXTENDRIGHT MAT
R←(((2⌷⍴MAT)⍴1),0)\MAT
∇R←N PIVOT MAT;LST;IDX
LST←N⌷[1]MAT
IDX←(0≠LST)⍳1
→(IDX>⍴LST)/0
R←IDX⌷LST
∇R←A GCD B
→(B=0)/END
(A B)←(B (|B | A))
→1
END: R←A
∇R←SIMPVEC VEC;SIMPL
SIMPL←VEC÷GCD/⌊|VEC[⍒|VEC]
→(×+/0<SIMPL-⌊SIMPL)/DONTSIMPL
R←SIMPL
→0
DONTSIMPL:R←VEC
∇R←L GAUSSELIM A;ZEROLNS
→(0=+/|A[L;])/END
A[L;]←(×L PIVOT A)×SIMPVEC A[L;]
ZEROLNS←(~L=ZEROLNS)/ZEROLNS←⍳↑⍴A
R←{A[⍵;]←((L PIVOT A)×A[⍵;])-(A[⍵;L]×A[L;])}¨ZEROLNS
END:R←A
∇R←GAUSSJORDAN MAT
R←{MAT←⍵ GAUSSELIM MAT}¨⍳↑⍴MAT
R←{MAT[⍵;]←SIMPVEC MAT[⍵;]}¨⍳↑⍴MAT
R←MAT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment