diff --git a/src/matrix/auto.clj b/src/matrix/auto.clj index a9e1782..3a399ae 100644 --- a/src/matrix/auto.clj +++ b/src/matrix/auto.clj @@ -27,7 +27,8 @@ ;; "Takes a matrix and a list of operations and returns a seq of matrices" ;; ) -;; (defn gaussian-top-op -;; [m] -;; "Takes a matrix and returns the op required to gaussian-eliminate the top" -;; {:n}) +(defn gaussian-column + [m col] + (cons {:mul-row col :by (/ 1 (at m col col))} + (for [y (range (inc col) (matrix-height m))] + {:add-row col :times (- (at m col y)) :to-row y}))) diff --git a/src/matrix/base.clj b/src/matrix/base.clj index 9997056..c36a240 100644 --- a/src/matrix/base.clj +++ b/src/matrix/base.clj @@ -89,3 +89,8 @@ m (:by inner) (:mul-row inner)))))) + +(defn at + "Returns the number at x y in a matrix" + [m x y] + (get (get m y) x)) diff --git a/src/matrix/render.clj b/src/matrix/render.clj index 348d854..889e3b3 100644 --- a/src/matrix/render.clj +++ b/src/matrix/render.clj @@ -167,7 +167,7 @@ (str n "R" (shrink-number (:add-row op)) " + " - "R" (shrink-number (:to op))))) + "R" (shrink-number (:to-row op))))) (defn pretty-row-op "Returns a pretty string of a row operation" diff --git a/src/matrix/spec.clj b/src/matrix/spec.clj index b50bedc..8e56f01 100644 --- a/src/matrix/spec.clj +++ b/src/matrix/spec.clj @@ -12,7 +12,7 @@ (spec/map-of #{:swap :with} number?)) (spec/def ::add - (spec/map-of #{:add-row :times :to} number?)) + (spec/map-of #{:add-row :times :to-row} number?)) (spec/def ::mul (spec/map-of #{:mul-row :by} number?))