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

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

Bild der Seite - 193 -

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

Text der Seite - 193 -

7.5 RateofConvergence 193 A single q in (7.5) is defined in the limit n → ∞. For finiten, and especially smallern, q will vary withn. To estimateq, we can compute all the errors en and set up(7.5) for threeconsecutiveexperimentsn−1,n, andn+1: en=Ceqn−1, en+1 =Ceqn . Dividing, e.g., the latter equation by the former, and solving with respect to q, we get that q= ln(en+1/en) ln(en/en−1) . Since thisq will vary somewhat withn, we call itqn. Asngrows, we expectqn to approacha limit (qn→q). ModifyingOurFunctions toReturnAll Approximations To computeall theqn values,we needall thexn approximations.However,ourprevious implementations of Newton’smethod, the secant method,and thebisection method returned just the finalapproximation. Therefore, we have modified our solvers5 accordingly, and placed them in nonlinear_solvers.py.A user can choose whether the final value or the whole history of solutions is to be returned. Each of the extended implementations now takesanextraparameterreturn_x_list.Thisparameter is aboolean,set toTrue if the function is supposed to return all the root approximations, or False, if the functionshouldonly return thefinalapproximation. Asanexample, letus takea closer lookatNewton: def Newton(f, dfdx, x, eps, return_x_list=False): f_value = f(x) iteration_counter = 0 if return_x_list: x_list = [] while abs(f_value) > eps and iteration_counter < 100: try: x = x - float(f_value)/dfdx(x) except ZeroDivisionError: print(’Error! - derivative zero for x = {:g}’.format(x)) sys.exit(1) # Abort with error f_value = f(x) iteration_counter += 1 if return_x_list: x_list.append(x) # Here, either a solution is found, or too many iterations if abs(f_value) > eps: iteration_counter = -1 # i.e., lack of convergence 5 An implemented numerical solution algorithm isoften called a solver.
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