Solve the linear least squares program
min 0.5 sumsq(C*x - d) x
subject to
A*x <= b, Aeq*x = beq, lb <= x <= ub.
The initial guess x0 and the constraint arguments (A and
b, Aeq and beq, lb and ub) can be set to
the empty matrix ([]
) if not given. If the initial guess
x0 is feasible the algorithm is faster.
options can be set with optimset
, currently the only
option is MaxIter
, the maximum number of iterations (default:
200).
Returned values:
Position of minimum.
Scalar value of objective as sumsq(C*x - d).
Vector of solution residuals C*x - d.
Status of solution:
0
Maximum number of iterations reached.
-2
The problem is infeasible.
-3
The problem is not convex and unbounded.
1
Global solution found.
Structure with additional information, currently the only field is
iterations
, the number of used iterations.
Structure containing Lagrange multipliers corresponding to the constraints.
This function calls the more general function quadprog
internally.
See also: quadprog.
The following code
C = [0.9501 0.7620 0.6153 0.4057 0.2311 0.4564 0.7919 0.9354 0.6068 0.0185 0.9218 0.9169 0.4859 0.8214 0.7382 0.4102 0.8912 0.4447 0.1762 0.8936]; d = [0.0578; 0.3528; 0.8131; 0.0098; 0.1388]; %% Linear Inequality Constraints A =[0.2027 0.2721 0.7467 0.4659 0.1987 0.1988 0.4450 0.4186 0.6037 0.0152 0.9318 0.8462]; b =[0.5251; 0.2026; 0.6721]; %% Linear Equality Constraints Aeq = [3 5 7 9]; beq = 4; %% Bound constraints lb = -0.1*ones(4,1); ub = ones(4,1); [x, resnorm, residual, flag, output, lambda] = lsqlin (C, d, A, b, Aeq, beq, lb, ub)
Produces the following output
x = -0.1000 -0.1000 0.1599 0.4090 resnorm = 0.1695 residual = 0.035297 0.087623 -0.353251 0.145270 0.121232 flag = 1 output = scalar structure containing the fields: iterations = 3 lambda = scalar structure containing the fields: lower = 0.0674 0.2499 0 0 upper = 0 0 0 0 eqlin = -0.016539 ineqlin = 0 0.4982 0
Package: optim