Hello Masoud,
In MATLAB, the lsqlin function is designed to solve linear least squares problems with constraints, including upper and lower bounds on the variables. It does not transform these bounds into a quadratic format. Instead, lsqlin incorporates bounds directly within its optimization algorithm. Here's a concise explanation of how it operates:
- Problem Setup: lsqlin addresses problems structured as:[ \min_x | Cx - d |_2^2 ]subject to:
- ( A \cdot x \leq b )
- ( A_{eq} \cdot x = b_{eq} )
- ( lb \leq x \leq ub )
Here, ( lb ) and ( ub ) represent the lower and upper bounds for the decision variables ( x ).
2. Active Set Approach: lsqlin often employs an active set method to manage constraints, including bounds. This method involves iteratively determining which constraints are "active" (binding) in the solution.
3. Bound Management: Bounds are integrated directly into the optimization:
- If a variable reaches its bound during iterations, it becomes an active constraint.
- The algorithm then searches for solutions within the feasible region defined by these active constraints.
4. Algorithm Configuration: You can configure various algorithm options using optimoptions, such as selecting between the 'active-set' and 'trust-region-reflective' algorithms, which handle constraints in distinct ways.
This setup ensures that lsqlin respects the specified bounds throughout the optimization process.
C = [1, 2; 3, 4; 5, 6];
d = [7; 8; 9];
lb = [0; 0]; % Lower bounds
ub = [10; 10]; % Upper bounds
options = optimoptions('lsqlin', 'Algorithm', 'active-set', 'Display', 'iter');
x = lsqlin(C, d, [], [], [], [], lb, ub, [], options);
I hope it helps!