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

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

Image of the Page - XVII -

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

Text of the Page - XVII -

Contents xvii 4.1.5 Callinga FunctionDefinedwith PositionalParameters . . . 83 4.1.6 A FunctionwithTwoReturnValues . . . . . . . . . . . . . . . . . . . 85 4.1.7 Callinga FunctionDefinedwith KeywordParameters . . . . 85 4.1.8 A FunctionwithAnotherFunctionas InputArgument . . . . 86 4.1.9 LambdaFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 4.1.10 A FunctionwithSeveralReturnStatements . . . . . . . . . . . . . 87 4.2 ProgrammingasaStep-Wise Strategy . . . . . . . . . . . . . . . . . . . . . . . . . 88 4.2.1 Makinga TimesTablesTest . . . . . . . . . . . . . . . . . . . . . . . . . . 89 4.2.2 The1stVersionofOurCode . . . . . . . . . . . . . . . . . . . . . . . . . 90 4.2.3 The2ndVersionofOurCode. . . . . . . . . . . . . . . . . . . . . . . . . 91 4.2.4 The3rdVersionofOurCode . . . . . . . . . . . . . . . . . . . . . . . . . 93 4.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 5 Some MorePythonEssentials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 5.1 Lists andTuples:Alternatives toArrays . . . . . . . . . . . . . . . . . . . . . . . 103 5.2 ExceptionHandling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 5.2.1 TheFourthVersionofOurTimesTablesProgram.. . . . . . . 106 5.3 SymbolicComputations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 5.3.1 NumericalVersusSymbolicComputations. . . . . . . . . . . . . . 111 5.3.2 SymPy:SomeBasic Functionality. . . . . . . . . . . . . . . . . . . . . 112 5.3.3 SymbolicCalculationswithSomeOtherTools . . . . . . . . . . 112 5.4 MakingOurOwnModule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 5.4.1 A NaiveImport . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 5.4.2 A Module forVerticalMotion . . . . . . . . . . . . . . . . . . . . . . . . 115 5.4.3 ModuleorProgram? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 5.5 Files: ReadandWrite. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 5.6 MeasuringExecutionTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 5.6.1 ThetimeitModule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 5.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 6 ComputingIntegralsand Testing Code . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 6.1 Basic IdeasofNumerical Integration . . . . . . . . . . . . . . . . . . . . . . . . . . 132 6.2 TheCompositeTrapezoidalRule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 6.2.1 TheGeneralFormula . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 6.2.2 A General Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 6.2.3 A Specific Implementation:What’s the Problem? . . . . . . . . 139 6.3 TheCompositeMidpointMethod. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 6.3.1 TheGeneralFormula . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 6.3.2 A General Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 6.3.3 Comparing theTrapezoidaland the MidpointMethods . . . 145 6.4 Vectorizing theFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 6.4.1 Vectorizing the MidpointRule . . . . . . . . . . . . . . . . . . . . . . . . 146 6.4.2 Vectorizing the TrapezoidalRule . . . . . . . . . . . . . . . . . . . . . . 147 6.4.3 SpeedupGainedwithVectorization . . . . . . . . . . . . . . . . . . . 148 6.5 Rate ofConvergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 6.6 TestingCode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 6.6.1 Problemswith BriefTestingProcedures . . . . . . . . . . . . . . . . 150 6.6.2 ProperTest Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
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