diff --git a/src/matrix/auto.clj b/src/matrix/auto.clj index cd0e181..b6f6dd2 100644 --- a/src/matrix/auto.clj +++ b/src/matrix/auto.clj @@ -51,6 +51,7 @@ (let [steps (gaussian-column m col) new (apply-all-at-once m steps)] (concat steps (gaussian-elim new (inc col))))))) +; TODO: if you can just divide to make a row good, do (defn back-sub-column [m col] diff --git a/src/matrix/core.clj b/src/matrix/core.clj index 7fec08c..28717fd 100644 --- a/src/matrix/core.clj +++ b/src/matrix/core.clj @@ -6,16 +6,34 @@ (:require [matrix.render :refer :all]) (:gen-class)) -(defn -main - "I don't do a whole lot ... yet." - [& args] +(defn steps-final-equations-interactive + [] (let [[steps final] (auto-steps-and-final (read))] (println "Steps:") ;; (for [step steps] ;; (println (pretty-row-op step))) (println (str/join "\n" (map with-inc-row-indices steps))) (println "Final:") - (pprint-matrix final))) + (pprint-matrix final :with-bar) + (println (equations final)))) + +(defn steps-with-matrices + [] + (let [got (read) + [steps final] (auto-steps-and-final got)] + (->> steps + (apply-steps got) + (cons got) + (map #(pretty-matrix % true)) + (#(interleave % (map pretty-row-op steps))) + (#(concat % [(pretty-matrix final true)])) + (str/join "\n") + println))) + +(defn -main + "I don't do a whole lot ... yet." + [& args] + (steps-final-equations-interactive)) ; TODO: actual parsing of row operations ; TODO: parse equations (easy, but requires context (e.g. x = 1 could be any number of variables)) diff --git a/src/matrix/render.clj b/src/matrix/render.clj index ebd518d..c701923 100644 --- a/src/matrix/render.clj +++ b/src/matrix/render.clj @@ -132,6 +132,12 @@ (if (not-empty z) " ") "= " eq)))) +(defn equations + "Write an equation for each row of an augmented matrix" + [m] + (str/join "\n" + (map equation-from-row m))) + (defn shrink-digit "Takes a digit and returns the subscript version" [d]