Loosely Constrained Least Squares Solution
Mostra commenti meno recenti
Thanks in advance!
I am attempting to find the least squares solution to the matrix equation Ax=b. A, n x m, is a thin matrix, where n>>m, leading to an overdetermined system. Additionally, the system is constrained loosely by the equation Cx=d, where C is a 4x21 matrix and d is a 4x1 vector. Finally, the solutions should fall within the range [-1 1].
For context, I am attempting to optimize a set of Chebyshev polynomial coefficients (hence the solution limit of [-1 1]) defined over the interval [-1 1], expanded to the 20th order, where the polynomial and polynomial first derivative endpoints are pinned to known values (Cx=d). A (n x m) here represents m nominal Chebyshev terms of the first kind (1, x, 2x^2-1, etc.) evaluated at n points between -1 and 1. b represents the value of the original polynomial evaluated at the same n points between -1 and 1, leaving the solution x to be the optimized Chebyshev coefficients.
As such, I applied the following options to lsqlin:
options = optimset('MaxIterations', 1000000, 'TolFun', 1e-5, 'TolCon', 1-e3)
And called lsqlin for each set of coefficients to optimize:
x = lsqlin(C,d,A,b,[],[],-1,1,[],options)
As previously stated, the constraint tolerance is loose, and error on the range of e-3 is acceptable. However, this method of calling lsqlin does not seem to allow for the constraints to have any tolerance. The first derivative endpoints of the resulting polynomials are pinned to the constraint values as desired, but to numerical precision, without any error allowance. This results in lsqlin being unable to find a solution to the problem within the allowed iterations (or even test runs two orders of magnitude higher), and unreasonable results output where coefficients are found to be on the order of e3, not within [-1 1].
Is there something I am missing with the application of constraint tolerances here? Or, is there a way to place a hierarcy on constraints, such that one will be met (coefficients within [-1 1]) at the expense of the other constraints?
Thanks again!
-CH
Risposta accettata
Più risposte (1)
Bruno Luong
il 30 Ago 2020
alpha = some positive value; % larget alpha, norm(C*x-d) gets smaller
E = [A; alpha*C];
f = [b; alpha*d];
x = lsqlin(E,f,[],[],[],[],-1,1,[],options)
3 Commenti
John D'Errico
il 30 Ago 2020
Modificato: John D'Errico
il 30 Ago 2020
An important point was missed here. When x is a vector, but the bounds are supplied only as a scalar, then the bounds only apply to the FIRST element of the vector. (I never liked that, but it is true. Far too many people make this mistake.)
So this is not valid for vector x.
x = lsqlin(E,f,[],[],[],[],-1,1,[],options)
Instead, use:
n = size(A,2);
lb = -ones(n,1);
ub = ones(n,1);
x = lsqlin(E,f,[],[],[],[],lb,ub,[],options);
If a scalar only is supplied, then consider this simple example:
lsqlin(randn(100,10),randn(100,1),[],[],[],[],0,1)
Minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the value of the optimality tolerance,
and constraints are satisfied to within the value of the constraint tolerance.
<stopping criteria details>
ans =
4.4012355548152e-10
0.0377174311402519
-0.0981597231592627
-0.102733917267231
0.0117681433517298
-0.0666227293207337
0.127194321772405
-0.12742206265685
-0.101845196324251
0.0025344777053746
As you can see, only the first element was constrained to have a lower bound of 0. The others were fully unconstrained.
Bruno Luong
il 30 Ago 2020
You might be right John. I just copy OP's bounds and focussing on the change of cost function and equality constraints.
John D'Errico
il 30 Ago 2020
Yes. I realize that you surely know the difference. This was more for the benefit of the OP, or others who would see your response.
Categorie
Scopri di più su Linear Least Squares in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!