Use your business data to your advantage with the help of Syncfusion’s new data science offerings. Discover how a custom big data solution can provide your company with valuable predictions about key market trends.

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

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

Craig Finch

Craig Finch is a Ph. D. candidate in the Modeling and Simulation program at the University of Central Florida (UCF). He earned a Bachelor of Science degree from the University of Illinois at Urbana-Champaign and a Master of Science degree from UCF, both in electrical engineering. Craig worked as a design engineer for TriQuint Semiconductor, and currently works as a research assistant in the Hybrid Systems Lab at the UCF NanoScience Technology Center. Craig's professional goal is to develop tools for computational science and engineering and use them to solve difficult problems. In particular, he is interested in developing tools to help biologists study living systems. Craig is committed to using, developing, and promoting open-source software. He provides documentation and "how-to" examples on his blog at http://www.shocksolution.com.
I would like to thank my advisers, Dr. J. Hickman and Dr. Tom Clarke, for giving me the opportunity to pursue my doctorate. I would also like to thank my parents for buying the Apple IIGS computer that started it all.

Alerts & Offers

Series & Level

We understand your time is important. Uniquely amongst the major publishers, we seek to develop and publish the broadest range of learning and information products on each technology. Every Packt product delivers a specific learning pathway, broadly defined by the Series type. This structured approach enables you to select the pathway which best suits your knowledge level, learning style and task objectives.

Learning

As a new user, these step-by-step tutorial guides will give you all the practical skills necessary to become competent and efficient.

Beginner's Guide

Friendly, informal tutorials that provide a practical introduction using examples, activities, and challenges.

Essentials

Fast paced, concentrated introductions showing the quickest way to put the tool to work in the real world.

Cookbook

A collection of practical self-contained recipes that all users of the technology will find useful for building more powerful and reliable systems.

Blueprints

Guides you through the most common types of project you'll encounter, giving you end-to-end guidance on how to build your specific solution quickly and reliably.

Mastering

Take your skills to the next level with advanced tutorials that will give you confidence to master the tool's most powerful features.

Starting

Accessible to readers adopting the topic, these titles get you into the tool or technology so that you can become an effective user.

Progressing

Building on core skills you already have, these titles share solutions and expertise so you become a highly productive power user.