7. Lists III: Repetition with Lists:  Homework

Last revision:  January 26 1998

Author: YourNameGoesHere

1. Iteration Towards a Fixed Point

One way to solve an equation of the form  "f[x] == x"  is to start with some guess and just "keep pressing the f button" (i.e., x, f[x], f[f[x]],...).  It may happen that the successive values get closer and closer to one particular value.  If this is the case, we say that the sequence converges.   If the sequence converges, it will converge to a solution of "f[x] == x", called a fixed point.  Use both "FindRoot[]" (which will give you the solution) and iteration (with an initial guess somewhere close to the actual solution) to solve

 (a)  Cos[x] == x  

and

 (b) Exp[-x] == x.  

Show a sequence of iteration values that converge to each solution.

2. Drunkard's Walk

In the last homework you created a list of 10 directions in a random walk.  Now we'd like to record the stops that each of these steps take you to if you start from the origin.  For example, suppose your list of random directions started with { {1,0},{1,0},{0,-1},...}, then your list of stops would be {{0,0},{1,0},{2,0},{2,-1},...}.

While we could use our old list of directions (up={0,1}, right={1,0}, and so on), let's be
a little more imaginative.  Let us say that a random direction is a list of two numbers, {a,b},
where "a" is a random Real number between -1 and 1, and "b" is similarly a random Real
number between -1 and 1.  (Note:  when we describe data as having (sub)elements "a", "b", and so forth, with particular properties, we are not indicating that any variables, such as "a" and "b", should be defined.  Instead, we are simply using letters to denote portions of the data element.  In this instance, then, we mean that a random direction is any pair of random real numbers between -1 and 1, such as {-0.4566,0.2424}.)

(a) Create a function "randDir[]" taking one argument "n" which will return a list of
n directions, as defined above.

(b) Now create a function "stops[]", taking one argument, "n", that will give you the stops of a walk which has random directions given by "randDir[]".  Hint:  think in terms of {0,0} + {a,b} + {c,d} + ...

(c) Use the option "PlotJoined->True" in the function "ListPlot[]" to get a picture of a drunkard's walk of 500 steps.

3. Indecisive Walker

An indecisive man is unsure about where to spend his day.  He could stay home, at coordinate {0,0}, go to the beach at {100,0}, or go to work at {50,87}.  Starting from the point {50,44}, he makes a random choice about which of the three possibilities to pursue.  Unfortunately the man proceeds only halfway to his choice before having a crisis about his decision.  He stops at this crisis point, makes a new random choice (possibly the same as before), and heads off.  Again the walker proceeds only halfway to his choice before having another crisis.  The indecisive man spends the entire day repeating this procedure, roughly 1000 times.  Produce a plot simulating the location of all of the crisis points.  (Recall from mathematics class that the midpoint of a line segment between the points {a,b} and {c,d} is {(a+c)/2, (b+d)/2}.)