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

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

Bild der Seite - 184 -

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

Text der Seite - 184 -

184 7 SolvingNonlinearAlgebraicEquations WhyNotUsean Arrayfor thexApproximations? Newton’smethod isnormally formulatedwithan iteration indexn, xn+1 =xn− f(xn) f ′(xn) . Seeingsuchan index,manywould implement this as x[n+1] = x[n] - f(x[n])/dfdx(x[n]) Such an array is fine, but requires storage of all the approximations. In large industrial applications, where Newton’s method solves millions of equations at once, one cannot afford to store all the intermediate approximations in memory, so then it is important to understand that the algorithm in Newton’s method has no more need forxn whenxn+1 is computed. Therefore, we can workwithonevariablexandoverwrite thepreviousvalue: x = x - f(x)/dfdx(x) Runningnaive_Newton(f, dfdx, 1000, eps=0.001)resultsintheapprox- imate solution 3.000027639.A smaller value ofepswill produce a more accurate solution. Unfortunately, the plain naive_Newton function does not return how many iterations it used, nor does it print out all the approximationsx0,x1,x2,.. ., whichwould indeedbeanice feature. Ifwe insert suchaprintout(print(x) in the while loop), a rerunresults in 500.0045 250.011249919 125.02362415 62.5478052723 31.3458476066 15.816483488 8.1927550496 4.64564330569 3.2914711388 3.01290538807 3.00002763928 We clearly see that the iterations approach the solution quickly. This speed of the search for the solution is the primary strength of Newton’s method compared to othermethods. 7.2.2 MakingaMoreEfficientandRobustImplementation Thenaive_Newton function works fine for the example we are considering here. However, for more general use, there are some pitfalls that should be fixed in an improvedversionof thecode.An examplemay illustratewhat theproblemis. Let us use naive_Newton to solve tanh(x) = 0, which has solution x = 0 (interactively,youmaydefinef(x)= tanh(x)andf ′(x)=1−tanh2(x)asPython
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