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 - 200 -
  • Benutzer
  • Version
    • Vollversion
    • Textversion
  • Sprache
    • Deutsch
    • English - Englisch

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

Bild der Seite - 200 -

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

Text der Seite - 200 -

200 7 SolvingNonlinearAlgebraicEquations a) ImplementHalley’smethodasafunctionHalley.Placethefunctioninamodule thathasatestblock,andtest thefunctionbysolvingx2−9=0,usingx0 =1000 asyour initialguess. b) Compared to Newton’s method, more computations per iteration are needed with Halley’s method, but a convergence rate of 3 may be achieved close to the root. You are now supposed to extend your module with a function compute_rates_decimal, which computes the convergence rates achieved withyour implementationofHalley (for thegivenproblem). The implementation of compute_rates_decimal should involve the decimal module (you search for the right documentation!), to better handle very small errors that may enter the rate computations. For comparison, you should also compute the rates without using the decimal module. Test and comparewith severalparametervalues. Hint Thelogarithmsin theratecalculationmight requiresomeextraconsideration whenyouuse thedecimalmodule. Filename:Halleys_method.py. Exercise7.7:FixedPoint Iteration Anonlinearalgebraicequationf(x)=0maybesolvedinmanydifferentways,and we have met some of these in this chapter. Another,very useful, solution approach is to first re-write the equation intox=φ(x) (this re-write is not unique), and then formulate the iteration xn+1 =φ(xn), n=0,1,.. . , withsomestartingvaluex0. Ifφ(x) is continuous,and ifφ(xn)approachesα asxn approachesα (i.e.,wegetα=φ(α)asn→∞), the iteration is calledafixedpoint iteration andα is referred to as a fixed point of the mappingx→φ(x). Clearly, if afixedpointα is found,αwill alsobeasolution to theoriginalequationf(x)=0. In this exercise, we will briefly explore the fixed point iteration method by solving x3+2x= e−x, x∈ [−2,2] . For comparison, however, you will first be asked to solve the equation by Newton’smethod(which, in fact, canbeseenasfixedpoint iteration8). a) Write a program that solves this equation by Newton’s method. Use x = 1 as your starting value. To better judge the printed answer found by Newton’s method, let the codealso plot the relevant functionon thegiven interval. b) The givenequationmay be rewritten asx= e−x−x32 . Extendyourprogramwith a functionfixed_point_iteration, which takes appropriateparameters, and uses fixed point iteration to find and return a solution (if found), as well as the numberof iterations required.Usex=1 as startingvalue. 8 Check out https://en.wikipedia.org/wiki/Fixed_point_iteration.
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