using lsqlin when you have a large matrix

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일

0 개 추천

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일

0 개 추천

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

dav
dav 2013년 2월 18일
편집: Walter Roberson 2013년 2월 18일
thanks. I am relatively new to matlab. My code is given below. is there any way to correct that code?
a0 = 0.05; a1 = 0.1; b1 = 0.85;
nu = randn(2300,1);
epsi = zeros(2300,1);
h = zeros(2300,1);
for i=2: 2300
h(i) = a0 + a1 * epsi(i-1)^2 + b1 * h(i-1) ;
epsi(i) = nu(i) * sqrt(h(i));
end
yt = zeros(2300,1);
for i=1: 2300
yt(i) = epsi(i)*epsi(i);
end
order = 5;
m = arx(yt, order);
r = resid([yt(1:order);yt], m);
r = r(order+1:end);
yt2 = zeros(2300,1);
for i=1: 2300
yt2(i) = yt(i)- r(i);
end
yt2(1:1300) = [];
yt(1:1299)=[];
yt(1001:1001)=[];
r(1:1299)=[];
r(1001:1001)=[];
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);
Walter Roberson
Walter Roberson 2013년 2월 18일
Even if you only have two constraints that you want to actively make use of, you need to supply values for the others, possibly "inf".
Matt J
Matt J 2013년 2월 18일
is there any way to correct that code?
As I already mentioned, it is an error to use a 2x2 matrix a=eye(2) and 2x1 vector b=zeros(2,1) when you have more than 2 unknowns.
Teja Muppirala
Teja Muppirala 2013년 2월 18일
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.
Teja Muppirala
Teja Muppirala 2013년 2월 18일
Oops I meant C, not A.
Matt J
Matt J 2013년 2월 18일
There are not 1000 unknowns, there are only 2.
Ah well. The question has been edited.

댓글을 달려면 로그인하십시오.

카테고리

태그

질문:

dav
2013년 2월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by