Forcing positive values when solving system of linear equations
36 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Meng Xi Zhu
el 15 de Dic. de 2021
Editada: John D'Errico
el 15 de Dic. de 2021
For finding the least squared error solution for X for the equation:
Ax = B
I am currently doing:
x = pinv(A) * B
However, in my case, there are negative values for X in the results, which is non desireable.
Is there a way to force X to be all non-negative values when solving the equation Ax = B using preferably SVD?
0 comentarios
Respuesta aceptada
John D'Errico
el 15 de Dic. de 2021
Editada: John D'Errico
el 15 de Dic. de 2021
Sorry. PINV does not allow you to constrain the sign of your estimates.
You can use LSQNONNEG, which does allow you to do that, or you can use a tool like LSQLIN (from the optimization toolbox.)
For eample here, A is a 100x7 matri, with rank 5 by design.
A = randn(100,5)*randn(5,7);
rank(A)
b = randn(100,1);
As you can see, A\b gets upset at you, because A is singular.
A\b
However lsqnonneg does not yell at you about a singular matrix A, so you may prefer that. But does it explicitly use the SVD? No. It uses an active set strategy, choosing a subset of the unknowns to be non-negative.
lsqnonneg(A,b)
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Linear Algebra en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!