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

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

Bild der Seite - 194 -

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

Text der Seite - 194 -

194 7 SolvingNonlinearAlgebraicEquations if return_x_list: return x_list, iteration_counter else: return x, iteration_counter We cannowmakeacall x, iter = Newton(f, dfdx, x=1000, eps=1e-6, return_x_list=True) andgeta listx returned.Withknowledgeoftheexactsolutionxoff(x)=0wecan computeall theerrorsen andall theassociatedqn valueswith thecompact function (also foundinnonlinear_solvers.py) def rate(x, x_exact): e = [abs(x_ - x_exact) for x_ in x] q = [log(e[n+1]/e[n])/log(e[n]/e[n-1]) for n in range(1, len(e)-1, 1)] return q The error model (7.5) works well for Newton’s method and the secant method. For thebisectionmethod,however, itworkswell in thebeginning,butnotwhen the solution is approached. We cancompute the ratesqn andprint themnicely (print_rates.py), def print_rates(method, x, x_exact): q = [’{:.2f}’.format(q_) for q_ in rate(x, x_exact)] print(method + ’:’) for q_ in q: print(q_, " ", end="") # end="" suppresses newline Theresult forprint_rates(’Newton’, x, 3) is Newton: 1.01 1.02 1.03 1.07 1.14 1.27 1.51 1.80 1.97 2.00 indicating thatq=2 is the rate forNewton’smethod.A similar computationusing thesecantmethod,gives the rates secant: 1.26 0.93 1.05 1.01 1.04 1.05 1.08 1.13 1.20 1.30 1.43 1.54 1.60 1.62 1.62 Here it seems thatq≈1.6 is the limit. Remark If we in the bisection method think of the length of the current interval containingthesolutionas theerroren, then(7.5)worksperfectlysinceen+1 = 12en, i.e.,q=1andC= 12,butifen is thetrueerror |x−xn|, it iseasilyseenfromasketch that thiserrorcanoscillatebetweenthecurrentinterval lengthandapotentiallyvery smallvalueasweapproachtheexact solution.Thecorrespondingratesqn fluctuate widelyandareofno interest.
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