xxii
List of Exercises
Exercise 4.10: Linear Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Exercise 4.11: Test Straight Line Requirement . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Exercise 4.12: Fit Straight Line to Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Exercise 4.13: Fit Sines to Straight Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Exercise 5.1: Nested for Loops and Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Exercise 5.2: Exception Handling: Divisions in a Loop . . . . . . . . . . . . . . . . . . . 125
Exercise 5.3: Taylor Series, sympy and Documentation . . . . . . . . . . . . . . . . . . . 125
Exercise 5.4: Fibonacci Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Exercise 5.5: Read File: Total Volume of Boxes . . . . . . . . . . . . . . . . . . . . . . . . . 127
Exercise 5.6: Area of a Polygon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Exercise 5.7: Count Occurrences of a String in a String . . . . . . . . . . . . . . . . . . . 128
Exercise 5.8: Compute Combinations of Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Exercise 6.1: Hand Calculations for the Trapezoidal Method . . . . . . . . . . . . . . 169
Exercise 6.2: Hand Calculations for the Midpoint Method . . . . . . . . . . . . . . . . . 169
Exercise 6.3: Compute a Simple Integral . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Exercise 6.4: Hand-Calculations with Sine Integrals . . . . . . . . . . . . . . . . . . . . . . 169
Exercise 6.5: Make Test Functions for the Midpoint Method . . . . . . . . . . . . . . . 169
Exercise 6.6: Explore Rounding Errors with Large Numbers . . . . . . . . . . . . . . . 169
Exercise 6.7: Write Test Functions for
4
0
√
xdx . . . . . . . . . . . . . . . . . . . . . . . . . 170
Exercise 6.8: Rectangle Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Exercise 6.9: Adaptive Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Exercise 6.10: Integrating x Raised to x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Exercise 6.11: Integrate Products of Sine Functions . . . . . . . . . . . . . . . . . . . . . . 172
Exercise 6.12: Revisit Fit of Sines to a Function . . . . . . . . . . . . . . . . . . . . . . . . . 172
Exercise 6.13: Derive the Trapezoidal Rule for a Double Integral . . . . . . . . . . . 173
Exercise 6.14: Compute the Area of a Triangle by Monte Carlo
Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Exercise 7.1: Understand Why Newton’s Method Can Fail . . . . . . . . . . . . . . . . 198
Exercise 7.2: See If the Secant Method Fails . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Exercise 7.3: Understand Why the Bisection Method Cannot Fail . . . . . . . . . . 199
Exercise 7.4: Combine the Bisection Method with Newton’s Method . . . . . . . 199
Exercise 7.5: Write a Test Function for Newton’s Method . . . . . . . . . . . . . . . . . 199
Exercise 7.6: Halley’s Method and the Decimal Module . . . . . . . . . . . . . . . . . . 199
Exercise 7.7: Fixed Point Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Exercise 7.8: Solve Nonlinear Equation for a Vibrating Beam . . . . . . . . . . . . . . 201
Exercise 8.1: Restructure a Given Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
Exercise 8.2: Geometric Construction of the Forward Euler Method . . . . . . . . 273
Exercise 8.3: Make Test Functions for the Forward Euler Method . . . . . . . . . . 273
Exercise 8.4: Implement and Evaluate Heun’s Method . . . . . . . . . . . . . . . . . . . . 274
Exercise 8.5: Find an Appropriate Time Step; Logistic Model . . . . . . . . . . . . . 274
Exercise 8.6: Find an Appropriate Time Step; SIR Model . . . . . . . . . . . . . . . . . 274
Exercise 8.7: Model an Adaptive Vaccination Campaign . . . . . . . . . . . . . . . . . . 274
Exercise 8.8: Make a SIRV Model with Time-Limited Effect
of Vaccination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Exercise 8.9: Refactor a Flat Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Exercise 8.10: Simulate Oscillations by a General ODE Solver . . . . . . . . . . . . 275
Exercise 8.11: Compute the Energy in Oscillations . . . . . . . . . . . . . . . . . . . . . . . 276
List of Exercises
Exercise 4.10: Linear Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Exercise 4.11: Test Straight Line Requirement . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Exercise 4.12: Fit Straight Line to Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Exercise 4.13: Fit Sines to Straight Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Exercise 5.1: Nested for Loops and Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Exercise 5.2: Exception Handling: Divisions in a Loop . . . . . . . . . . . . . . . . . . . 125
Exercise 5.3: Taylor Series, sympy and Documentation . . . . . . . . . . . . . . . . . . . 125
Exercise 5.4: Fibonacci Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Exercise 5.5: Read File: Total Volume of Boxes . . . . . . . . . . . . . . . . . . . . . . . . . 127
Exercise 5.6: Area of a Polygon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Exercise 5.7: Count Occurrences of a String in a String . . . . . . . . . . . . . . . . . . . 128
Exercise 5.8: Compute Combinations of Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Exercise 6.1: Hand Calculations for the Trapezoidal Method . . . . . . . . . . . . . . 169
Exercise 6.2: Hand Calculations for the Midpoint Method . . . . . . . . . . . . . . . . . 169
Exercise 6.3: Compute a Simple Integral . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Exercise 6.4: Hand-Calculations with Sine Integrals . . . . . . . . . . . . . . . . . . . . . . 169
Exercise 6.5: Make Test Functions for the Midpoint Method . . . . . . . . . . . . . . . 169
Exercise 6.6: Explore Rounding Errors with Large Numbers . . . . . . . . . . . . . . . 169
Exercise 6.7: Write Test Functions for
4
0
√
xdx . . . . . . . . . . . . . . . . . . . . . . . . . 170
Exercise 6.8: Rectangle Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Exercise 6.9: Adaptive Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Exercise 6.10: Integrating x Raised to x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Exercise 6.11: Integrate Products of Sine Functions . . . . . . . . . . . . . . . . . . . . . . 172
Exercise 6.12: Revisit Fit of Sines to a Function . . . . . . . . . . . . . . . . . . . . . . . . . 172
Exercise 6.13: Derive the Trapezoidal Rule for a Double Integral . . . . . . . . . . . 173
Exercise 6.14: Compute the Area of a Triangle by Monte Carlo
Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Exercise 7.1: Understand Why Newton’s Method Can Fail . . . . . . . . . . . . . . . . 198
Exercise 7.2: See If the Secant Method Fails . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Exercise 7.3: Understand Why the Bisection Method Cannot Fail . . . . . . . . . . 199
Exercise 7.4: Combine the Bisection Method with Newton’s Method . . . . . . . 199
Exercise 7.5: Write a Test Function for Newton’s Method . . . . . . . . . . . . . . . . . 199
Exercise 7.6: Halley’s Method and the Decimal Module . . . . . . . . . . . . . . . . . . 199
Exercise 7.7: Fixed Point Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Exercise 7.8: Solve Nonlinear Equation for a Vibrating Beam . . . . . . . . . . . . . . 201
Exercise 8.1: Restructure a Given Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
Exercise 8.2: Geometric Construction of the Forward Euler Method . . . . . . . . 273
Exercise 8.3: Make Test Functions for the Forward Euler Method . . . . . . . . . . 273
Exercise 8.4: Implement and Evaluate Heun’s Method . . . . . . . . . . . . . . . . . . . . 274
Exercise 8.5: Find an Appropriate Time Step; Logistic Model . . . . . . . . . . . . . 274
Exercise 8.6: Find an Appropriate Time Step; SIR Model . . . . . . . . . . . . . . . . . 274
Exercise 8.7: Model an Adaptive Vaccination Campaign . . . . . . . . . . . . . . . . . . 274
Exercise 8.8: Make a SIRV Model with Time-Limited Effect
of Vaccination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Exercise 8.9: Refactor a Flat Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Exercise 8.10: Simulate Oscillations by a General ODE Solver . . . . . . . . . . . . 275
Exercise 8.11: Compute the Energy in Oscillations . . . . . . . . . . . . . . . . . . . . . . . 276
