sum of coefficients less than 1
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Shashank Prasanna
el 3 de Mzo. de 2013
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 comentarios
Teja Muppirala
el 5 de Mzo. de 2013
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
Más respuestas (0)
Ver también
Categorías
Más información sobre Linear Least Squares en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!