q=0.6;
n=4;
x0=[1120,1150,1450,1710];
g1=exp(-2/(n+1));g2=exp(2/(n+1));g3=0;
for i=2:n
g4=x0(i-1)/x0(i);
if (g4g2)
g3=1+g3;
end
end
g3
x1(1)=x0(1);c=0;d=0;e=0;f=0;
for i=2:n
x1(i)=x0(i)+x1(i-1);
z1(i)=q*x1(i)+(1-q)*x1(i-1);
z2(i)=z1(i)*z1(i);
c=z1(i)+c;
d=x0(i)+d;
e=z1(i)*x0(i)+e;
f=z2(i)+f;
end
a=(c*d-(n-1)*e)/((n-1)*f-c*c);
b=(d*f-c*e)/((n-1)*f-c*c);
g=b/a;
m=-1*n*a;
y=(x0(1)-g)*exp(m)+g;
x=y-x1(n);
x