Solve an overdetermined problem with lsqlin
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am having trouble formatting the inputs to lsqlin. I would like to solve for x in Cx=d, where C is 100 by 5 and d is 100 by 10 so x has to be 5 by 10. I would like to impose the constraint that d>0 and d<15. Here is my example.
C = rand(10,5); d = rand(10,15); % Create example inputs
% Skip inputs that don't seem to be required for the problem
A = []; b = [];
Aeq = []; beq = [];
% Set up the lower and upper bound constraints
[rowC,colC] = size(C);
[rowD,colD] = size(d);
dum = zeros(colC,colD); % Placeholder matrix which is the same size as x
lowerBound = 0*dum; % Lower bound on all values of x is zero
upperBound = 100 + dum; % Upper bound
x = lsqlin(C, d, A, b, Aeq, beq, lowerBound, upperBound);
I get the following error,
Error using lsqlin (line 226)
The number of rows in C must be equal to the length of d.
Matlab defines the length of a matrix to be the larger of its dimensions, so here the length of b is 15. This error occurs even for the simpler problem
x = lsqlin(C, d);
I am missing something basic in the setup here. What is it? If I should use a nonlinear solver instead like lsqnonlin, what is the input function?
0 Kommentare
Akzeptierte Antwort
John D'Errico
am 2 Mai 2019
Bearbeitet: John D'Errico
am 2 Mai 2019
lsqlin is not written to allow multiple right hand side vectors. But each column of d is just a separate, distinct, independent problem. So just use a loop. WTP?
1 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Linear Least Squares finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!