From d9089a0f219795b9f4ff7f8b5576cef678fbe36d Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 2 Feb 2014 11:33:03 -0500 Subject: [PATCH] New function: Linear.Matrix.identity_matrix. --- src/Linear/Matrix.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Linear/Matrix.hs b/src/Linear/Matrix.hs index c48f722..c0f56b3 100644 --- a/src/Linear/Matrix.hs +++ b/src/Linear/Matrix.hs @@ -213,6 +213,18 @@ construct lambda = Mat $ generate make_row make_row i = generate (lambda i) +-- | Create an identity matrix with the right dimensions. +-- +-- Examples: +-- +-- >>> identity_matrix :: Mat3 Int +-- ((1,0,0),(0,1,0),(0,0,1)) +-- >>> identity_matrix :: Mat3 Double +-- ((1.0,0.0,0.0),(0.0,1.0,0.0),(0.0,0.0,1.0)) +-- +identity_matrix :: (Arity m, Ring.C a) => Mat m m a +identity_matrix = + construct (\i j -> if i == j then (fromInteger 1) else (fromInteger 0)) -- | Given a positive-definite matrix @m@, computes the -- upper-triangular matrix @r@ with (transpose r)*r == m and all -- 2.43.2