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.
Bijaya NepalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Patrick BogersDatacenter platform engineer LindowsCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Patrick BogersDatacenter platform engineer LindowsCommented:
No more questions from poster
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MATLAB Programming

From novice to tech pro — start learning today.