Web-Books
im Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Seite - 48 -
  • Benutzer
  • Version
    • Vollversion
    • Textversion
  • Sprache
    • Deutsch
    • English - Englisch

Seite - 48 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Bild der Seite - 48 -

Bild der Seite - 48 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Text der Seite - 48 -

48 2 BasicConstructions Exercise2.11:Compute Up through history, greatminds have developed different computational schemes for thenumber .Wewillhereconsider twosuchschemes,onebyLeibniz(1646 1716), andonebyEuler (1707 1783). TheschemebyLeibnizmaybewritten D8 1X kD0 1 .4kC1/.4kC3/; whileone formof theEuler schememayappearas D vu u t6 1X kD1 1 k2 : If only the firstN terms of each sum are used as an approximation to , each modifiedschemewill havecomputed with someerror. Writeaprogramthat takesN as input fromtheuser, andplots theerrordevelop- mentwith both schemes as thenumber of iterations approachesN . Your program shouldalsoprintout thefinalerrorachievedwithbothschemes, i.e.when thenum- ber of terms is N. Run the programwithN D 100 and explain brieflywhat the graphsshow. Filename:compute_pi.py. Exercise2.12:Computecombinationsof sets ConsideranIDnumberconsistingof two lettersand threedigits, e.g.,RE198.How many different numbers canwe have, and how can a program generate all these combinations? Ifacollectionofn thingscanhavem1variationsof thefirst thing,m2of thesec- ondandsoon, the total numberofvariationsof the collectionequalsm1m2 mn. Inparticular, theIDnumberexemplifiedabovecanhave26 26 10 10 10D676;000 variations. To generate all the combinations, wemust have five nested for loops. Thefirst two runoverall lettersA,B, andsoon toZ,while thenext three runover all digits0;1;:: :;9. To convinceyourself about this result, start outwith an IDnumberon the form A3where thefirst part canvaryamongA,B, andC, and thedigit canbeamong1, 2, or 3. Wemust startwithAand combine itwith 1, 2, and3, then continuewith B,combinedwith1,2, and3, andfinallycombineCwith1,2, and3.Adouble for loopdoes thework. a) Inadeckofcards, eachcard is acombinationofa rankandasuit. Thereare13 ranks: ace (A), 2, 3, 4, 5, 6, 7, 8, 9, 10, jack (J), queen (Q), king (K), and four suits: clubs (C), diamonds (D), hearts (H), and spades (S).A typical cardmay beD3.Write statements thatgenerateadeckofcards, i.e., all thecombinations CA,C2,C3, and soon toSK. b) Avehicle registrationnumber ison the formDE562,where the lettersvaryfrom AtoZandthedigits from0to9.Writestatements thatcomputeall thepossible registrationnumbersandstores themina list.
zurück zum  Buch Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python
Titel
Programming for Computations – Python
Untertitel
A Gentle Introduction to Numerical Simulations with Python
Autoren
Svein Linge
Hans Petter Langtangen
Verlag
Springer Open
Datum
2016
Sprache
englisch
Lizenz
CC BY-NC 4.0
ISBN
978-3-319-32428-9
Abmessungen
17.8 x 25.4 cm
Seiten
248
Schlagwörter
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Kategorie
Informatik
Web-Books
Bibliothek
Datenschutz
Impressum
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python