using lsqlin when you have a large matrix

1 次查看(过去 30 天)
hi,
Can someone please tell me how to correct the following code.
x = [yt,r];
a = eye(2);
b = zeros(2,1);
opts = optimset('lsqlin');
opts.LargeScale = 'off';
opts.Display = 'none';
coef = lsqlin(x,yt2,-a,-b);
My x is a 1000*2 matrix. so i get an error. I read the help for that but couldn't understand it clearly.
thanks.

采纳的回答

Teja Muppirala
Teja Muppirala 2013-2-18
I don't think there is anything wrong with this code, except LSQNONNEG would be easier.
coef = lsqlin(x,yt2,-a,-b);
is the same as
coef = lsqnonneg(x,yt2);
When I run your core, I don't get any errors at all. I just get
coef =
0.4036
0
Which I have no reason to doubt is a valid answer.
Are you perhaps referring to the warning that comes up regarding the solver?
  1 个评论
dav
dav 2013-2-18
编辑:dav 2013-2-18
thanks I also figured it out that coef = lsqnonneg(x,yt2) is much easier.

请先登录,再进行评论。

更多回答(1 个)

Matt J
Matt J 2013-2-18
编辑:Matt J 2013-2-18
If you have 1000 unknowns why is "a" only 2x2?
Also, since your constraints are only lower bounds on the unknowns, use the lb input argument instead of A,b
Also, since you only have positivity constraints, consider using LSQNONNEG instead of LSQLIN.
  6 个评论
Matt J
Matt J 2013-2-18
There are not 1000 unknowns, there are only 2.
Ah well. The question has been edited.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Linear Least Squares 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by