Solve an overdetermined problem with lsqlin
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
John D'Errico
2019-5-2
编辑:John D'Errico
2019-5-2
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?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Least Squares 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!