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

Seite - 127 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition

Bild der Seite - 127 -

Bild der Seite - 127 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition

Text der Seite - 127 -

5.7 Exercises 127 larger theq, thequicker theerrorgoes tozeroas thenumberof iterations (n)grows (whenen < 1). With the given error model, we may compute the convergencerate from q= ln(en+1/en) ln(en/en−1) . This is derived by considering the error model for three consecutive iterations, dividingoneequationby the otherandsolving forq. If then a seriesof iterations is run,wecancomputeasequenceofvalues forq as the iterationcountern increases. As n increases, the computed q values are expected to approach the convergence rate that characterizes the particular iterative method. For the ratio we are looking athere, theconvergenceratio is1. Extend your module with a functioncompute_rates, which takes an array (or a list) F with (e.g., 20) Fibonacci numbers as input and computes (and prints) the corresponding values for q. Call the function from the test block and run the program.Do theconvergenceratesapproach theexpectedvalue? Later, in Sect.6.6.2, you will learn that convergence rates are very useful when testing (verifying)software. Filename:Fibonacci_numbers.py. Exercise5.5:ReadFile:TotalVolume ofBoxes A file box_data.dat contains volume data for a collection of rectangular boxes. These boxes all have the same bottom surface area, but (typically) differ in height. Thefile could, forexample, read: Volume data for rectangular boxes 10.0 3.0 4.0 2.0 3.0 5.0 Apart from the header, each line represents one box. However, since they all have the same bottom surface area, that area (10.0) is only given for the first box. For that first box, also the height (3.0) is given, as it is for each of the following boxes. a) Writedownaformulaforcomputingthe totalvolumeofallboxesrepresentedin the file. That formula should be written such that a minimum of multiplications andadditions isused. b) Write a program that reads the filebox_data.dat, computes the total volume of all boxes represented in the file, and prints that volume to the screen. In the calculations,apply the formula just derived. (Note that, as afirst step,youmayread thefile and just print (to screen)what is read.Comparingthisprintoutwithfilecontent(usesomeeditor) is thenagood idea.) c) In the filebox_data.dat, after the last line (containing the height of the “last” box), insert a coupleof empty lines, i.e. just press enter a few times. Then, save thefile and run theprogramanew.Whathappens?Explainbriefly.
zurück zum  Buch Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Titel
Programming for Computations – Python
Untertitel
A Gentle Introduction to Numerical Simulations with Python 3.6
Band
Second Edition
Autoren
Svein Linge
Hans Petter Langtangen
Verlag
Springer Open
Datum
2020
Sprache
englisch
Lizenz
CC BY 4.0
ISBN
978-3-319-32428-9
Abmessungen
17.8 x 25.4 cm
Seiten
356
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