function[vmrs,VERS,H,C,R]=RS2(vector)
%this program makes use of the classical R/S method.
N=length(vector);
n=5;
vmrs=[];
%the vector vmrs is used to save the log of the mean value of R/S.
h=[];
%this vector is used to save the log value of length n.
VRS=[];
%it represents V-statistic
while n<N
a=floor(N/n);
s=0;
for i=1:a;
v1=zeros(n,1);
vl=vector(n*(i-1)+1:n*(i-1)+n);
m=mean(v1);
%find the mean value of the I-th sub-vector.
v2=v1-m;
v3=cumsum(v2);
%the cumulative deviations from mean of the I-th sub-vector.
r=max(v3)-min(v3)
%range calculation.;
sig=std(v1,1);
%sample standard deviations normalized by n.
rs=r/sig;
s=s+rs;
%the sum of rescaled range for¡®a¡¯sub-vectors correspond to the
%length n of subvector.
end
mrs=s/a;
vmrs=[vmrs;log10(mrs)];
h=[h;log10(n)];
VRS=[VRS;mrs/sqrt(n)];
n=n+1;
end
figure(1);
[H,C,R]=postreg(vmrs','h');
%to make use of BP network to make regression about¡®vmrs¡¯versus¡®h¡¯
figure(2)'
plot(h,vmrs,'*')
hold on;
y=C+H*h;
plot(h.y,'r-');
hold on;
polt(h,VRS,'r');
disp(VRS');
figure(3);
plot(h,vmrs,'*')
Cn=2^(2*H-1)-1;
disp('the correlation funtion Cm=');
disp(Cn);