Link to home
Start Free TrialLog in
Avatar of Bijaya Nepal
Bijaya Nepal

asked on

Drunken sailor

Question :You are to simulate the motion of a drunken sailor (i.e. a random walk problem).  The sailor is standing at the middle of a pier on the shore side.  The sailor’s ship is directly across from him.The pier size is L paces long and W paces wide (i.e. the sailor starts at coordinates ½ W, 0 and the ship is L paces away) and the ship stretches across the entire width of the pier.Due to the sailor’s inebriated condition a straight walking path cannot be maintained.  Each second the sailor attempts to take a step.  There is a 25% chance that the sailor will go left, a 20% chance the sailor will go right, a 10% chance the sailor will stand still, and a 45% chance the sailor will go forward.  Assume the sailor does not go backwards.If the sailor’s position exceeds the dimensions of the pier (zero to W) they fall into the sea.  If they make it to the other side they are safe at their ship.Write a  Matlab program(script file) that takes L and W as user inputs.  The motion of the sailor is then simulated.  If the sailor falls into the sea an appropriate message should be output.  If the sailor makes it to the ship the time and number of paces it took them should be output.  For either case a plot showing the sailor’s path should be made.
Hint: Use evenly distributed random numbers to determine what direction the sailor goes.
Avatar of Patrick Bogers
Patrick Bogers
Flag of Netherlands image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No more questions from poster