sum of coefficients less than 1
1 次查看(过去 30 天)
显示 更早的评论
Can someone please modify the following code so that it has a constraint that the sum of ar1 and ar2 is less than one.
Thanks
clc;
clear;
m=2;
a0 = 0.1; a1 = 0.2; a2=0.15;
epsi=zeros(3000,1);
simsig=zeros(3000,1);
for i = 1:3000
if (i==1)
simsig(i) = a0/(1-a1-a2) ;
s=(simsig(i))^0.5;
epsi(i) = normrnd(0,1) * s;
elseif (i==2)
epsi(i)=epsi(1);
else
simsig(i) = a0+ a1*(epsi(i-1))^2+a2*(epsi(i-2))^2;
s=(simsig(i))^0.5;
epsi(i) = normrnd(0,1) * s;
end
end
yt1=epsi.^2;
ytlast=epsi(3000)^2;
ytlast2=epsi(2999)^2;
ytinitial=yt1(2001:3000);
yt = yt1(2003:3000);
ytlag1= yt1(2002:2999);
ytlag2= yt1(2001:2998);
a =ones(1000-m,1);
x = [a,ytlag1,ytlag2];
opts = optimset('lsqnonneg');
opts.LargeScale = 'off';
opts.Display = 'none';
coef = lsqnonneg(x,yt);
alpha0 =coef(1);
ar1=coef(2);
ar2= coef(3);
0 个评论
采纳的回答
Shashank Prasanna
2013-3-3
Do you have the optimization toolbox? LSQNONNEG cannot handle constraints.
Also, please format your code when you post. It makes it easier to read code. You can select your code and use the '{}Code' button.
9 个评论
Teja Muppirala
2013-3-5
To make coeff(2) + coeff(3) < 1, you can call LSQLIN like this:
coeff = lsqlin(x,yt,[0 1 1],[1],[],[],[0;0;0],[1;1;1])
See the help for LSQLIN
更多回答(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!