Created
May 10, 2012 20:13
-
-
Save mac-r/2655592 to your computer and use it in GitHub Desktop.
Ornstein-Unlenbeck in Maple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
restart; | |
with(Statistics): | |
STDNORM:=proc( ) local ij,U1,U2,S,B,X1;global i,X2; | |
if type(i,boolean)then | |
if (i) then | |
i:=not(i);X2; | |
else | |
for ij from 1 to infinity do | |
U1:=evalf(2.0*rand()/10^12)-1.0; | |
U2:=evalf(2.0*rand()/10^12)-1.0; | |
S:=U1*U1+U2*U2; | |
if(S=1.0 or S<=0.0) then next end if; | |
B:=sqrt(-2.0*ln(S)/S); | |
X1:=B*U1; | |
X2:=B*U2; | |
break; | |
end do; | |
i:=not(i);X1; | |
end if; | |
else ERROR("i should be boolean") end if; | |
end proc: | |
meanreverting:=proc(T,n,alpha,m,nu,y0) local h,P,j,z,a,b,d,A,Y; | |
global i,X2; | |
i:=false; | |
h:=T/n; | |
Y:=y0; | |
P[0]:=[0,evalf(y0)]; | |
a:=evalf(exp(-alpha*h)); | |
b:=sqrt(1-a^2); | |
d:=m*(1-a); | |
for j from 1 to n do; | |
z:=STDNORM(); | |
Y:=d+Y*a+nu*b*z; | |
P[j]:=[evalf(j*h),Y]; | |
end do; | |
seq(P[j],j=0..n); | |
end proc: | |
y0:= 0.02673189: m:= 0.0051: nu:= 0.51936: N:= 12: M:= 1000: T:= 1: h := T/N:alpha:=20: | |
randomize(): | |
SPr := seq([meanreverting(T,N,alpha,m,nu,y0)], i = 1 .. M): | |
for k to N do: | |
RIU[k] := Mean([seq(SPr[i][k][2], i = 1 .. M)]): | |
end do: | |
RIU_plot:=seq(RIU[k],k=1..12); | |
PLOT(CURVES(SPr),TITLE("Прогноз темпов роста аудитории российского интернета")); | |
#PLOT(CURVES(RIU_plot),TITLE("Прогноз темпов роста аудитории российского интернета")); | |
RIU_plot := 0.02673189000, 0.002775788100, 0.0007051991596, | |
0.01460316795, -0.001395036910, 0.01100092534, 0.02954795427, | |
0.01744122578, 0.01662275555, 0.03567445478, -0.004317302288, | |
0.05583135921 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment