# An Introduction to SAGE Programming: With Applications to SAGE Interacts for Numerical Methods

## Books Features a simplified presentation of numerical methods by introducing and implementing SAGE programs

An Introduction to SAGE Programming: With Applications to SAGE Interacts for Numerical Methods emphasizes how to implement numerical methods using SAGE Math and SAGE Interacts and also addresses the fundamentals of computer programming, including if statements, loops, functions, and interacts. The book also provides a unique introduction to SAGE and its computer algebra system capabilities; discusses second and higher order equations and estimate limits; and determines derivatives, integrals, and summations. Providing critical resources for developing successful interactive SAGE numerical computations, the book is accessible without delving into the mathematical rigor of numerical methods.

The author illustrates the benefits of utilizing the SAGE language for calculus and the numerical analysis of various methods such as bisection methods, numerical integration, Taylor’s expansions, and Newton’s iterations. Providing an introduction to the terminology and concepts involved, An Introduction to SAGE Programming: With Applications to SAGE Interacts for Numerical Methods also features:

• An introduction to computer programming using SAGE
• Many practical examples throughout to illustrate the application of SAGE Interacts for various numerical methods
• Discussions on how to use SAGE Interacts and SAGE Cloud in order to create mathematical demonstrations
• Numerous homework problems and exercises that allow readers to practice their programming skillset
• A companion website that includes related SAGE programming code and select solutions to the homework problems and exercises

An Introduction to SAGE Programming: With Applications to SAGE Interacts for Numerical Methods is an ideal reference for applied mathematicians who need to employ SAGE for the study of numerical methods and analysis. The book is also an appropriate supplemental textbook for upper-undergraduate and graduate-level courses in numerical methods.

Preface vii

1. INTRODUCTION 1

1.1 What is Sage Math? 1

1.2 Various Flavors of Sage Math 1

1.2.1 Sage Math on your Machine 1

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 vs Exact Values 10

2.2.3 Constants 11

2.2.4 Breaking Long Lines of Code 12

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 53

2.3.3 Exercises 54

3. INTRODUCTION TO PROGRAMMING IN SAGE 57

3.1 Variables 58

3.1.1 Exercises 61

3.2 More on Operators 61

3.2.1 Exercises 63

3.3 Making Decisions 64

3.3.1 Boolean Expressions 64

3.3.2 If statements 66

3.3.3 Exercises 73

3.4 Loops 75

3.4.1 For loops 75

3.4.2 Strings 82

3.4.3 While loops 84

3.4.4 Nested loops 88

3.4.5 Lists 91

3.4.6 Exercises 96

3.5 Functions 99

3.5.1 Using library functions. Random, Scipy, Numpy 104

3.5.2 Exercises 105

3.6 Interacts 107

3.6.1 Exercises 123

3.7 Application to Data Security: Caesar’s Cipher. Interacts, strings, and encryption 125

3.7.1 Exercises 127

3.8 Application to Business: Present Value of an Annuity. Amortization127

3.8.1 Exercises 133

3.9 Application to Elementary Statistics. Mean, Median, Histograms, and Bar Charts. 134

3.9.1 Exercises 142

4. SAGE INTERACTS FOR NUMERICAL METHODS 143

4.1 Equations of Lines 143

4.1.1 Exercises 145

4.2 Tangent Lines and Plots 145

4.2.1 Exercises 149

4.3 Taylor Polynomials 149

4.3.1 Exercises 155

4.4 Riemann Sum and De…nite Integrals 156

4.4.1 Exercises 162

4.5 Trapezoidal Rule for Numerical Integration 162

4.5.1 Exercises 170

4.6 Bisection Algorithm for Solving Equations 170

4.6.1 Exercises 179

4.7 Newton-Raphson Algorithm for Solving Equations 179

4.7.1 Exercises 191

4.8 Polynomial Interpolation 192

4.8.1 Exercises 198

4.9 Linear Spline Interpolation 198

4.9.1 Exercises 202

4.10 Cubic Spline Interpolation 203

4.10.1 Exercises 212

4.11 SAGE for solving Di¤erential Equations 212

4.12 Numerical Methods for Ordinary Di¤erential Equations 215

4.12.1 Exercises 221

4.13 Numerical Methods for Partial Di¤erential Equations 222

4.13.1 Exercises 227

4.14 Scatter plots. Line of Best Fit and More 228

4.14.1 Exercises 236

4.15 Matrices, Eigenvalues, and Eigenvectors 236

4.15.1 Exercises 243

4.16 Solving Matrix Equations 243

4.16.1 Exercises 245

Bibliography 247

Index 249

## Books & Journals

### Books #### Common Errors in Statistics (and How to Avoid Them), 4th Edition #### The Analysis of Covariance and Alternatives: Statistical Methods for Experiments, Quasi-Experiments, and Single-Case Studies, 2nd Edition View all

### Journals #### Mathematical Finance #### Complexity View all