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 - 200 -
  • User
  • Version
    • full version
    • text only version
  • Language
    • Deutsch - German
    • English

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

Image of the Page - 200 -

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

Text of the Page - 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.
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