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

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

Image of the Page - 189 -

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

Text of the Page - 189 -

7.3 TheSecantMethod 189 Fig. 7.2 Illustrates theuseofsecants inthesecantmethodwhensolvingx2βˆ’9=0,x∈[0,1000]. From two chosen starting values, x0 = 1000 and x1 = 700 the crossing x2 of the corresponding secant with thex axis is computed, followed by a similar computation ofx3 fromx1 andx2 iteration_counter = 0 while abs(f_x1) > eps and iteration_counter < 100: try: denominator = (f_x1 - f_x0)/(x1 - x0) x = x1 - f_x1/denominator except ZeroDivisionError: print(’Error! - denominator zero for x = ’, x) sys.exit(1) # Abort with error x0 = x1 x1 = x f_x0 = f_x1 f_x1 = f(x1) iteration_counter = iteration_counter + 1 # Here, either a solution is found, or too many iterations if abs(f_x1) > eps: iteration_counter = -1 return x, iteration_counter if __name__ == ’__main__’: def f(x): return x**2 - 9 x0 = 1000; x1 = x0 - 1 solution, no_iterations = secant(f, x0, x1, eps=1.0e-6) if no_iterations > 0: # Solution found
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