File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -430,6 +430,8 @@ A ′∖ .eye(3): 3x3-matrix:
430430⎝-0.01953124999999994 -0.08984374999999999 -0.19531249999999994⎠
431431```
432432
433+ The inverse of ` A ` can more concisely also be obtained via ` A.inverse! ` .
434+
433435## Matrix Decompositions
434436
435437The following matrix decompositions are currently supported:
Original file line number Diff line number Diff line change @@ -440,7 +440,7 @@ public extension LANumeric {
440440 return nil
441441 }
442442 }
443-
443+
444444}
445445
446446infix operator ′* : MultiplicationPrecedence
@@ -510,6 +510,10 @@ public extension Matrix where Element : LANumeric {
510510 return result
511511 }
512512
513+ static prefix func - ( matrix : Matrix ) -> Matrix {
514+ return - 1 * matrix
515+ }
516+
513517 static func += ( left : inout Matrix , right : Matrix ) {
514518 left. accumulate ( 1 , 1 , right)
515519 }
@@ -625,7 +629,7 @@ public extension Matrix where Element : LANumeric {
625629 guard let result = Element . schurDecomposition ( & A) else { return nil }
626630 return ( eigenValues: result. eigenValues, schurForm: A, schurVectors: result. schurVectors)
627631 }
628-
632+
629633 static func ∖ ( lhs : Matrix , rhs : Matrix ) -> Matrix {
630634 return lhs. solveLeastSquares ( rhs) !
631635 }
@@ -641,6 +645,11 @@ public extension Matrix where Element : LANumeric {
641645 static func ′∖ ( lhs : Matrix , rhs : Vector < Element > ) -> Vector < Element > {
642646 return lhs. solveLeastSquares ( transpose: . adjoint, rhs) !
643647 }
648+
649+ var inverse : Matrix ? {
650+ guard rows == columns else { return nil }
651+ return self . solveLeastSquares ( . eye( rows) )
652+ }
644653
645654}
646655
You can’t perform that action at this time.
0 commit comments