#C26.txt: Tne Metropolis algorithm (Monte Carlo) Help:=proc(): print(`RandMC(n,M),LD(P), SimMC(L,Ini,K) `): print(`ST(L) , TestST(L,Ini,K1,K2)`): end: #LD(P): outputs i with prob. P[i] LD:=proc(P) local m,i,P1, r: m:=ilcm(seq(denom(P[i]),i=1..nops(P))): P1:=m*P: r:=rand(1..convert(P1,`+`))(): for i from 1 to nops(P1) while convert([op(1..i,P1)],`+`)j, Ini, the initial distribution #warm-up of K1 steps, and records the location of #the next K2 steps TestST:=proc(L,Ini,K1,K2) local Exa,Path,x,App: Exa:=evalf(ST(L)): Path:=SimMC(L,Ini,K1+K2): App:=evalf(add(x[Path[i]],i=K1+1..K1+K2)/K2): App:=[seq(coeff(App,x[i],1),i=1..nops(L))]: Exa,App: end: