vector - How to check if a matrix is upper-triangular in clojure -
i want write function compute upper triangular nature of matrix. lets a_i_j number in i^th row , j^th column. matrix upper-triangular if a_i_j = 0 > j.
try this:
(defn is-upper-triangular [m] (->> (map-indexed vector m) (mapcat (fn [[r v]] (take r v))) (every? zero?)))
the above code take 0 element first row, 1 element second row, , 2 elements third rows, etc... , checks taken elements zero. if zero, upper triangular.
this code not check given matrix square. can add check if necessary.
Comments
Post a Comment