Chapter 5: Programming in Sage and Python
5.1. Repetition without Boredom: The For Loop
- 5.1.4. Wasteful Loops
- 5.1.9. For Loops and Taylor Polynomials
- 5.1.10. Exploring Chaos Theory
5.2. Writing Subroutines
- 5.2.1. An Example: Working with Coinage
- 5.2.3. An Example: Designing Aquariums
5.3. Loops and Newton's Method
- 5.3.2. Newton's Method with a For Loop
- 5.3.6. Returning a Value and Nesting Subroutines
5.4. An Introduction to Control Flow
- 5.4.1. Verbosity Control
- 5.4.3. Stopping Newton's Method Early
5.5. More Concepts in Flow Control
- 5.5.1. Raising an "Exception"
- 5.5.2. The If-Then-Else Construction
- 5.5.4. The elif Command
5.6. While Loops versus For Loops
- 5.6.1. A Question about Factorials
- 5.6.3. Newton's Method with a While Loop
- 5.6.5. Factorization by Trial Division
5.7. How Arrays and Lists Work
- 5.7.1 Lists of Points and Plotting
- 5.7.3 Operations on Lists
- 5.7.4 Looping through an Array
5.8. Simulations: the Monte-Carlo Method
- 5.8.1. Throwing Darts to Estimate Pi
- 5.8.2. Archimedes, the Cylinder, and the Sphere
- 5.8.2. A Monte-Carlo Simulation
- 5.8.4 Rolling Dice in Sage
- 5.8.5. Estimation Error and Confidence Intervals
- 5.8.5. An Application to Political Science
5.9. Some Intermediate-Level Techniques
- 5.9.1. Using the assert Command
- 5.9.3 Averaging Some Numbers
- 5.9.6. Useful Shortcut Commands for Lists
- 5.9.8. Understanding the try command