X-Git-Url: http://gitweb.michael.orlitzky.com/?p=numerical-analysis.git;a=blobdiff_plain;f=src%2FLinear%2FMatrix.hs;h=c0f56b348f4d4d2fbdf272cbac05e7c799eddce7;hp=c48f722265b19e3bd195ce5dc16e3ab44162d137;hb=d9089a0f219795b9f4ff7f8b5576cef678fbe36d;hpb=504257320e56784b914ff69e8efb22d6191e3372 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