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

Page - 177 - in Programming for Computations โ€“ Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Image of the Page - 177 -

Image of the Page - 177 - in Programming for Computations โ€“ Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Text of the Page - 177 -

7.1 BruteForceMethods 177 7.1.1 BruteForceRootFinding Assumethatwe havea set ofpointsalong thecurveofacontinuousfunctionf(x): We want to solvef(x) = 0, i.e., find the pointsx wheref crosses the x axis. A brute force algorithm is to run through all points on the curve and check if one point is below thex axis and if the next point is above thex axis, or the other way around.If this is foundtobe thecase,weknowthat,whenf is continuous, it has to cross thex axis at least once between these twox values. In otherwords,f is zero at least onceon that sub-interval. Note that, in the following algorithm, we refer to โ€œtheโ€ root on a sub-interval, even if there may be more than one root in principle. Whether there are more than one root on a sub-interval will of course depend on the function, as well as on the size and location of the sub-interval. For simplicity, we will just assume there is at most one root on a sub-interval (or that it is sufficiently precise to talk about one root, even if therecouldbe more). NumericalAlgorithm Moreprecisely,wehaveaset ofn+1points (xi,yi),yi = f(xi), i = 0,.. .,n, wherex0 < ... < xn. We check ifyi < 0 andyi+1 > 0 (or the other way around). A compact expression for this check is to perform the test yiyi+1 <0. If so, the rootoff(x)=0 is in [xi,xi+1]. Assumingalinearvariationoff betweenxi andxi+1,wehavetheapproximation f(x)โ‰ˆ f(xi+1)โˆ’f(xi) xi+1โˆ’xi (xโˆ’xi)+f(xi)= yi+1โˆ’yi xi+1โˆ’xi(xโˆ’xi)+yi, which,whenset equal tozero,gives the root x=xiโˆ’ xi+1โˆ’xi yi+1โˆ’yiyi .
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