Web-Books
im Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Seite - 193 -
  • Benutzer
  • Version
    • Vollversion
    • Textversion
  • Sprache
    • Deutsch
    • English - Englisch

Seite - 193 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Bild der Seite - 193 -

Bild der Seite - 193 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Text der Seite - 193 -

6.2 Newton’sMethod 193 Whynotuseanarrayforthexapproximations? Newton’smethod isnormally formulatedwithan iteration indexn, xnC1 Dxn f.xn/ f 0.xn/ : Seeingsuchan index,manywould implement this as x[n+1] = x[n] - f(x[n])/dfdx(x[n]) Suchanarray isfine, but requires storageof all the approximations. In large industrial applications,whereNewton’smethod solvesmillions of equations at once,onecannot afford to storeall the intermediateapproximations inmemory, so then it is important to understand that the algorithminNewton’smethodhas nomoreneed forxnwhenxnC1 is computed. Therefore,wecanworkwith one variablexandoverwrite thepreviousvalue: x = x - f(x)/dfdx(x) Running naive_Newton(f, dfdx, 1000, eps=0.001) results in the ap- proximate solution 3.000027639. A smaller value of epswill produce a more accurate solution. Unfortunately, the plain naive_Newton function does not re- turn how many iterations it used, nor does it print out all the approximations x0;x1;x2;: : :, whichwould indeedbe a nice feature. Ifwe insert such a printout, a rerun results in 500.0045 250.011249919 125.02362415 62.5478052723 31.3458476066 15.816483488 8.1927550496 4.64564330569 3.2914711388 3.01290538807 3.00002763928 Weclearly see that the iterations approach the solution quickly. This speed of thesearch for thesolution is theprimarystrengthofNewton’smethodcompared to othermethods. 6.2.2 MakingaMoreEfficientandRobustImplementation Thenaive_Newton functionworksfine for the examplewe are considering here. However, formore general use, there are some pitfalls that should be fixed in an improvedversionof the code. An examplemay illustratewhat the problem is: let us solve tanh.x/ D 0, which has solution x D 0. With jx0j 1:08 everything worksfine. Forexample,x0 leads tosix iterations if D0:001:
zurück zum  Buch Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python
Titel
Programming for Computations – Python
Untertitel
A Gentle Introduction to Numerical Simulations with Python
Autoren
Svein Linge
Hans Petter Langtangen
Verlag
Springer Open
Datum
2016
Sprache
englisch
Lizenz
CC BY-NC 4.0
ISBN
978-3-319-32428-9
Abmessungen
17.8 x 25.4 cm
Seiten
248
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