Python Programming: An Introduction to Computer Science

(Nora) #1
1.9.EXERCISES 11

0.166187 0.

0.540418 0.

0.968629 0.

0.118509 0.

Withverysimilarstartingvalues,theoutputsstaysimilarfora fewiterations,butthendiffermarkedly. By
aboutthefifthiteration,therenolongerseemstobeany relationshipbetweenthetwo models.
Thesetwo featuresofourchaosprogram,apparentunpredictabilityandextremesensitivitytoinitial
values,arethehallmarksofchaoticbehavior. Chaoshasimportantimplicationsforcomputerscience.It
turnsoutthatmany phenomenaintherealworldthatwemightlike tomodelandpredictwithourcomputers
exhibitjustthiskindofchaoticbehavior. Youmayhave heardoftheso-calledbutterflyeffect. Computer
modelsthatareusedtosimulateandpredictweatherpatternsaresosensitive thattheeffectofa single
butterflyflappingitswingsinNewJersey mightmake thedifferenceofwhetherornotrainis predictedin
Peoria.
It’s verypossiblethatevenwithperfectcomputermodeling,wemightneverbeabletomeasureexisting
weatherconditionsaccuratelyenoughto predictweathermorethana few daysin advance.Themeasurements
simplycan’t bepreciseenoughtomake thepredictionsaccurateover a longertimeframe.
Asyoucansee,thissmallprogramhasa valuablelessontoteachusersofcomputers. Asamazingas
computersare,theresultsthatthey give usareonlyasusefulasthemathematicalmodelsonwhichthe
programsarebased. Computerscangive incorrectresultsbecauseoferrorsinprograms,butevencorrect
programsmayproduceerroneousresultsif themodelsarewrongortheinitialinputsarenotaccurateenough.


1.9 Exercises



  1. Compareandcontrastthefollowingpairsofconceptsfromthechapter.


(a)Hardwarevs.Software
(b)Algorithmvs.Program
(c)ProgrammingLanguagevs.NaturalLanguage
(d)High-Level Languagevs.MachineLanguage
(e)Interpretervs.Compiler
(f)Syntaxvs.Semantics


  1. Listandexplaininyourownwordstheroleofeachofthefive basicfunctionalunitsofa computer
    depictedinFigure1.1.

  2. Writea detailedalgorithmformakinga peanutbutterandjellysandwich(orsomeothersimpleevery-
    dayactivity).

  3. Asyouwilllearnina laterchapter, many ofthenumbersstoredina computerarenotexactvalues,but
    rathercloseapproximations.Forexample,thevalue0.1,mightbestoredas0.10000000000000000555.
    Usually, suchsmalldifferencesarenota problem;however, givenwhatyouhave learnedaboutchaotic
    behaviorinChapter1,youshouldrealizetheneedforcautionincertainsituations.Canyouthinkof
    exampleswherethismightbea problem?Explain.

  4. TracethroughtheChaosprogramfromSection1.6byhandusing 0 15 astheinputvalue.Showthe
    sequenceofoutputthatresults.

  5. EnterandruntheChaosprogramfromSection1.6usingwhateverPythonimplementationyouhave
    available.Tryit outwithvariousvaluesofinputtoseethatit functionsasdescribedinthechapter.

  6. ModifytheChaosprogramfromSection1.6using2.0inplaceof3.9asthemultiplierinthelogistic
    function.Yourmodifiedlineofcodeshouldlooklike this:

Free download pdf