From: Michael Orlitzky Date: Sun, 2 Feb 2014 16:33:03 +0000 (-0500) Subject: New function: Linear.Matrix.identity_matrix. X-Git-Url: http://gitweb.michael.orlitzky.com/?p=numerical-analysis.git;a=commitdiff_plain;h=d9089a0f219795b9f4ff7f8b5576cef678fbe36d;hp=504257320e56784b914ff69e8efb22d6191e3372 New function: Linear.Matrix.identity_matrix. --- 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