Lab 1, iteration of linear functions

In this lab, you will explore what happens when you apply a linear function $ax+b$ again and again to a given initial value $x_0$. Using Sage to help you automate your investigations, you will observe the iteration process for many values of $a$, $b$, and $x_0$. If all goes well, patterns will start to emerge…. I will give you gidance on how to write your findings, and after a couple weeks, you will hand in a fancy article.

Due dates

A short draft which includes your first section and at least part of your second section is due on Monday, September 9. A final draft is due Monday, September 16.

Code hints

  • To get the last element of an array a, use the syntax a[-1].
  • To round a quantity q off with three decimal points of accuracy, use the syntax round(q,3).

My example code

def iterlin(a,b,x0,n=20):
    output = [x0]
    for i in range(n):
        output.append( a*output[-1]+b )
    return [round(x,3) for x in output]

Problem #6:

convergent_pairs = []
divergent_pairs = []
for a in vector(range(-30,31))/10 :
    for b in vector(range(-30,31))/10 :
        s = iterlin( a, b, 2 )
        if  abs(s[-1]-s[-2])<.1 :
            convergent_pairs.append( (a,b) )
            divergent_pairs.append( (a,b) )
point(convergent_pairs,color="pink") + point(divergent_pairs,color="lightblue")