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

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

Image of the Page - 199 -

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

Text of the Page - 199 -

7.7 Exercises 199 3. x0 =1andx1 =2.3 4. x0 =1andx1 =2.4 Filename:secant_failure.*. Exercise7.3:UnderstandWhythe BisectionMethod CannotFail Solve the same problem as in Exercise 7.1, using the bisection method, but let the initial interval be [−5,3]. Report how the interval containing the solution evolves during the iterations. Filename:bisection_nonfailure.*. Exercise7.4:Combine the BisectionMethod withNewton’sMethod Anattractiveideais tocombinethereliabilityofthebisectionmethodwiththespeed of Newton’s method. Such a combination is implemented by running the bisection method until we have a narrow interval, and then switch to Newton’s method for speed. Writeafunctionthat implementsthisidea.Startwithaninterval[a,b]andswitch toNewton’smethodwhenthecurrent interval in thebisectionmethodisa fractions oftheinitial interval(i.e.,whentheintervalhaslengths(b−a)).Potentialdivergence of Newton’s method is still an issue, so if the approximate root jumps out of the narrowed interval (where the solution is known to lie), one can switch back to the bisection method.The value of smust be givenas an argument to the function,but itmayhaveadefaultvalueof0.1. Try thenewmethodon tanh(x)=0withan initial interval [−10,15]. Filename:bisection_Newton.py. Exercise7.5:WriteaTest FunctionforNewton’sMethod The purpose of this function is to verify the implementation of Newton’s method in theNewton functionin thefilenonlinear_solvers.py.Constructanalgebraic equationandperformtwo iterationsofNewton’smethodbyhandorwith theaidof SymPy. Find the corresponding size of |f(x)| and use this as value forepswhen callingNewton.Thefunctionshould thenalsoperformtwoiterationsandreturn the sameapproximationto therootasyoucalculatedmanually. Implement this idea for aunit test asa test functiontest_Newton(). Filename:test_Newton.py. Exercise7.6:Halley’sMethodand theDecimal Module A nonlinearalgebraicequationf(x)= 0 may also be solvedby Halley’s method,7 givenas: xn+1 =xn− 2f(xn)f ′(xn) 2f ′(xn)2−f(xn)f ′′(xn), n=0,1,.. . , withsomestartingvaluex0. 7 http://mathworld.wolfram.com/HalleysMethod.html.
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