Web-Books
in the Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Page - 126 -
  • User
  • Version
    • full version
    • text only version
  • Language
    • Deutsch - German
    • English

Page - 126 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Image of the Page - 126 -

Image of the Page - 126 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Text of the Page - 126 -

126 5 SomeMorePythonEssentials Google), and you probably have to look into more details about how Taylor series arehandledwithsympy. Toyourcomfort, this isavery typicalsituationforengineersandscientists.They need to solvea problem,but donot (yet!)have the requiredknowledgefor all parts of the problem. Being able to find and understand the required information is then very important. Exercise5.4:FibonacciNumbers The Fibonacci numbers13 is a sequence of integers in which each number (except the twofirst ones) isgivenasasumof the twoprecedingnumbers: Fn=Fnβˆ’1 +Fnβˆ’2, F0 =1,F1 =1, n=2,3,.. . Thus, thesequencestartsoutas 1,1,2,3,5,8,13,21,34,.. . a) Write a function make_Fibonacci that generates, and returns, the N first Fibonacci numbers, when N is an input parameter to the function. Place the function in a module named fibonacci (i.e., a file named fibonacci.py). The module should have a test block, so that if run as a program, e.g., the 20 first Fibonacci numbers are printed to screen. Check that the program behaves as intended. b) The famous Johannes Kepler14 found that the ratio of consecutive Fibonacci numbersconvergesto the goldenratio, i.e. lim nβ†’βˆž Fn+1 Fn = 1+ √ 5 2 . Extend your module by defining a function converging_ratio, which takes an array (or a list) F with (e.g., 20) Fibonacci numbers as input and then checks (you decide how) whether Kepler’s understanding seems correct. Place a call to the function in the test block and run the program. Was Kepler right? c) With the iterative procedure of the previous question, the ratios converged to the golden ratio at a certain rate. This brings in the concept of convergence rate, which we have not yet addressed (see, e.g., Sect.7.5, or elsewhere). However, if you are motivated, you may get a head start right now. Inbrief, ifwedefine thedifference(inabsolutevalue)between Fn+1 Fn and thegolden ratio as the error en at iterationn, this error (when small enough) will develop as en+1 = Ceqn, where C is some constant and q is the convergence rate (in fact, this error model is typical for iterative methods). That is, we have a relation that predicts how the error changes from one iteration to the next. We note that the 13 Read more about the Fibonacci numbers, e.g., on Wikipedia (https://en.wikipedia. org/wiki/Fi- bonacci_number). 14 https://en.wikipedia.org/wiki/Johannes_Kepler.
back to the  book Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Title
Programming for Computations – Python
Subtitle
A Gentle Introduction to Numerical Simulations with Python 3.6
Volume
Second Edition
Authors
Svein Linge
Hans Petter Langtangen
Publisher
Springer Open
Date
2020
Language
English
License
CC BY 4.0
ISBN
978-3-319-32428-9
Size
17.8 x 25.4 cm
Pages
356
Keywords
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Category
Informatik
Web-Books
Library
Privacy
Imprint
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python