CS110 Introduction to Computing
Fall 2006
Lab Assignment#1
This lab is designed to get you started with using the Python environment in our CS Labs. In this lab you will learn to configure IDLE for use in this course, write a simple Python program, run it, prepare materials for submission, and then write about it.
Assignment: Do Programming Exercise#3 and Exercise#4 from Chapter 1 of Zelle.
What you will need to do
Notes:
Plan on spending at least an hour in the computer lab to complete this assignment. Make sure you have read Chapter 1 and also the assigned exercises and know what you have to do (including this handout) prior to coming to the lab.
Add the following line to all your Python programs:
# File: <place name of your program file here> # Date: <date created> # Created by: <your name> # Assignment: <place assignment number here>
First, it took me a while to get comfortable with IDLE and Python environment. I realized that the Python Shell is where programs get executed. the programs are actually created in a program file and then run using the Run Module command. Once I was past this, the rest was easy. Here are the results of my assignment.
At first, I tried the original program with various values between 0.0 and 1.0. It appreared that all the program was producing was a set of 10 random numbers. They were diffeerent for each input value and so I concluded that the behavior of the logistic function was chaotic (as discussed in class).
However, once I did Exercise#3 and modified the multiplier from 3.9 to 2.0, the values produced by the program were random at first but then they quickly turned into 0.5 and all subsequent outputs were 0.5. Exercise#4 made me modify the program from producing 20 numbers instead of 10. Th ebehavior of the program remained the same. That is, once the output produced a 0.5, all remaining outputs were 0.5. For fun, I changed the 2.0 back to 3.9 and tried producing 20 outputs. But all I got were 20 random numbers.
As we were told in class, the logistic can be used to model chaotic as well as functions that stabilize on a fixed point. I think that by changing 3.9 to 2.0 the program went from being chaotic to fixed as shown by the outputs.
Here is the final version of the program:
# File: chaos.py # Date: September 11, 2006 # Created by: Deepak Kumar # Assignment: #1
def main(): print "This program illustrates a chaotic function" x = input("Enter a number between 0 and 1: ") for i in range(20): x = 2.0 * x * (1 - x) print x
main()
Here are some outputs produced by the program:
First, the caotic version, without modifications:
This program illustrates a chaotic function Enter a number between 0 and 1: 0.25 0.73125 0.76644140625 0.698135010439 0.82189581879 0.570894019197 0.955398748364 0.166186721954 0.540417912062 0.9686289303 0.118509010176
>>> ================================ RESTART ================================ >>> This program illustrates a chaotic function Enter a number between 0 and 1: 0.75 0.73125 0.76644140625 0.698135010439 0.82189581879 0.570894019197 0.955398748364 0.166186721954 0.540417912062 0.9686289303 0.118509010176
Next, the one with 3.9 changed to 2.0 produced this output:
>>> ================================ RESTART ================================
>>>
This program illustrates a chaotic function
Enter a number between 0 and 1: 0.25
0.375
0.46875
0.498046875
0.499992370605
0.499999999884
0.5
0.5
0.5
0.5
0.5
>>> ================================ RESTART ================================
>>>
This program illustrates a chaotic function
Enter a number between 0 and 1: 0.75
0.375
0.46875
0.498046875
0.499992370605
0.499999999884
0.5
0.5
0.5
0.5
0.5
After modifying to produce 20 outputs: >>> ================================ RESTART ================================ >>> This program illustrates a chaotic function Enter a number between 0 and 1: 0.25 0.375 0.46875 0.498046875 0.499992370605 0.499999999884 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 >>>