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

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

Bild der Seite - 111 -

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

Text der Seite - 111 -

5.3 SymbolicComputations 111 thatall the100questionsactuallygetasked,andalso thatpointsaregivencorrectly. The simplicity of the present program allows this to be done while running it. Experiencedprogrammers,however,usually write dedicated code for such testing. How to do this for implementations of numerical methods, will be presented later (seeChap.6). Note that, even if some error handling can be implemented by use of if-elif-elseconstructions, exception handling allows better programming,and is thepreferredandmodernwayofhandlingerrors.The recommendationtonovice programmersis therefore todevelopthehabitofusingtry-exceptconstructions. 5.3 SymbolicComputations Even though the main focus in this book is programming of numerical methods, there are occasions where symbolic (also called exact or analytical) operations are useful. 5.3.1 NumericalVersusSymbolicComputations Doing symbolic computations means, as the name suggests, that we do compu- tations with the symbols themselves rather than with the numerical values they could represent. Let us illustrate the difference between symbolic and numerical computationswitha little example.A numericalcomputationcouldbe x = 2 y = 3 z = x*y print(z) whichwill make thenumber6appearon thescreen. A symbolic counterpart of this code could be written by use of the SymPy package2 (namedsympy in Python): import sympy as sym x, y = sym.symbols(’x y’) # define x and y as a mathematical symbols z = x*y print(z) whichcausesthesymbolicresultx*y toappearonthescreen.Notethatnonumerical value was assigned to any of the variables in the symbolic computation. Only the symbols were used, as when you do symbolic mathematics by hand on a piece of paper.Notealso howsymbolnamesmust bedeclaredbyusingsymbols. 2 SymPy (http://docs.sympy.org/latest/index.html) is included in Anaconda. In case you have not installedAnaconda, you may have to installSymPy separately.
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