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

  1. Make a folder (either on your BMC account or on a memory stick or disk) for working on your CS110 Labs and configure IDLE to use this folder for all your work (Click here for details).
  2. Create the program module chaos.py as described on page 12 of your text.
  3. Run this using the input values on pages 12 and 13 and confirm that you are getting the same results.
  4. Modify the program as instructed in Exercise#3 (page 23).
  5. Modify the program once again to do Exercise#4 (page 23).
  6. Run the program several times with different inputs. Observe the behavior and then write up your observations.
  7. Print out the final version of the program file and your write up for submission to the instructor.
  8. Make a blog posting saying that you have completed the assignment and also write up any logistical or other issues/questions raised while working on this assignment.

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>


Solution

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
 >>>

 


Back to CS110 Course Page