How can I solve the set of liner equations using lsqlin?

10 次查看(过去 30 天)
Given the set of 5 linear equations above, I'd like to optimize unknown parameters A, B, C, D and E using a function lsqlin. For example, coefficients r and given values R are as below:
Each unknown parameters (A, B, C, D, and E) must be between 0 and 1. Could you somebody help me with this?

采纳的回答

John D'Errico
John D'Errico 2020-9-3
编辑:John D'Errico 2020-9-3
IF it is ok to violate the sum to 1, then do as David has shown. The solution he wrote will allow that equation to be violated.
HOWEVER, if that must be treated as inviolable, then you need to use an equality constraint.
% r and R represent equationions that can be violted.
r = [.95,.89,.33,.31,.08;.95,.86,.036,.32,.08;.95,.73,.35,.21,.08;.87,.46,.32,.13,.08];
R=[.49;.47;.42;.19];
% the equality constraint, that the unknowns sum to 1
Aeq = [1 1 1 1 1];
beq = 1;
lb = zeros(1,5);
ub = ones(1,5);
ABCDE = lsqlin(r,R,[],[],Aeq,beq,lb,ub);
You can unpack the values of A,B,C,D,E into scalar variables. However, my suggestion is to keep them in vector form.
Finally since the problem you have written is an underdetermined one, it MAY have an exact solution, however the bound constraints may prevent that from happening. If the array r has more than 4 rows, then this will usually be a least squares problem. In that case, then you would usually want to keep the equality constraint separate.
Usually the best way to solve problems of this sort is to keep the equality constraints separate from the equations that can allow some amount of violation.

更多回答(1 个)

David Hill
David Hill 2020-9-3
r=[.95,.89,.33,.31,.08;.95,.86,.036,.32,.08;.95,.73,.35,.21,.08;.87,.46,.32,.13,.08;1,1,1,1,1];
R=[.49;.47;.42;.19;1];
x=lsqlin(r,R,[],[],[],[],zeros(5,1),ones(5,1));

类别

Help CenterFile Exchange 中查找有关 Linear Least Squares 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by