AN INTRODUCTION TO SAGE PROGRAMMING

Similar documents
Excel Formulas & Functions

School of Innovative Technologies and Engineering

Mathematics. Mathematics

MMOG Subscription Business Models: Table of Contents

Lecture Notes on Mathematical Olympiad Courses

Instrumentation, Control & Automation Staffing. Maintenance Benchmarking Study

THE PROMOTION OF SOCIAL AWARENESS

Bittinger, M. L., Ellenbogen, D. J., & Johnson, B. L. (2012). Prealgebra (6th ed.). Boston, MA: Addison-Wesley.

AGS THE GREAT REVIEW GAME FOR PRE-ALGEBRA (CD) CORRELATED TO CALIFORNIA CONTENT STANDARDS

Course Syllabus for Math

Answers To Hawkes Learning Systems Intermediate Algebra

Grade 6: Correlated to AGS Basic Math Skills

Honors Mathematics. Introduction and Definition of Honors Mathematics

To link to this article: PLEASE SCROLL DOWN FOR ARTICLE

Mathematics subject curriculum

Business Analytics and Information Tech COURSE NUMBER: 33:136:494 COURSE TITLE: Data Mining and Business Intelligence

Guide to Teaching Computer Science

Dublin City Schools Mathematics Graded Course of Study GRADE 4

Radius STEM Readiness TM

Introduction to the Practice of Statistics

UNIT ONE Tools of Algebra

AU MATH Calculus I 2017 Spring SYLLABUS

HOLMER GREEN SENIOR SCHOOL CURRICULUM INFORMATION

Diagnostic Test. Middle School Mathematics

MTH 141 Calculus 1 Syllabus Spring 2017

CHALLENGES FACING DEVELOPMENT OF STRATEGIC PLANS IN PUBLIC SECONDARY SCHOOLS IN MWINGI CENTRAL DISTRICT, KENYA

STA 225: Introductory Statistics (CT)

Math 121 Fundamentals of Mathematics I

Math 181, Calculus I

Physics Experimental Physics II: Electricity and Magnetism Prof. Eno Spring 2017

21st CENTURY SKILLS IN 21-MINUTE LESSONS. Using Technology, Information, and Media

1 3-5 = Subtraction - a binary operation

Syllabus ENGR 190 Introductory Calculus (QR)

Measurement. When Smaller Is Better. Activity:

Statewide Framework Document for:

Python Machine Learning

Algebra 1, Quarter 3, Unit 3.1. Line of Best Fit. Overview

SkillPort Quick Start Guide 7.0

THE UNITED REPUBLIC OF TANZANIA MINISTRY OF EDUCATION, SCIENCE, TECHNOLOGY AND VOCATIONAL TRAINING CURRICULUM FOR BASIC EDUCATION STANDARD I AND II

PROGRAM REVIEW CALCULUS TRACK MATH COURSES (MATH 170, 180, 190, 191, 210, 220, 270) May 1st, 2012

University of Groningen. Systemen, planning, netwerken Bosman, Aart

Quick Start Guide 7.0

International Series in Operations Research & Management Science

CURRICULUM VITAE. To develop expertise in Graph Theory and expand my knowledge by doing Research in the same.

Exploring Derivative Functions using HP Prime

Grading Policy/Evaluation: The grades will be counted in the following way: Quizzes 30% Tests 40% Final Exam: 30%

Course Name: Elementary Calculus Course Number: Math 2103 Semester: Fall Phone:

TabletClass Math Geometry Course Guidebook

AP Statistics Summer Assignment 17-18

Learning Disability Functional Capacity Evaluation. Dear Doctor,

Focus of the Unit: Much of this unit focuses on extending previous skills of multiplication and division to multi-digit whole numbers.

Biology Keystone Questions And Answers

Class Meeting Time and Place: Section 3: MTWF10:00-10:50 TILT 221

Kendriya Vidyalaya Sangathan

AP Calculus AB. Nevada Academic Standards that are assessable at the local level only.

FUNCTIONS AND OPERATORS IN MAPLE AND MATLAB. Matthias Kawski (Received September 23, 2003)

The lab is designed to remind you how to work with scientific data (including dealing with uncertainty) and to review experimental design.

B.S/M.A in Mathematics

Edexcel GCSE. Statistics 1389 Paper 1H. June Mark Scheme. Statistics Edexcel GCSE

Math-U-See Correlation with the Common Core State Standards for Mathematical Content for Third Grade

GACE Computer Science Assessment Test at a Glance

Iep Data Collection Templates

The Handbook of Dispute Resolution

PROVIDING AND COMMUNICATING CLEAR LEARNING GOALS. Celebrating Success THE MARZANO COMPENDIUM OF INSTRUCTIONAL STRATEGIES

Mathematics Assessment Plan

Analysis of Enzyme Kinetic Data

1.11 I Know What Do You Know?

SOUTHERN MAINE COMMUNITY COLLEGE South Portland, Maine 04106

A R "! I,,, !~ii ii! A ow ' r.-ii ' i ' JA' V5, 9. MiN, ;

Enhancing Learning with a Poster Session in Engineering Economy

12-WEEK GRE STUDY PLAN

Fountas-Pinnell Level P Informational Text

New Jersey Society of Radiologic Technologists Annual Meeting & Registry Review

TEACHING Simple Tools Set II

Math Techniques of Calculus I Penn State University Summer Session 2017

CPMT 1347 Computer System Peripherals COURSE SYLLABUS

STT 231 Test 1. Fill in the Letter of Your Choice to Each Question in the Scantron. Each question is worth 2 point.

Characteristics of the Text Genre Informational Text Text Structure

Bluetooth mlearning Applications for the Classroom of the Future

Research computing Results

Physical Versus Virtual Manipulatives Mathematics

PeopleSoft Human Capital Management 9.2 (through Update Image 23) Hardware and Software Requirements

Level 1 Mathematics and Statistics, 2015

Strategies for Solving Fraction Tasks and Their Link to Algebraic Thinking

Undergraduate Program Guide. Bachelor of Science. Computer Science DEPARTMENT OF COMPUTER SCIENCE and ENGINEERING

Common Core Curriculum Map For Sociology

Intermediate Algebra

Probability and Statistics Curriculum Pacing Guide

10.2. Behavior models

Holt Mcdougal Pre Algebra Teachers Edition

Characterizing Mathematical Digital Literacy: A Preliminary Investigation. Todd Abel Appalachian State University

THE UNIVERSITY OF SYDNEY Semester 2, Information Sheet for MATH2068/2988 Number Theory and Cryptography

St Math Teacher Login

Foothill College Fall 2014 Math My Way Math 230/235 MTWThF 10:00-11:50 (click on Math My Way tab) Math My Way Instructors:

Dialogue Live Clientside

Self Study Report Computer Science

THE ALLEGORY OF THE CATS By David J. LeMaster

We are strong in research and particularly noted in software engineering, information security and privacy, and humane gaming.

Content Teaching Methods: Social Studies. Dr. Melinda Butler

Transcription:

AN INTRODUCTION TO SAGE PROGRAMMING

AN INTRODUCTION TO SAGE PROGRAMMING With Applications to SAGE Interacts for Numerical Methods RAZVAN A. MEZEI Lenoir-Rhyne University Donald & Helen Schort School of Mathematics and Computing Sciences Hickory, NC USA

Copyright 2016 by John Wiley & Sons, Inc. All rights reserved Published by John Wiley & Sons, Inc., Hoboken, New Jersey Published simultaneously in Canada No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 750-4470, or on the web at www.copyright.com. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions. Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts in preparing this book, they make no representations or warranties with respect to the accuracy or completeness of the contents of this book and specifically disclaim any implied warranties of merchantability or fitness for a particular purpose. No warranty may be created or extended by sales representatives or written sales materials. The advice and strategies contained herein may not be suitable for your situation. You should consult with a professional where appropriate. Neither the publisher nor author shall be liable for any loss of profit or any other commercial damages, including but not limited to special, incidental, consequential, or other damages. For general information on our other products and services or for technical support, please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic formats. For more information about Wiley products, visit our web site at www.wiley.com. Library of Congress Cataloging-in-Publication Data applied for. ISBN:9781119122784 Typeset in 10/12pt TimesLTStd by SPi Global, Chennai, India. Printed in the United States of America 10987654321 1 2016

I would like to dedicate this work to all my instructors who passionately directed my interest into the great fields of Mathematics, Computer Science, and Statistics. To name just a few of them, in chronological order: Aurel Netea, Petru Dragos, Barnabas Bede, Alina Alb Lupas, Dan Noje, Mircea Balaj, Sorin Gal, Mircea Dragan, Alexandru Bica, Ioan Fechete, Ioan Dzitac, George Anastassiou, Maria Botelho, James Campbell, E. Olusegun George, Nikos Frantzikinakis, and not the least Seok Wong. There are many more, but the named ones modeled my thinking and gave me a direction to where I am today and influenced me the most. Thank you from all my heart for your dedication, support, and friendship. Razvan A. Mezei

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

viii CONTENTS 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

CONTENTS ix 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

PREFACE This work is intended to be a gentle introduction to programming in Sage Math and Sage Interacts. It assumes no programming background from the reader, and it is specifically tailored for Mathematics, Mathematics Education, and Engineering students and instructors. The book starts with a description on how one can use Sage Math as a calculator. It also explains how one can use it for computations and for plotting. Then, it covers a brief and gentle introduction to programming in Sage Math. You will learn how to create your own methods in Sage Math and how to create Sage Interacts. The book ends with a chapter that gives several examples on how one can use Sage Interacts for various Numerical Methods. If you have no programming background yet, your programming skills need some improvements, you want to learn how to use Sage Math to program some numerical methods, or you want to create neat interactive representations of some mathematical concepts, then this book is for you. The book, however, does not address in detail the mathematical topics covered in the given Sage Interacts examples. In particular, no mathematical proofs are given in here. If you want to study the Mathematical side of Numerical Analysis, we recommend pairing this book with such a textbook. See, for example, [2; 7; 8]. If you are still wondering whether to use a programming language such as Python, C, C++, Java, or some computational software such as Maple, Mathematica, Octave, or R, look no further. We strongly recommend you Sage Math. It is FREE, open-source, and it uses a Python-like syntax. This last phrase contains some of the strongest arguments why you may want to choose Sage Math. To elaborate on the last statement, free open-source software allows you to use the software for free and also allows you to access the source code, which can be

xii PREFACE a great source of inspiration and information. It also allows you to obtain the entire Sage Math s source code and change it to better address your own needs. The Sage Math syntax is similar to that of Python. Python has become very popular for being one of the easiest introductory programming languages. It became so trendy that many (if not most, by the time you read this book) universities in the United States are using Python to teach Introductory to Programming courses. It is that easy! In fact, most of the Sage Math source code was written in Python. An interesting article one may want to read in this direction is Python bumps off Java as top learning language, by Joab Jackson (http://www.javaworld.com/article/2452940/learn-java /python-bumps-off-java-as-top-learning-language.html). It says that Python has surpassed Java as the top language used to introduce U.S. students to programming and computer science. We hope we got your interest in learning Sage Math. You can use it as a Computer Algebra System, as a Programming Tool, or to create nice interactive mathematical demonstrations (using Sage Interacts). You can download and install Sage Math on your own machine, or you can use it over the Internet: for this, you may either choose Sage Cloud, or you may prefer Sage Cell. Sage is accessible from your desktop computer or from your smartphone. We recommend this book to all undergraduate Mathematics, Mathematics Education, Computer Science and Information Technology, pre-engineering, and Science students and instructors. Sage Math can be used in most Mathematics courses, in Introduction to Programming courses, as well as other computational courses. Razvan A. Mezei USA