Sage Beginner's Guide

Unlock the full potential of Sage for simplifying and automating mathematical computing with this book and eBook

Sage Beginner's Guide

Beginner's Guide
Craig Finch

Unlock the full potential of Sage for simplifying and automating mathematical computing with this book and eBook
$29.99
$49.99
RRP $29.99
RRP $49.99
eBook
Print + eBook
$12.99 p/month

Want this title & more? Subscribe to PacktLib

Enjoy full and instant access to over 2000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.
+ Collection
Free Sample

Book Details

ISBN 139781849514460
Paperback364 pages

About This Book

  • The best way to learn  Sage which  is a open source alternative to Magma, Maple, Mathematica, and Matlab
  • Learn to use symbolic and numerical computation to simplify your work and produce publication-quality graphics
  • Numerically solve systems of equations, find roots, and analyze data from experiments or simulations
  • Save time on algebra by automatically simplifying symbolic expressions, performing calculus operations, and manipulating vectors and matrices
  • Use the Python programming language to write and debug code more quickly than traditional compiled languages like C++ or Fortran
  • Key features of Sage are explained using practical examples from engineering, science, and applied mathematics

Who This Book Is For

If you are an engineer, scientist, mathematician, or student, this book is for you. To get the most from Sage by using the Python programming language, we'll give you the basics of the language to get you started. For this, it will be helpful if you have some experience with basic programming concepts.

Table of Contents

Chapter 1: What Can You Do with Sage?
Getting started
Using Sage as a powerful calculator
More advanced graphics
A practical example: analysing experimental data
Time for action – fitting the standard curve
Time for action – plotting experimental data
Time for action – fitting a growth model
Summary
Chapter 2: Installing Sage
Before you begin
Installing a binary version of Sage on Windows
Installing a binary version of Sage on OS X
Installing a binary version of Sage on GNU/Linux
Building Sage from source
Summary
Chapter 3: Getting Started with Sage
How to get help with Sage
Starting Sage from the command line
Using the interactive shell
Time for action – doing calculations on the command line
Using the notebook interface
Time for action – doing calculations with the notebook interface
Displaying results of calculations
Operators and variables
Time for action – using strings
Callable symbolic expressions
Time for action – defining callable symbolic expressions
Functions
Time for action – calling functions
Time for action – defining and using your own functions
Time for action – defining a function with keyword arguments
Objects
Time for action – working with objects
Summary
Chapter 4: Introducing Python and Sage
Python 2 and Python 3
Writing code for Sage
Sequence types: lists, tuples, and strings
Time for action – creating lists
Time for action – accessing items in a list
Time for action – returning multiple values from a function
Time for action – working with strings
For loops
Time for action – iterating over lists
Time for action – computing a solution to the diffusion equation
Time for action – using a list comprehension
While loops and text file I/O
Time for action – saving data in a text file
Time for action – reading data from a text file
If statements and conditional expressions
Storing data in a dictionary
Time for action – defining and accessing dictionaries
Lambda forms
Time for action – using lambda to create an anonymous function
Summary
Chapter 5: Vectors, Matrices, and Linear Algebra
Vectors and vector spaces
Time for action – working with vectors
Time for action – manipulating elements of vectors
Matrices and matrix spaces
Time for action – solving a system of linear equations
Time for action – accessing elements and parts of a matrix
Time for action – manipulating matrices
Time for action – matrix algebra
Time for action – trying other matrix methods
Time for action – computing eigenvalues and eigenvectors
Time for action – computing the QR factorization
Time for action – computing the singular value decomposition
An introduction to NumPy
Time for action – creating NumPy arrays
Time for action – working with NumPy arrays
Time for action – creating matrices in NumPy
Summary
Chapter 6: Plotting with Sage
Confusion alert: Sage plots and matplotlib
Plotting in two dimensions
Time for action – plotting symbolic expressions
Time for action – plotting a function with a pole
Time for action – plotting a parametric function
Time for action – making a polar plot
Time for action – plotting a vector field
Time for action – making a scatter plot
Time for action – plotting a list
Time for action – plotting with graphics primitives
Using matplotlib
Time for action – plotting functions with matplotlib
Time for action – getting the matplotlib figure object
Time for action – improving polar plots
Time for action – making a bar chart
Time for action – making a pie chart
Time for action – plotting a histogram
Plotting in three dimensions
Time for action – make an interactive 3D plot
Time for action – parametric plots in 3D
Time for action – making some contour plots
Summary
Chapter 7: Making Symbolic Mathematics Easy
Using the notebook interface
Defining symbolic expressions
Time for action – defining callable symbolic expressions
Time for action – defining relational expressions
Time for action – relational expressions with assumptions
Manipulating expressions
Time for action – manipulating expressions
Time for action – working with rational functions
Time for action – substituting symbols in expressions
Time for action – expanding and factoring polynomials
Time for action – manipulating trigonometric expressions
Time for action – simplifying expressions
Solving equations and finding roots
Time for action – solving equations
Time for action – finding roots
Differential and integral calculus
Time for action – calculating limits
Time for action – calculating derivatives
Time for action – calculating integrals
Series and summations
Time for action – computing sums of series
Time for action – finding Taylor series
Laplace transforms
Time for action – computing Laplace transforms
Solving ordinary differential equations
Time for action – solving an ordinary differential equation
Summary
Chapter 8: Solving Problems Numerically
Sage and NumPy
Solving equations and finding roots numerically
Time for action – finding roots of a polynomial
Finding minima and maxima of functions
Time for action – minimizing a function of one variable
Time for action – minimizing a function of several variables
Numerical approximation of derivatives
Time for action – approximating derivatives with differences
Time for action – computing gradients
Numerical integration
Time for action – numerical integration
Time for action – numerical integration with NumPy
Discrete Fourier transforms
Time for action – computing discrete Fourier transforms
Time for action – plotting window functions
Solving ordinary differential equations
Time for action – solving a first-order ODE
Time for action – solving a higher-order ODE
Time for action – alternative method of solving a system of ODEs
Numerical optimization
Time for action – linear programming
Time for action – least squares fitting
Time for action – a constrained optimization problem
Probability
Time for action – accessing probability distribution functions
Summary
Chapter 9: Learning Advanced Python Programming
How to write good software
Object-oriented programming
Time for action – defining a class that represents a tank
Time for action – making the tanks move
Time for action – creating your first module
Time for action – creating a vehicle base class
Time for action – creating a combat simulation package
Potential pitfalls when working with classes and instances
Time for action – using class and instance attributes
Time for action – more about class and instance attributes
Time for action – creating empty classes and functions
Handling errors gracefully
Time for action – raising and handling exceptions
Time for action – creating custom exception types
Unit testing
Time for action – creating unit tests for the Tank class
Summary
Chapter 10: Where to go from here
Typesetting equations with LaTeX
Time for action – PDF output from the notebook interface
Time for action – working with LaTeX markup in the notebook interface
Time for action – putting it all together
Speeding up execution
Time for action – detecting collisions between spheres
Time for action – detecting collisions: command-line version
Time for action – faster collision detection
Time for action – using NumPy
Time for action – optimizing collision detection with Cython
Calling Sage from Python
Time for action – calling Sage from a Python script
Introducing Python decorators
Time for action – introducing the Python decorator
Making interactive graphics
Time for action – making interactive controls
Using interactive controls
Summary

What You Will Learn

  • Download and install Sage, and learn how to use the command-line and notebook interface
  • Learn the basics of Python programming
  • Solve problems in linear algebra with vectors and matrices
  • Visualize functions and data sets with publication-quality graphics
  • Define, re-arrange, and simplify symbolic expressions
  • Calculate integrals, derivatives, and transforms symbolically and numerically
  • Solve ordinary differential equations (ODEs) and systems of ODEs
  • Fit functions to data using unconstrained and constrained numerical optimization
  • Apply object-oriented principles to simplify your code
  • Speed up calculations with Numpy arrays
  • Learn to use Sage as a toolbox for writing Python programs

In Detail

Your work demands results, and you don't have time for tedious, repetitive mathematical tasks. Sage is a free, open-source software package that automates symbolic and numerical calculations with the power of the Python programming language, so you can focus on the analytical and creative aspects of your work or studies.

Sage Beginner's Guide shows you how to do calculations with Sage. Each concept is illustrated with a complete example that you can use as a starting point for your own work. You will learn how to use many of the functions that are built in to Sage, and how to use Python to write sophisticated programs that utilize the power of Sage.

This book starts by showing you how to download and install Sage, and introduces the command-line interface and the graphical notebook interface. It also includes an introduction to Python so you can start programming in Sage. Every major concept is illustrated with a practical example.

After learning the fundamentals of variables and functions in Sage, you will learn how to symbolically simplify expressions, solve equations, perform integrals and derivatives, and manipulate vectors and matrices. You will learn how Sage can produce numerous kinds of plots and graphics. The book will demonstrate numerical methods in Sage, and explain how to use object-oriented programming to improve your code.

Sage Beginner's Guide will give you the tools you need to unlock the full potential of Sage for simplifying and automating mathematical computing.

Authors

Table of Contents

Chapter 1: What Can You Do with Sage?
Getting started
Using Sage as a powerful calculator
More advanced graphics
A practical example: analysing experimental data
Time for action – fitting the standard curve
Time for action – plotting experimental data
Time for action – fitting a growth model
Summary
Chapter 2: Installing Sage
Before you begin
Installing a binary version of Sage on Windows
Installing a binary version of Sage on OS X
Installing a binary version of Sage on GNU/Linux
Building Sage from source
Summary
Chapter 3: Getting Started with Sage
How to get help with Sage
Starting Sage from the command line
Using the interactive shell
Time for action – doing calculations on the command line
Using the notebook interface
Time for action – doing calculations with the notebook interface
Displaying results of calculations
Operators and variables
Time for action – using strings
Callable symbolic expressions
Time for action – defining callable symbolic expressions
Functions
Time for action – calling functions
Time for action – defining and using your own functions
Time for action – defining a function with keyword arguments
Objects
Time for action – working with objects
Summary
Chapter 4: Introducing Python and Sage
Python 2 and Python 3
Writing code for Sage
Sequence types: lists, tuples, and strings
Time for action – creating lists
Time for action – accessing items in a list
Time for action – returning multiple values from a function
Time for action – working with strings
For loops
Time for action – iterating over lists
Time for action – computing a solution to the diffusion equation
Time for action – using a list comprehension
While loops and text file I/O
Time for action – saving data in a text file
Time for action – reading data from a text file
If statements and conditional expressions
Storing data in a dictionary
Time for action – defining and accessing dictionaries
Lambda forms
Time for action – using lambda to create an anonymous function
Summary
Chapter 5: Vectors, Matrices, and Linear Algebra
Vectors and vector spaces
Time for action – working with vectors
Time for action – manipulating elements of vectors
Matrices and matrix spaces
Time for action – solving a system of linear equations
Time for action – accessing elements and parts of a matrix
Time for action – manipulating matrices
Time for action – matrix algebra
Time for action – trying other matrix methods
Time for action – computing eigenvalues and eigenvectors
Time for action – computing the QR factorization
Time for action – computing the singular value decomposition
An introduction to NumPy
Time for action – creating NumPy arrays
Time for action – working with NumPy arrays
Time for action – creating matrices in NumPy
Summary
Chapter 6: Plotting with Sage
Confusion alert: Sage plots and matplotlib
Plotting in two dimensions
Time for action – plotting symbolic expressions
Time for action – plotting a function with a pole
Time for action – plotting a parametric function
Time for action – making a polar plot
Time for action – plotting a vector field
Time for action – making a scatter plot
Time for action – plotting a list
Time for action – plotting with graphics primitives
Using matplotlib
Time for action – plotting functions with matplotlib
Time for action – getting the matplotlib figure object
Time for action – improving polar plots
Time for action – making a bar chart
Time for action – making a pie chart
Time for action – plotting a histogram
Plotting in three dimensions
Time for action – make an interactive 3D plot
Time for action – parametric plots in 3D
Time for action – making some contour plots
Summary
Chapter 7: Making Symbolic Mathematics Easy
Using the notebook interface
Defining symbolic expressions
Time for action – defining callable symbolic expressions
Time for action – defining relational expressions
Time for action – relational expressions with assumptions
Manipulating expressions
Time for action – manipulating expressions
Time for action – working with rational functions
Time for action – substituting symbols in expressions
Time for action – expanding and factoring polynomials
Time for action – manipulating trigonometric expressions
Time for action – simplifying expressions
Solving equations and finding roots
Time for action – solving equations
Time for action – finding roots
Differential and integral calculus
Time for action – calculating limits
Time for action – calculating derivatives
Time for action – calculating integrals
Series and summations
Time for action – computing sums of series
Time for action – finding Taylor series
Laplace transforms
Time for action – computing Laplace transforms
Solving ordinary differential equations
Time for action – solving an ordinary differential equation
Summary
Chapter 8: Solving Problems Numerically
Sage and NumPy
Solving equations and finding roots numerically
Time for action – finding roots of a polynomial
Finding minima and maxima of functions
Time for action – minimizing a function of one variable
Time for action – minimizing a function of several variables
Numerical approximation of derivatives
Time for action – approximating derivatives with differences
Time for action – computing gradients
Numerical integration
Time for action – numerical integration
Time for action – numerical integration with NumPy
Discrete Fourier transforms
Time for action – computing discrete Fourier transforms
Time for action – plotting window functions
Solving ordinary differential equations
Time for action – solving a first-order ODE
Time for action – solving a higher-order ODE
Time for action – alternative method of solving a system of ODEs
Numerical optimization
Time for action – linear programming
Time for action – least squares fitting
Time for action – a constrained optimization problem
Probability
Time for action – accessing probability distribution functions
Summary
Chapter 9: Learning Advanced Python Programming
How to write good software
Object-oriented programming
Time for action – defining a class that represents a tank
Time for action – making the tanks move
Time for action – creating your first module
Time for action – creating a vehicle base class
Time for action – creating a combat simulation package
Potential pitfalls when working with classes and instances
Time for action – using class and instance attributes
Time for action – more about class and instance attributes
Time for action – creating empty classes and functions
Handling errors gracefully
Time for action – raising and handling exceptions
Time for action – creating custom exception types
Unit testing
Time for action – creating unit tests for the Tank class
Summary
Chapter 10: Where to go from here
Typesetting equations with LaTeX
Time for action – PDF output from the notebook interface
Time for action – working with LaTeX markup in the notebook interface
Time for action – putting it all together
Speeding up execution
Time for action – detecting collisions between spheres
Time for action – detecting collisions: command-line version
Time for action – faster collision detection
Time for action – using NumPy
Time for action – optimizing collision detection with Cython
Calling Sage from Python
Time for action – calling Sage from a Python script
Introducing Python decorators
Time for action – introducing the Python decorator
Making interactive graphics
Time for action – making interactive controls
Using interactive controls
Summary

Book Details

ISBN 139781849514460
Paperback364 pages
Read More

Recommended for You