Web-Books
in the Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Page - 25 -
  • User
  • Version
    • full version
    • text only version
  • Language
    • Deutsch - German
    • English

Page - 25 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Image of the Page - 25 -

Image of the Page - 25 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Text of the Page - 25 -

1.5 MoreBasicConcepts 25 limit(sin(x)/x, x, 0) solve(5*x - 15, x) WolframAlpha isveryflexiblewith respect to syntax. Another impressive tool for symbolic computations is Sage6, which is a very comprehensivepackagewith theaimof“creatingaviable freeopensourcealterna- tive toMagma,Maple,MathematicaandMatlab”. Sage is implemented inPython. Projectswithextensivesymboliccomputationswillcertainlybenefitfromexploring Sage. 1.5.11 ConcludingRemarks Programmingdemandsyoutobeaccurate! In thischapter,youhaveseensomeexamplesofhowsimple thingsmaybedone in Python. Hopefully, you have tried to do the examples on your own. If you have, most certainly you have discovered that what youwrite in the code has to be very accurate. For example, with our previous example of four heights collected inanarrayh,writingh(0) insteadofh[0]givesanerror, even if you and I know perfectly well what youmean! Remember that it is not a human that runs your code, it is a machine. Therefore, even if the meaning of your code looksfine toahumaneye, it still has tocomply indetail to the rulesof the programming language. If not, yougetwarnings anderrormessages. This also goesfor loweranduppercase letters. Ifyoudofrom math import *andgive thecommandpi, youget3:1415:::. However, if youwritePi, yougetanerror message. Payattention tosuchdetailsalsowhentheyaregiven in laterchapters. Remembertoinsertcommentstoexplainyourcode Whenyouwriteacomputerprogram,youhave twoverydifferentkindsof read- ers. One is Python,whichwill interpret and runyour programaccording to the rules. Theother issomehuman,forexample,yourselforapeer. It isveryimpor- tant toorganizeandcomment thecodeso thatyoucangobacktoyourowncode after, e.g., ayearandstill understandwhat cleverconstructionsyouput in there. This is relevantwhen you need to change or extend your code (which usually happensoften in reality). Organizedcodingandgoodcommenting is evenmore critical if otherpeopleare supposed tounderstandcode thatyouhavewritten. Fastcodeversusreadableandcorrectcode Numericalcomputinghasastrong tradition inpayingmuchattention tocreating fast code. Real industrial applications of numerical computing often involves simulations that run forhours,days, andevenweeks. Fast code is tremendously important in those cases. The problemwith a strong focus on fast code, un- fortunately, is sometimes that clear and easily understandable constructions are replacedbycleverandless readable,but fastercode.However, forbeginnersit is most important to learn towrite readable andcorrect code.Wewillmake some 6http://sagemath.org/
back to the  book Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python
Title
Programming for Computations – Python
Subtitle
A Gentle Introduction to Numerical Simulations with Python
Authors
Svein Linge
Hans Petter Langtangen
Publisher
Springer Open
Date
2016
Language
English
License
CC BY-NC 4.0
ISBN
978-3-319-32428-9
Size
17.8 x 25.4 cm
Pages
248
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