Solve a system of linear equations

조회 수: 6 (최근 30일)
Chubashini
Chubashini 2024년 2월 28일
편집: John D'Errico 2024년 2월 28일
Hello,
I would like to solve a system of linear equations for the unknowns xj using a least-squared approximation procedure with a non-negative constraint (using the lsqnonneg function in MATLAB). The linear equation system is represented as S=YA, where S is a 30-element vector containing all the si values, Y is a 30×n matrix containing all the yj,i values, and A is an n-element vector containing the unknowns xj. While I can solve each equation for individual sample using the lsnonneg function in MATLAB, I am seeking guidance on how to solve the equations for many samples simultaneously..
Thanks,

답변 (1개)

John D'Errico
John D'Errico 2024년 2월 28일
편집: John D'Errico 2024년 2월 28일
I am confused. You say that you know how to solve the problem using lsqnonneg. So just use it!
n = 30;
Y = rand(30,n);
S = rand(30,1);
See, that if I just use backslash here, it will produce a result that is not bounded to be nonnegative.
xslash = Y\S
xslash = 30×1
0.3452 -0.8259 -2.7427 -0.2307 -2.4206 -0.3200 -1.8315 -1.9436 -1.1118 4.4774
As such, you use lsqnonneg. And you do not use lsqnonneg one equation at a time. It applies to the entire system.
x = lsqnonneg(Y,S)
x = 30×1
0.0204 0.0166 0.4094 0 0 0 0 0.1144 0 0

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by