Here are two versions of the iterlin() program described in Chapter 1.
- A Maple procedure
As you enter the code, you need to press [SHIFT-ENTER] at the end of each line, except for the last, where you press [ENTER]. The code defines a procedure that takes four arguments, a, b, x0, and n. So, for example, to generate the first ten iterates of the functioniterlin := proc(a, b, x0, n) local i,x; x := x0: for i from 1 to n do x := a*x + b: print(evalf(x)): end do: end proc:f(x) = -0.5x+4 starting with x0 = 5, we enter> iterlin(-0.5, 4, 5, 10);
- A Mathematica function
Type this in as a single line, followed by [SHIFT-ENTER]. Now iterlin is defined as a function of the four variables a, b, x0, and n. To get a list of the first ten iterates of the functioniterlin[a_, b_, x0_, n_] := NestList[(a #1 + b)&, x0, n]f(x) = -0.5x+4 starting with x0 = 5, we type infollowed by [SHIFT-ENTER].> iterlin[-0.5, 4, 5, 10]