SHARE
TWEET

Untitled

a guest Jun 18th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. x(t+1)=x(t)-1; probability p=0.3
  2. x(t+1)=x(t)-2; probability q=0.2
  3. x(t+1)=x(t)+1; probability p=0.5
  4.      
  5. p=0.3;
  6. q=0.2;
  7. s=0.5;
  8. numberOfSteps = 100;
  9. maxCount = 10000;
  10. for count=1:maxCount
  11.     x=0;
  12.     for i = 1:numberOfSteps
  13.         random = rand(1, 1);
  14.         if random <=p
  15.             x=x-1;
  16.         elseif random<=(p+q)
  17.             x=x-2;
  18.         else
  19.             x=x+1;
  20.         end
  21.     end
  22.     xfinal(count) = x;
  23. end
  24. [f,x]=hist(xfinal,30);
  25. figure(1)
  26. bar(x,f/sum(f));
  27. xlabel('xfinal')
  28. ylabel('frequency')
  29. mean = mean(xfinal)
  30. variance = var(xfinal)
  31.      
  32. [nelements,centers] = hist(data,nbins);
  33.   plot(centers,nelements);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top