www.it-ebooks.info Sage Beginner's Guide Unlock the full potenal of Sage for simplifying and automang mathemacal compung Craig Finch BIRMINGHAM - MUMBAI www.it-ebooks.info Sage Beginner's Guide Copyright © 2011 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmied in any form or by any means, without the prior wrien permission of the publisher, except in the case of brief quotaons embedded in crical arcles or reviews. Every eort has been made in the preparaon of this book to ensure the accuracy of the informaon presented. However, the informaon contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark informaon about all of the companies and products menoned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this informaon. First published: May 2011 Producon Reference: 1250411 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-849514-46-0 www.packtpub.com Cover Image by Ed Maclean (edmaclean@gmail.com) www.it-ebooks.info Credits Author Craig Finch Reviewers Dr. David Kirkby Minh Nguyen Acquision Editor Usha Iyer Development Editor Hyacintha D'Souza Technical Editor Ajay Shanker Indexers Tejal Daruwale Rekha Nair Project Coordinator Joel Goveya Proofreaders Aaron Nash Mario Cecere Graphics Nilesh Mohite Producon Coordinator Adline Swetha Jesuthas Cover Work Adline Swetha Jesuthas www.it-ebooks.info About the Author Craig Finch is a Ph. D. Candidate in the Modeling and Simulaon 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 computaonal science and engineering and use them to solve dicult problems. In parcular, he is interested in developing tools to help biologists study living systems. Craig is commied to using, developing, and promong open-source soware. He provides documentaon 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. www.it-ebooks.info About the Reviewers Dr. David Kirkby is a chartered engineer living in Essex, England. David has a B.Sc. in Electrical and Electronic Engineering, an M.Sc. in Microwaves and OptoElectronics, and a Ph.D. in Medical Physics. Despite David's Ph.D. being in Medical Physics, it was primarily an engineering project, measuring the opcal properes of human ssue, with a mixture of Monte Carlo modeling, radio frequency design, and laser opcs. David was awarded his Ph.D. in 1999 from University College London. Although not a mathemacian, Dr. Kirkby has made extensive use of mathemacal soware. Most of his experience has been with MathemacaTM from Wolfram Research, although he has used both MATLAB TM and Simulink TM too. David is the author of a number of open-source projects, including soware for modeling transmission lines using nite dierence ( http://atlc.sourceforge.net/), design of Yagi-Uda antennas (http://www.g8wrb.org/yagi/) which can use a genec algorithm for opmizaon, as well as soware for data collecon and analysis from electronic test equipment. David once wrote a web-based interface to MathemacaTM (http://witm. sourceforge.net/ ) which allows MathemacaTM to be used from a personal computer, PDA or smartphone. Soon aer the Sage project was started by Professor William Stein, Dr. Kirkby joined the development of Sage. He primarily worked on the successful port of Sage to the Solaris and OpenSolaris operang systems and encourages other developers to write portable code, conforming to POSIX standard, avoiding GNUisms. Professionally, David's skill sets include computer modeling, radio frequency design, analogue circuit design, electromagnec compability and opcs—both free space and integrated. David has also been a Solaris system administrator for the University of Washington where the Sage project is based. When not working on wring soware, David enjoys playing chess, gardening, and spending me with his wife Lin and dog Smudge. Readers wishing to contact Dr. Kirkby can do so via his website http://www.drkirkby. co.uk/ where details of his consulng services may be found. www.it-ebooks.info Minh Nguyen has been a contributor to the Sage project since December 2007. Over the years, he has worked on various aspects of Sage ranging from the standard documentaon and modules such as cryptography, number theory, and graph theory to the Sage build system. He regularly maintains the Sage website and works on book projects that aim to provide in-depth documentaon on using Sage to study cryptography and mathemacs. More of his ranngs can be found at http://mvngu.wordpress.com. www.it-ebooks.info www.PacktPub.com Support les, eBooks, discount offers and more You might want to visit www.PacktPub.com for support les and downloads related to your book. Did you know that Packt oers eBook versions of every book published, with PDF and ePub les available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details. At www.PacktPub.com, you can also read a collecon of free technical arcles, sign up for a range of free newsleers and receive exclusive discounts and oers on Packt books and eBooks. http://PacktLib.PacktPub.com Do you need instant soluons to your IT quesons? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's enre library of books. Why Subscribe? Fully searchable across every book published by Packt Copy & paste, print and bookmark content On demand and accessible via web browser Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine enrely free books. Simply use your login credenals for immediate access. www.it-ebooks.info www.it-ebooks.info Table of Contents Preface 1 Chapter 1: What Can You Do with Sage? 9 Geng started 9 Using Sage as a powerful calculator 12 Symbolic mathemacs 14 Linear algebra 17 Solving an ordinary dierenal equaon 18 More advanced graphics 19 Visualising a three-dimensional surface 20 Typeseng mathemacal expressions 21 A praccal example: analysing experimental data 22 Time for acon – ng the standard curve 22 Time for acon – plong experimental data 24 Time for acon – ng a growth model 25 Summary 26 Chapter 2: Installing Sage 29 Before you begin 29 Installing a binary version of Sage on Windows 30 Downloading VMware Player 30 Installing VMWare Player 30 Downloading and extracng Sage 30 Launching the virtual machine 31 Start Sage 32 Installing a binary version of Sage on OS X 33 Downloading Sage 34 Installing Sage 34 Starng Sage 34 www.it-ebooks.info [...]...Table of Contents Installing a binary version of Sage on GNU/Linux Downloading and decompressing Sage Running Sage from your user account Installing for multiple users Building Sage from source Prerequisites Downloading and decompressing source tarball Building Sage Installation Summary Chapter 3: Getting Started with Sage How to get help with Sage Starting Sage from the command line Using the interactive... http://wiki.sagemath.org/SupportedPlatforms www.it-ebooks.info Preface The mission statement of the Sage project is: Creating a viable, free, open source alternative to Magma, Maple, Mathematica, and Matlab If you are familiar with any of these commercial mathematical software systems, then you already have a good idea what Sage does Sage offers several advantages over its commercial competitors Sage is... the bug list for Sage is public, and it can be accessed at http://trac.sagemath.org/ Users are encouraged to participate in the development of Sage by reporting and fixing bugs, and contributing new capabilities With bugs and source code open for public review, you can have a high degree of confidence that Sage will produce correct results This book is written for people who are new to Sage, and perhaps... experimental data and fitting models Chapter 2, Installing Sage covers how to install a binary version of Sage on Windows and install a binary version of Sage on OS X; install a binary version of Sage on GNU/Linux; compile Sage from source [2] www.it-ebooks.info Preface Chapter 3, Getting Started with Sage covers using the interactive shell; using the notebook interface; learning more about operators and... You Do with Sage? Sage is a powerful tool—but you don't have to take my word for it This chapter will showcase a few of the things that Sage can do to enhance your work At this point, don't expect to understand every aspect of the examples presented in this chapter Everything will be explained in more detail in the later chapters Look at the things Sage can do, and start to think about how Sage might... showcase some of the basics of Sage so that you can follow along using a public notebook server These examples can also be run from an interactive session if you have installed Sage www.it-ebooks.info What Can You Do with Sage? Go to http://www.sagenb.org/ and sign up for a free account You can also browse worksheets created and shared by others If you have already installed Sage, launch the notebook interface... help function to learn more about it." A block of code is set as follows: print('This is a string') print(1.0) print(sqrt) Any command-line input or output is written as follows: sage: R = 250e3 sage: C = 4e-6 sage: tau = R * C sage: tau New terms and important words are shown in bold Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "clicking the Next... a small subset of Sage' s capabilities What this book covers Chapter 1, What can You do with Sage? covers how Sage can be used for: making simple numerical calculations; performing symbolic calculations, solving systems of equations and ordinary differential equations; making plots in two and three dimensions; and analyzing experimental data and fitting models Chapter 2, Installing Sage covers how to... Mathematical software systems like Sage have highly optimized functions that implement common numerical operations like integration, solving ordinary differential equations, and solving systems of equations Sage is a collection of nearly 100 mathematical software packages, which are listed at http://www.sagemath.org/links-components.html When possible, existing tools are integrated into Sage, rather than duplicating... can graph it with the following code: f(x) = e^x * cos(x) plot(f, (x, -2, 8)) [ 15 ] www.it-ebooks.info What Can You Do with Sage? Sage will produce the following plot: Sage can also compute definite integrals symbolically: To compute a definite integral, we simply have to tell Sage the limits of integration: f(x) = sqrt(1 - x^2) f_integral = integrate(f, (x, 0, 1)) show(f_integral) The result is: This . extracng Sage 30 Launching the virtual machine 31 Start Sage 32 Installing a binary version of Sage on OS X 33 Downloading Sage 34 Installing Sage 34 Starng Sage. version of Sage on GNU/Linux 35 Downloading and decompressing Sage 35 Running Sage from your user account 36 Installing for mulple users 37 Building Sage from