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
`c`: Shall be a rank-2 `real` or `complex` array of the same kind as `a` defining the linear equality constraints. It is an `intent(in)` argument.
1112
1112
`lwork`: Shall be an `integer` scalar returning the optimal size required for the workspace array to solve the constrained least-squares problem.
1113
1113
1114
+
## `weighted_lstsq` - Computes the weighted least squares solution to a linear matrix equation {#weighted-lstsq}
1115
+
1116
+
### Status
1117
+
1118
+
Experimental
1119
+
1120
+
### Description
1121
+
1122
+
This function computes the weighted least-squares solution to a linear matrix equation \( A \cdot x = b \) where each observation has a different weight.
1123
+
1124
+
The solver minimizes the weighted 2-norm \(\| D(Ax - b) \|_2^2 \) where \( D = \mathrm{diag}(\sqrt{w}) \) is a diagonal matrix formed from the square roots of the weight vector. This is equivalent to transforming the problem to ordinary least-squares through row scaling. The solver is based on LAPACK's `*GELSD` backends.
1125
+
1126
+
### Syntax
1127
+
1128
+
`x = `[[stdlib_linalg(module):weighted_lstsq(interface)]]`(w, a, b [, cond, overwrite_a, rank, err])`
1129
+
1130
+
### Arguments
1131
+
1132
+
`w`: Shall be a rank-1 `real` array containing the weight vector. For complex `a` and `b`, `w` shall use the same real kind as the components of `a`. All weights must be positive. It is an `intent(in)` argument.
1133
+
1134
+
`a`: Shall be a rank-2 `real` or `complex` array containing the coefficient matrix. It is an `intent(inout)` argument.
1135
+
1136
+
`b`: Shall be a rank-1 array of the same kind as `a`, containing the right-hand-side vector. It is an `intent(in)` argument.
1137
+
1138
+
`cond` (optional): Shall be a scalar `real` value cut-off threshold for rank evaluation: singular values with `s_i <= cond*maxval(s)` are treated as zero, and the rank counts values with `s_i > cond*maxval(s), i=1:rank`. Shall be a scalar, `intent(in)` argument.
1139
+
1140
+
`overwrite_a` (optional): Shall be an input `logical` flag. If `.true.`, input matrix `a` will be used as temporary storage and overwritten. This avoids internal data allocation. This is an `intent(in)` argument.
1141
+
1142
+
`rank` (optional): Shall be an `integer` scalar value, that contains the rank of input matrix `a`. This is an `intent(out)` argument.
1143
+
1144
+
`err` (optional): Shall be a `type(linalg_state_type)` value. This is an `intent(out)` argument.
1145
+
1146
+
### Return value
1147
+
1148
+
Returns an array value of the same kind as `a`, containing the weighted least-squares solution.
1149
+
1150
+
Raises `LINALG_VALUE_ERROR` if any weight is non-positive or if the matrix and weight/right-hand-side have incompatible sizes.
1151
+
Raises `LINALG_ERROR` if the underlying Singular Value Decomposition process did not converge.
1152
+
Exceptions trigger an `error stop`.
1153
+
1154
+
### Example
1155
+
1156
+
```fortran
1157
+
{!example/linalg/example_weighted_lstsq.f90!}
1158
+
```
1159
+
1160
+
## `solve_weighted_lstsq` - Compute the weighted least squares solution to a linear matrix equation (subroutine interface). {#solve-weighted-lstsq}
1161
+
1162
+
### Status
1163
+
1164
+
Experimental
1165
+
1166
+
### Description
1167
+
1168
+
This subroutine computes the weighted least-squares solution to a linear matrix equation \( A \cdot x = b \) where each observation has a different weight.
1169
+
1170
+
The solver minimizes the weighted 2-norm \(\| D(Ax - b) \|_2^2 \) where \( D = \mathrm{diag}(\sqrt{w}) \) is a diagonal matrix formed from the square roots of the weight vector. This is equivalent to transforming the problem to ordinary least-squares through row scaling. The solver is based on LAPACK's `*GELSD` backends.
1171
+
1172
+
### Syntax
1173
+
1174
+
`call `[[stdlib_linalg(module):solve_weighted_lstsq(interface)]]`(w, a, b, x [, cond, overwrite_a, rank, err])`
1175
+
1176
+
### Arguments
1177
+
1178
+
`w`: Shall be a rank-1 `real` array containing the weight vector. For complex `a` and `b`, `w` shall use the same real kind as the components of `a`. All weights must be positive. It is an `intent(in)` argument.
1179
+
1180
+
`a`: Shall be a rank-2 `real` or `complex` array containing the coefficient matrix. It is an `intent(inout)` argument.
1181
+
1182
+
`b`: Shall be a rank-1 array of the same kind as `a`, containing the right-hand-side vector. It is an `intent(in)` argument.
1183
+
1184
+
`x`: Shall be a rank-1 array of the same kind as `a`, and size of at least `n`, containing the solution to the weighted least squares system. It is an `intent(inout)` argument.
1185
+
1186
+
`cond` (optional): Shall be a scalar `real` value cut-off threshold for rank evaluation: singular values with `s_i <= cond*maxval(s)` are treated as zero, and the rank counts values with `s_i > cond*maxval(s), i=1:rank`. Shall be a scalar, `intent(in)` argument.
1187
+
1188
+
`overwrite_a` (optional): Shall be an input `logical` flag. If `.true.`, input matrix `a` will be used as temporary storage and overwritten. This avoids internal data allocation. This is an `intent(in)` argument.
1189
+
1190
+
`rank` (optional): Shall be an `integer` scalar value, that contains the rank of input matrix `a`. This is an `intent(out)` argument.
1191
+
1192
+
`err` (optional): Shall be a `type(linalg_state_type)` value. This is an `intent(out)` argument.
1193
+
1194
+
### Return value
1195
+
1196
+
Returns an array value of the same kind as `a`, containing the weighted least-squares solution.
1197
+
1198
+
Raises `LINALG_VALUE_ERROR` if any weight is non-positive or if the matrix and weight/right-hand-side have incompatible sizes.
1199
+
Raises `LINALG_ERROR` if the underlying Singular Value Decomposition process did not converge.
1200
+
Exceptions trigger an `error stop`.
1201
+
1202
+
### Example
1203
+
1204
+
```fortran
1205
+
{!example/linalg/example_weighted_lstsq.f90!}
1206
+
```
1207
+
1114
1208
## `det` - Computes the determinant of a square matrix
0 commit comments