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; endendyt1=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);
Best Answer