Table of Contents
Preface xi
1 Introduction 1
1.1 What is Sage Math? 1
1.2 Various Flavors of Sage Math 2
1.2.1 Sage Math on Your Machine 2
1.2.2 Sage Cell 2
1.2.3 Sage Cloud 2
2 Using Sage Math as a Calculator 5
2.1 First Sage Math Examples 5
2.2 Computations 6
2.2.1 Basic Arithmetic Operators 6
2.2.2 Decimals Versus Exact Values 10
2.2.3 Constants 11
2.2.4 Breaking Long Lines of Code 12
2.2.5 Comments 13
2.2.6 Library Functions 14
2.2.7 Working with Strings 17
2.2.8 Solving Equations and Inequalities 19
2.2.9 Calculus Functions 21
2.2.10 Exercises 25
2.3 Graphs 28
2.3.1 2D Graphs 28
2.3.2 3D Graphs 50
2.3.3 Exercises 52
3 Introduction to Programming in Sage 55
3.1 Variables 56
3.1.1 Exercises 59
3.2 More on Operators 59
3.2.1 Exercises 61
3.3 Making Decisions 61
3.3.1 Boolean Expressions 61
3.3.2 If Statements 64
3.3.3 Exercises 71
3.4 Loops 73
3.4.1 For Loops 73
3.4.2 Strings 80
3.4.3 While Loops 82
3.4.4 Nested Loops 86
3.4.5 Lists 88
3.4.6 Exercises 93
3.5 Functions 96
3.5.1 Using Library Functions: Random, SciPy, NumPy 101
3.5.2 Exercises 101
3.6 Interacts 103
3.6.1 Exercises 118
3.7 Application to Data Security: Caesar's Cipher. Interacts, Strings, and Encryption 120
3.7.1 Exercises 122
3.8 Application to Business: Present Value of an Annuity. Amortization 122
3.8.1 Exercises 127
3.9 Application to Elementary Statistics: Mean, Median, Histograms, and Bar Charts 128
3.9.1 Exercises 135
4 Sage Interacts for Numerical Methods 137
4.1 Equations of Lines 137
4.1.1 Exercises 139
4.2 Tangent Lines and Plots 139
4.2.1 Exercises 142
4.3 Taylor Polynomials 143
4.3.1 Exercises 147
4.4 Riemann Sum and Definite Integrals 148
4.4.1 Exercises 153
4.5 Trapezoidal Rule for Numerical Integration. 153
4.5.1 Exercises 159
4.6 Bisection Algorithm for Solving Equations 160
4.6.1 Exercises 167
4.7 Newton-Raphson Algorithm for Solving Equations 167
4.7.1 Exercises 178
4.8 Polynomial Interpolation 179
4.8.1 Exercises 184
4.9 Linear Spline Interpolation 184
4.9.1 Exercises 188
4.10 Cubic Spline Interpolation 188
4.10.1 Exercises. 196
4.11 Sage for Solving Differential Equations 196
4.12 Numerical Methods for Ordinary Differential Equations 199
4.12.1 Exercises 205
4.13 Numerical Methods for Partial Differential Equations 205
4.13.1 Exercises 210
4.14 Scatter Plots - Line of Best Fit and More 211
4.14.1 Exercises 218
4.15 Matrices, Eigenvalues, and Eigenvectors 218
4.15.1 Exercises 224
4.16 Solving Matrix Equations 224
4.16.1 Exercises 226
References 227
Index 229