Lesson goal: Iterating a function with a for-loop

Previous: Finding square roots | Home | Next: Interating the logistic function

Programming languages often have built in functions that perform a particular task. Previous lessons demonstrated those that take square roots, find random numbers, make pi available, and compute absolute values. There an interesting math lesson that combines functions and for-loops, called "iteration." The theme is to address what happens to a number if you apply a function to it over and over again.

As an example, suppose you took the number $137$ and took the square root of it. You'd get $11.7$. Then, what if you took the square root of $11.7$? And what if you kept doing over and over again, maybe 100 times? Would an eventual number or pattern emerge?

It's a strange question, but a very important one in modern research mathematics called "interation." With a for-loop, you can easily repeatedly apply a function to a number as many times as you want. The result of this "research" is to determine what (stable) number these interations eventually produce.

In this lesson, we'll try interating the square root of some number. In other words, we'll choose a number and apply the square root to it, over and over again.

Now you try. Try choosing an initial value for x. Fix the for loop to count to 100 or so, then program in the function to interate in the x= line under the for loop.

Type your code here:

See your results here: