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

16 visualizaciones (últimos 30 días)
hinami
hinami el 3 de Sept. de 2020
Editada: John D'Errico el 3 de Sept. de 2020
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?

Respuesta aceptada

John D'Errico
John D'Errico el 3 de Sept. de 2020
Editada: John D'Errico el 3 de Sept. de 2020
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.

Más respuestas (1)

David Hill
David Hill el 3 de Sept. de 2020
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));

Categorías

Más información sobre Linear Least Squares en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by