We help IT Professionals succeed at work.

Drunken sailor

Bijaya Nepal
Bijaya Nepal asked
Last Modified: 2017-04-06
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.
Watch Question

Datacenter platform engineer Lindows
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
Patrick BogersDatacenter platform engineer Lindows

No more questions from poster

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions