how to do random walk?
Mostrar comentarios más antiguos
1. Write a function xrand(x) which takes as input a number from 0 to 100 and as output returns 1 with likelihood x% and returns -1 with likelihood (100 - x)%. For example, if you evaluate wrand(70.8) one hundred thousand times, you should see approximately 70,800 1s and 29,200 -1s. (Make sure your function works even if w is not an integer.)
2. Write a “weighted” random walk rwalk(n,x) which continues until it is a distance of n from the origin and where the steps are taken using the wrand(x) function. (You should not be typing any of the same code from wrand in this function. Instead you should just be typing “wrand”, which will use the function you’ve just written.)
3 comentarios
James Tursa
el 8 de Feb. de 2018
What have you done so far? What specific problems are you having with your code?
siemcheng ngor
el 8 de Feb. de 2018
Jos (10584)
el 8 de Feb. de 2018
Think about:
- what does the statement rand(w) return
- when does w==rand(w) evaluate to true?
- how many statements are there in the else-block?
Respuestas (1)
Image Analyst
el 9 de Feb. de 2018
0 votos
I have a few random walk demos. You might look them over. Adapt as needed if they look close to what you want.
2 comentarios
Natesha Alexander
el 18 de Nov. de 2018
I am trying to simulate a symmetric random walk on a line where deltax and delta t =0.1
Image Analyst
el 18 de Nov. de 2018
OK, good luck.
If you ever do have a question, post in a new link with your code.
Categorías
Más información sobre Random Number Generation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!