MATLAB Answers


using lsqlin when you have a large matrix

Asked by dav
on 18 Feb 2013


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.



Log in to comment.


2 Answers

Answer by Teja Muppirala
on 18 Feb 2013
 Accepted Answer

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 =


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 Comment

thanks I also figured it out that coef = lsqnonneg(x,yt2) is much easier.

Log in to comment.

Answer by Matt J
on 18 Feb 2013
Edited by Matt J
on 18 Feb 2013

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.


There are not 1000 unknowns, there are only 2. It only seems that way because what the documentation refers to as A, is being called x here, and what the doc refers to as x, is being called coef.

Oops I meant C, not A.

There are not 1000 unknowns, there are only 2.

Ah well. The question has been edited.

Log in to comment.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!