You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+92-37Lines changed: 92 additions & 37 deletions
Original file line number
Diff line number
Diff line change
@@ -100,73 +100,128 @@ The function returns a `real` scalar value representing the determinant of the i
100
100
- The determinant of the matrix is computed using the LAPACK [getrf](@ref la_lapack::getrf) backend.
101
101
- If `overwrite_a` is enabled, the input matrix `a` will be destroyed during the computation process.
102
102
103
-
## `inv(A)`
104
-
**Type**: Function
105
-
**Description**: Inverse of a scalar or square matrix.
106
-
**Optional arguments**:
107
-
-`err`: Return state handler.
108
103
109
-
## `invert(A)`
110
-
**Type**: Subroutine
111
-
**Description**: In-place inverse of a scalar or square matrix.
112
-
**Optional arguments**:
113
-
-`err`: Return state handler.
114
104
115
-
**Usage**: `call invert(A, err=err)` where `A` is replaced with $A^{-1}$.
105
+
## [inv](@ref la_inverse::inv) - Inverse of a square matrix.
106
+
107
+
### Syntax
108
+
109
+
`inv_a = inv(a [, err])`
116
110
117
-
## `.inv.A`
118
-
**Type**: Operator
119
-
**Description**: Inverse of a scalar or square matrix.
111
+
### Description
112
+
113
+
This function computes the inverse \f$ A^{-1} \f$ of a real or complex square matrix \f$ A \f$, provided that \f$ A \f$ is non-singular.
114
+
The inverse of a matrix is defined as:
115
+
116
+
\f[
117
+
A A^{-1} = A^{-1} A = I
118
+
\f]
119
+
120
+
where \f$ I \f$ is the identity matrix of the same size as \f$ A \f$. The inverse exists only if \f$ A \f$ is square and has full rank (i.e., all its singular values are nonzero).
120
121
121
-
**Effect**: `A` is replaced with $A^{-1}$.
122
+
The computation is performed using LU decomposition.
122
123
123
-
## [pseudoinvert](@ref la_pseudoinverse::pseudoinvert) - Moore-Penrose pseudo-inverse of a matrix.
124
+
### Arguments
125
+
126
+
-`a`: A `real` or `complex` square matrix of size \f$ [n,n] \f$, representing the matrix to be inverted.
127
+
-`err` (optional): A [type(la_state)](@ref la_state_type::la_state) variable that returns the error state. If not provided, the function will stop execution on error.
128
+
129
+
### Return value
130
+
131
+
-`inv_a`: A `real` or `complex` square matrix of size \f$ [n,n] \f$, representing the inverse of `a`.
132
+
133
+
### Errors
134
+
135
+
- Raises [LINALG_VALUE_ERROR](@ref la_state_type::linalg_value_error) if `a` is singular or has invalid size.
136
+
- If `err` is not provided, exceptions will trigger an `error stop`.
137
+
138
+
### Notes
139
+
140
+
- This function computes the inverse using LAPACK's LU decomposition routine [GETRF](@ref la_lapack::getrf) followed by [GETRI](@ref la_lapack::getri).
141
+
- The inverse should be used with caution in numerical computations. For solving linear systems, using [solve](@ref la_solve::solve) is usually more stable and efficient than explicitly computing the inverse.
This subroutine computes the Moore-Penrose pseudo-inverse \f$ A^+ \f$ of a real or complex matrix \f$ A \f$ using Singular Value Decomposition (SVD). The pseudo-inverse is a generalization of the matrix inverse that can be computed for non-square and singular matrices. It is particularly useful for solving least-squares problems and underdetermined systems.
151
+
This subroutine computes the inverse \\( A^{-1} \\) of a real or complex square matrix \\( A \\) **in-place**, modifying `a` directly. It uses the LU decomposition method via LAPACK's [GETRF](@ref la_lapack::getrf) and [GETRI](@ref la_lapack::getri) routines.
132
152
133
-
The computation is based on the singular value decomposition (SVD):
153
+
Given a square matrix \\( A \\), the LU decomposition factorizes it as:
134
154
135
155
\f[
136
-
A = U \Sigma V^T
156
+
A = P L U
137
157
\f]
138
158
139
-
where \f$ U \f$ and \f$ V \f$ are orthogonal matrices, and \f$ \Sigma \f$ is a diagonal matrix containing the singular values. The pseudo-inverse is computed as:
159
+
where:
160
+
-\\( P \\) is a permutation matrix,
161
+
-\\( L \\) is a lower triangular matrix with unit diagonal,
162
+
-\\( U \\) is an upper triangular matrix.
163
+
164
+
The inverse is then obtained by solving \\( A X = I \\) using the LU factors.
165
+
166
+
### Arguments
167
+
168
+
-`a`: A `real` or `complex` square matrix of size \\( [n,n]\\). On output, it is replaced with its inverse \\( A^{-1} \\).
169
+
-`err` (optional): A [type(la_state)](@ref la_state_type::la_state) variable that returns the error state. If not provided, the function will stop execution on error.
170
+
171
+
### Errors
172
+
173
+
- Raises [LINALG_ERROR](@ref la_state_type::linalg_error) if the matrix is singular.
174
+
- Raises [LINALG_VALUE_ERROR](@ref la_state_type::linalg_value_error) if `a` has invalid size.
175
+
- If `err` is not provided, exceptions will trigger an `error stop`.
176
+
177
+
### Notes
178
+
179
+
- This subroutine modifies `a` in-place. If the original matrix needs to be preserved, use [inv](@ref la_inverse::inv) instead.
180
+
- The determinant of `a` can be computed before inversion using [det](@ref la_determinant::det) to check for singularity.
181
+
- The computational complexity is \\( O(n^3) \\), making it expensive for large matrices.
182
+
- It is recommended to use matrix factorizations (e.g., LU or QR) for solving linear systems instead of computing the inverse explicitly, as it is numerically more stable and efficient.
183
+
184
+
185
+
## [operator(.inv.)](@ref la_inverse::operator(.inv.)) - Compute the inverse of a square matrix.
186
+
187
+
### Syntax
188
+
189
+
```fortran
190
+
invA = .inv. A
191
+
```
192
+
193
+
### Description
194
+
195
+
This operator computes the inverse \f$ A^{-1} \f$ of a square, non-singular real or complex matrix \f$ A \f$ using an LU decomposition. The inversion satisfies:
140
196
141
197
\f[
142
-
A^+ = V \Sigma^+ U^T
198
+
A A^{-1} = I
143
199
\f]
144
200
145
-
where \f$ \Sigma^+ \f$ is obtained by inverting the nonzero singular values.
201
+
where \f$ I \f$ is the identity matrix of appropriate size.
202
+
203
+
This operator is functionally equivalent to [inv](@ref la_inverse::inv) but provides a more convenient syntax. It supports operator chaining, allowing multiple inversions within expressions:
146
204
147
205
### Arguments
148
206
149
-
-`a`: A `real` or `complex` matrix of size \f$ [m,n] \f$, representing the input matrix to be inverted.
150
-
-`pinva`: A `real` or `complex` matrix of size \f$ [n,m] \f$, representing the pseudo-inverse of `a`. This is an output argument.
151
-
-`rtol` (optional): A real scalar specifying the relative tolerance for singular value truncation. Singular values smaller than `rtol * max(singular_values(A))` are set to zero. If not provided, a default machine-precision-based tolerance is used.
152
-
-`err` (optional): A [type(la_state)](@ref la_state_type::la_state) variable that returns the error state. If not provided, the function will stop execution on error.
207
+
-`A`: A `real` or `complex` square matrix of size \f$ [n,n] \f$, representing the input matrix to be inverted.
153
208
154
209
### Return value
155
210
156
-
The pseudo-inverse of the input matrix `a` is returned in `pinva`.
211
+
-`invA`: A `real` or `complex` square matrix of size \f$ [n,n] \f$, and same kind as `A` representing its inverse.
212
+
- If `A` is singular or the inversion fails, an **empty matrix** (size \f$ [0,0] \f$) is returned instead of raising an error.
157
213
158
214
### Errors
159
215
160
-
-Raises [LINALG_VALUE_ERROR](@refla_state_type::linalg_value_error) if the dimensions of `pinva` do not match the expected output size.
161
-
-Raises [LINALG_ERROR](@ref la_state_type::linalg_error) if the SVD decomposition fails.
162
-
-If `err` is not provided, exceptions will trigger an `error stop`.
216
+
-Unlike [inv](@refla_inverse::inv), this operator **does not provide explicit error handling**.
217
+
-If `A` is singular or an error occurs during inversion, the function **returns an empty matrix** (size \f$ [0,0] \f$) instead of raising an exception.
218
+
-The caller should check the size of the returned matrix to determine if inversion was successful.
163
219
164
220
### Notes
165
221
166
-
- This subroutine computes the pseudo-inverse using LAPACKs SVD decomposition routine [`*GESVD`](@ref la_lapack::gesvd).
167
-
- The choice of `rtol` affects numerical stability and rank estimation: setting it too high may result in an inaccurate inverse, while setting it too low may amplify numerical noise.
168
-
- This version requires `pinva` to be pre-allocated. To obtain the required size before allocation, use [`pseudoinvert_space`](@ref la_pseudoinvert::pseudoinvert_space).
169
-
222
+
- This operator internally calls LAPACK's LU decomposition routine [GETRF](@ref la_lapack::getrf) followed by [GETRI](@ref la_lapack::getri).
223
+
- The chaining property allows for concise expressions but requires caution: if any intermediate inversion fails, subsequent operations may propagate errors due to empty matrix results.
224
+
- If strict error handling is required, use [inv](@ref la_inverse::inv) instead.
170
225
171
226
## [pinv](@ref la_pseudoinverse::pinv) - Moore-Penrose pseudo-inverse of a matrix (function).
172
227
@@ -210,7 +265,7 @@ where \f$ \Sigma^+ \f$ is obtained by inverting the nonzero singular values.
210
265
211
266
### Notes
212
267
213
-
- This function computes the pseudo-inverse using LAPACKs SVD decomposition routine [`*GESVD`](@ref la_lapack::gesvd).
268
+
- This function computes the pseudo-inverse using LAPACK's SVD decomposition routine [`*GESVD`](@ref la_lapack::gesvd).
214
269
- The choice of `rtol` affects numerical stability and rank estimation: setting it too high may result in an inaccurate inverse, while setting it too low may amplify numerical noise.
215
270
- This function returns a newly allocated matrix. For an in-place version, use [`pseudoinvert`](@ref la_pseudoinverse::pseudoinvert).
216
271
@@ -255,7 +310,7 @@ where \f$ \Sigma^+ \f$ is the inverse of the nonzero singular values in \f$ \Sig
255
310
### Notes
256
311
257
312
- This operator internally calls [pinv](@ref la_pseudoinverse::pinv) and behaves identically.
258
-
- The pseudo-inverse is computed using LAPACKs SVD decomposition routine [GESVD](@ref la_lapack::gesvd).
313
+
- The pseudo-inverse is computed using LAPACK's SVD decomposition routine [GESVD](@ref la_lapack::gesvd).
259
314
- This operator is a convenient shorthand for calling the functional interface `pinv(a)`.
0 commit comments