Arbitrary Precision and Symbolic Calculations

Size: px
Start display at page:

Download "Arbitrary Precision and Symbolic Calculations"

Transcription

1 Arbitrary Precision and Symbolic Calculations K. 1 1 Department of Mathematics 2018

2 Sympy There are several packages for Python that do symbolic mathematics. The most prominent of these seems to be Sympy. Sympy stands for Symbolic Python. Sympy is a separate project from Numpy, Scipy, Pylab, and Matplotlib. We can typically pick what we want from those and load them using from *py import * Don t do that with Sympy.

3 Loading Sympy from numpy import * import sympy as sp I recommend doing it this way because Sympy has many functions with the same names as common math or Numpy functions. For example, sp.zeros(5) returns a Sympy 5 5 matrix of sympy.core.numbers.zero values, while zeros(5) returns a 5 1 array of zeros with type numpy.float64. Failing to keep these packages straight can lead to a great deal of confusion and frustration.

4 Numbers Sympy understands many more basic data types than simple int and float. z = sp.zeros(3) z[0,1]=3 type(z[0,1]) gives a result of class sympy.core.numbers.integer. z[0,2] = 3. give a result of class sympy.core.numbers.float

5 Numbers z[1,0] = sp.pi yields a result of type sympy.core.numbers.pi while z[1,1] = pi gives a type sympy.core.numbers.float z[1,2] = sp.exp(1) has type sympy.core.numbers.exp1

6 Rationals We can do rational numbers in Sympy: z[2,1] = sp.rational(2,5) print(z[2,1]) yields 2/5. This has type sympy.core.numbers.rational, by the way. Observe the capital R and the comma in the arguments. z[2,2] = sp.rational(1/2) type(z[2,2]) gives sympy.core.numbers.zero. But z[2,2] = sp.rational(1,2) type(z[2,2]) is sympy.core.numbers.half

7 Floating Point We can evaluate any number to arbitrary precision using the evalf() method. q = sp.rational(3,7) print(q.evalf()) gives Not good enough? q.evalf(51) gives Likewise, sp.pi.evalf(51) is

8 Exactness The good and bad news in this is that Sympy knows the difference between an exact number and an approximation. a = sin(pi/4) print(a) b = sp.sin(pi/4) print(b) c = sp.sin(sp.pi/4) print(c) gives , , and sqrt(2)/2, respectively.

9 Precision Sympy floating point numbers are different from the hardware floating point numbers used in Python and Numpy. However, Sympy by default uses the same precision in the mantissa as IEEE 754. a = sin(1) b = sp.sin(1) c = (a-b).evalf() yields e-18. But... a = sin(1) b = sp.sin(1).evalf() c = a-b yields 0.

10 Variables In Numpy/Python, every variable has a value. By contrast, we can make symbolic variables in Sympy, variables in a mathematical sense. There are a couple of ways to do this. sp.var( x,y ) makes x and y into variables. Often people use the syntax x,y = symbols( x,y ) to do the same thing.

11 Ranges of Variables We can make ranges of variables. sp.var( u:3 ) gives (u0, u1, u2). sp.var( a:d ) gives (a, b, c, d) a,b,c,d = sp.symbols( a:d ) does the same thing as the last.

12 Principles Symbolic calculation is very resource- and time-intensive. It is recursive. It is slow. Use symbolic calculation when you have a special need for it. Always convert to floating point or integer data types as soon as you can afford to.

13 Why would we use this? Suppose we want to demonstrate experimentally the relation ( e = lim ) n. n n def num_exp(n): return (1.+1./n)**n

14 Time required: 1.7e-4 seconds

15 Symbolic version The high-precision version is a bit different: here digit is 50. def sym_exp(n,digit): res = (1 + sp.rational(1,n).evalf(digit))**n.evalf(digit) return res

16 Time required: 2.0e-2 seconds

17 Caution! We could write the symbolic version badly (I did). def slo_exp(n,digit): res = (1 + sp.rational(1,n))**n return res.evalf(digit) This did not finish in the five minutes I gave it. Switch to floating point as early as possible. Even 50-digit floating point is spectacularly faster than rational calculations.

18 Functions vs. Expressions It is important in symbolic calculations to distinguish between functions and expressions. An expression is any combination of arithmetic operators with symbolic and numerical objects: e.g sp.var( x,alpha ) expr1 = x*x*x*x-alpha expr2 = sp.sin(x) A function is... a function. It maps arguments to some result. When we evaluate a function at a symbolic argument, the result is an expression.

19 Functions vs. Expressions f = lambda x: x*x*x*x-alpha v = f(2) results in v = -alpha u = f(x+2) gives u = -alpha + (x + 2)**4. The f is a function, while u and v are expressions.

20 Algebraic operations We can do algebraic operations on expressions. Most of these operations can be expressed as methods of the expressions, or as stand-alone functions. u.expand() or sp.expand(u) results in -alpha + x**4 + 8*x**3 + 24*x**2 + 32*x The expand() method just distributes multiplication over addition.

21 Factor The factor method tries to factor polynomials. (x*x+2*x+1).factor() sp.factor(x*x+2*x+1) give the same result: (x + 1)**2 sp.factor(x**3-3*x**2+x-3) yields (x - 3)*(x**2 + 1). sp.factor(x**3-3*x**2+x-3,extension=[sp.i]) gives (x - 3)*(x - I)*(x + I). Note that the imaginary unit in Sympy is I.

22 Fractions There are a couple of methods to handle fractional expressions. p = x**3-3*x**2+x-3 q = (x-2)*(x-1)*(x+3) r = sp.apart(p/q) results in 1-3/(x + 3) + 1/(x - 1) - 1/(x - 2) sp.together(r) gives ((x - 2)*(x - 1)*(x + 3) - 3*(x - 2)*(x - 1) + (x - 2)*(x + 3) - (x - 1)*(x + 3))/((x - 2)*(x - 1)*(x + 3)) Incidentally sp.numer(p/q) gives the numerator of the fraction; sp.denom(p/q)...

23 Simplify The simplify method tries to distribute, factor, cancel, and use some trig identities to make an expression smaller. r.together().simplify() gives (x**3-3*x**2 + x - 3)/(x**3-7*x + 6) ((x*x+2*x+1)/(x+1)).simplify() produces x + 1. Note that simplification is considered to be a purely formal process. No attention was paid to what happens if x = -1. sp.simplify(sp.tan(x)**2+1) results in cos(x)**(-2).

24 Substitution We can substitute into expressions. Recall that u = -alpha + (x + 2)**4. u.subs(x,0) gives -alpha+16. u.subs(x,x-2) gives -alpha + x**4. u.subs(x,0).subs(alpha,23) yields -7.

Symbolic and Automatic Di erentiation in Python

Symbolic and Automatic Di erentiation in Python Lab 15 Symbolic and Automatic Di erentiation in Python Lab Objective: Python is good for more than just analysis of numerical data. There are several packages available which allow symbolic and automatic

More information

Interval Arithmetic. MCS 507 Lecture 29 Mathematical, Statistical and Scientific Software Jan Verschelde, 28 October 2011

Interval Arithmetic. MCS 507 Lecture 29 Mathematical, Statistical and Scientific Software Jan Verschelde, 28 October 2011 Naive Arithmetic 1 2 Naive 3 MCS 507 Lecture 29 Mathematical, Statistical and Scientific Software Jan Verschelde, 28 October 2011 Naive Arithmetic 1 2 Naive 3 an expression Naive Problem: Evaluate f(x,

More information

Choose the file menu, and select Open. Input to be typed at the Maple prompt. Output from Maple. An important tip.

Choose the file menu, and select Open. Input to be typed at the Maple prompt. Output from Maple. An important tip. MAPLE Maple is a powerful and widely used mathematical software system designed by the Computer Science Department of the University of Waterloo. It can be used for a variety of tasks, such as solving

More information

YOGYAKARTA STATE UNIVERSITY MATHEMATICS AND NATURAL SCIENCES FACULTY MATHEMATICS EDUCATION STUDY PROGRAM

YOGYAKARTA STATE UNIVERSITY MATHEMATICS AND NATURAL SCIENCES FACULTY MATHEMATICS EDUCATION STUDY PROGRAM YOGYAKARTA STATE UNIVERSITY MATHEMATICS AND NATURAL SCIENCES FACULTY MATHEMATICS EDUCATION STUDY PROGRAM TOPIC 1 INTRODUCING SOME MATHEMATICS SOFTWARE (Matlab, Maple and Mathematica) This topic provides

More information

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc.

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc. CSC312 Principles of Programming Languages : Functional Programming Language Overview of Functional Languages They emerged in the 1960 s with Lisp Functional programming mirrors mathematical functions:

More information

Chapter 2. Python Programming for Physicists. Soon-Hyung Yook. March 31, Soon-Hyung Yook Chapter 2 March 31, / 52

Chapter 2. Python Programming for Physicists. Soon-Hyung Yook. March 31, Soon-Hyung Yook Chapter 2 March 31, / 52 Chapter 2 Python Programming for Physicists Soon-Hyung Yook March 31, 2017 Soon-Hyung Yook Chapter 2 March 31, 2017 1 / 52 Table of Contents I 1 Getting Started 2 Basic Programming Variables and Assignments

More information

CS177 Python Programming. Recitation 2 - Computing with Numbers

CS177 Python Programming. Recitation 2 - Computing with Numbers CS177 Python Programming Recitation 2 - Computing with Numbers Outline Data types. Variables Math library. Range Function What is data (in the context of programming)? Values that are stored and manipulated

More information

Computer Science 102. Into to Computational Modeling Special Topics: Programming in Matlab

Computer Science 102. Into to Computational Modeling Special Topics: Programming in Matlab Computer Science 102 Into to Computational Modeling Special Topics: Programming in Matlab Matlab An integrated programming and graphical environment Interpreted : interactive; get answer immediately Also

More information

Get It Interpreter Scripts Arrays. Basic Python. K. Cooper 1. 1 Department of Mathematics. Washington State University. Basics

Get It Interpreter Scripts Arrays. Basic Python. K. Cooper 1. 1 Department of Mathematics. Washington State University. Basics Basic Python K. 1 1 Department of Mathematics 2018 Python Guido van Rossum 1994 Original Python was developed to version 2.7 2010 2.7 continues to receive maintenance New Python 3.x 2008 The 3.x version

More information

Introduction to Scientific Computing with Python, part two.

Introduction to Scientific Computing with Python, part two. Introduction to Scientific Computing with Python, part two. M. Emmett Department of Mathematics University of North Carolina at Chapel Hill June 20 2012 The Zen of Python zen of python... fire up python

More information

MST30040 Differential Equations via Computer Algebra Fall 2010 Worksheet 1

MST30040 Differential Equations via Computer Algebra Fall 2010 Worksheet 1 MST3000 Differential Equations via Computer Algebra Fall 2010 Worksheet 1 1 Some elementary calculations To use Maple for calculating or problem solving, the basic method is conversational. You type a

More information

Introduction to Programming II W4260. Lecture 2

Introduction to Programming II W4260. Lecture 2 Introduction to Programming II W4260 Lecture 2 Overview Storing Data Basic types Arrays Controlling the flow of execution Loops (for, while) Ifthenelse Operators Arithmetic, relational, logical Functions

More information

Section 1: Numerical Calculations

Section 1: Numerical Calculations Section 1: Numerical Calculations In this section you will use Maple to do some standard numerical calculations. Maple's ability to produce exact answers in addition to numerical approximations gives you

More information

Arithmetic expressions can be typed into Maple using the regular operators:

Arithmetic expressions can be typed into Maple using the regular operators: Basic arithmetic Arithmetic expressions can be typed into Maple using the regular operators: (type "3 + 4" and then press "[Enter]" to start the evaluation of the expression) 7 (1.1) 5 (1.2) 21 (1.3) (type

More information

Tropical Implicitization

Tropical Implicitization Tropical Implicitization Jan Verschelde University of Illinois at Chicago Department of Mathematics Statistics and Computer Science http://www.math.uic.edu/ jan jan@math.uic.edu Graduate Computational

More information

Exact real arithmetic. Keith Briggs

Exact real arithmetic. Keith Briggs Exact real arithmetic Keith Briggs Keith.Briggs@bt.com more.btexact.com/people/briggsk2/xr.html 2002 Nov 20 15:00 Typeset in L A T E X2e on a linux system Exact real arithmetic p.1/35 Complexity Outline

More information

Ch.2: Loops and lists

Ch.2: Loops and lists Ch.2: Loops and lists Joakim Sundnes 1,2 Hans Petter Langtangen 1,2 Simula Research Laboratory 1 University of Oslo, Dept. of Informatics 2 Aug 29, 2018 Plan for 28 August Short quiz on topics from last

More information

>>> * *(25**0.16) *10*(25**0.16)

>>> * *(25**0.16) *10*(25**0.16) #An Interactive Session in the Python Shell. #When you type a statement in the Python Shell, #the statement is executed immediately. If the #the statement is an expression, its value is #displayed. #Lines

More information

operator overloading algorithmic differentiation the class DifferentialNumber operator overloading

operator overloading algorithmic differentiation the class DifferentialNumber operator overloading operator overloading 1 Computing with Differential Numbers algorithmic differentiation the class DifferentialNumber operator overloading 2 Computing with Double Doubles the class DoubleDouble defining

More information

Equations and Functions, Variables and Expressions

Equations and Functions, Variables and Expressions Equations and Functions, Variables and Expressions Equations and functions are ubiquitous components of mathematical language. Success in mathematics beyond basic arithmetic depends on having a solid working

More information

Automatically improving floating point code

Automatically improving floating point code Automatically improving floating point code Scientists Write Code Every scientist needs to write code Analyze data Simulate models Control experiments Scientists Write Code Every scientist needs to write

More information

Introductory Scientific Computing with Python

Introductory Scientific Computing with Python Introductory Scientific Computing with Python More plotting, lists and FOSSEE Department of Aerospace Engineering IIT Bombay SciPy India, 2015 December, 2015 FOSSEE (FOSSEE IITB) Interactive Plotting 1

More information

THE AUSTRALIAN NATIONAL UNIVERSITY Final Examination November COMP1730 / COMP6730 Programming for Scientists

THE AUSTRALIAN NATIONAL UNIVERSITY Final Examination November COMP1730 / COMP6730 Programming for Scientists THE AUSTRALIAN NATIONAL UNIVERSITY Final Examination November 2016 COMP1730 / COMP6730 Programming for Scientists Study Period: 15 minutes Time Allowed: 3 hours Permitted Materials: One A4 page (1 sheet)

More information

1 Maple Introduction. 1.1 Getting Started. 1.2 Maple Commands

1 Maple Introduction. 1.1 Getting Started. 1.2 Maple Commands 1 Maple Introduction 1.1 Getting Started The software package Maple is an example of a Computer Algebra System (CAS for short), meaning that it is capable of dealing with problems in symbolic form. This

More information

Excel Functions & Tables

Excel Functions & Tables Excel Functions & Tables Fall 2012 Fall 2012 CS130 - Excel Functions & Tables 1 Review of Functions Quick Mathematics Review As it turns out, some of the most important mathematics for this course revolves

More information

ü 1.1 Getting Started

ü 1.1 Getting Started Chapter 1 Introduction Welcome to Mathematica! This tutorial manual is intended as a supplement to Rogawski's Calculus textbook and aimed at students looking to quickly learn Mathematica through examples.

More information

Mathematical Experiments with Mathematica

Mathematical Experiments with Mathematica Mathematical Experiments with Mathematica Instructor: Valentina Kiritchenko Classes: F 12:00-1:20 pm E-mail : vkiritchenko@yahoo.ca, vkiritch@hse.ru Office hours : Th 5:00-6:20 pm, F 3:30-5:00 pm 1. Syllabus

More information

Long (LONGMATH) variables may be used the same as short variables. The syntax is the same. A few limitations apply (see below).

Long (LONGMATH) variables may be used the same as short variables. The syntax is the same. A few limitations apply (see below). Working with Long Numbers. Long Variables Constants You define a long variable with the LONG statement, which works similar to the DIM statement. You can define long variables and dimension long variable

More information

1 2 (3 + x 3) x 2 = 1 3 (3 + x 1 2x 3 ) 1. 3 ( 1 x 2) (3 + x(0) 3 ) = 1 2 (3 + 0) = 3. 2 (3 + x(0) 1 2x (0) ( ) = 1 ( 1 x(0) 2 ) = 1 3 ) = 1 3

1 2 (3 + x 3) x 2 = 1 3 (3 + x 1 2x 3 ) 1. 3 ( 1 x 2) (3 + x(0) 3 ) = 1 2 (3 + 0) = 3. 2 (3 + x(0) 1 2x (0) ( ) = 1 ( 1 x(0) 2 ) = 1 3 ) = 1 3 6 Iterative Solvers Lab Objective: Many real-world problems of the form Ax = b have tens of thousands of parameters Solving such systems with Gaussian elimination or matrix factorizations could require

More information

Introduction to Logic Programming. Ambrose

Introduction to Logic Programming. Ambrose Introduction to Logic Programming Ambrose Bonnaire-Sergeant @ambrosebs abonnairesergeant@gmail.com Introduction to Logic Programming Fundamental Logic Programming concepts Related to FP General implementation

More information

Introduction to numerical algorithms

Introduction to numerical algorithms Introduction to numerical algorithms Given an algebraic equation or formula, we may want to approximate the value, and while in calculus, we deal with equations or formulas that are well defined at each

More information

debugging, hexadecimals, tuples

debugging, hexadecimals, tuples debugging, hexadecimals, tuples Matt Valeriote 28 January 2019 Searching for/asking for help Searching for help Google (or your search engine of choice) be as specific as possible Asking for help reproducible/minimal

More information

John Perry. Spring 2016

John Perry. Spring 2016 MAT 305: Introduction to Sage University of Southern Mississippi Spring 2016 Outline 1 2 3 4 5 Outline 1 2 3 4 5 Sage? Software for Algebra and Geometry Exploration Computer Algebra System started by William

More information

Multiplying and Dividing Rational Expressions

Multiplying and Dividing Rational Expressions Multiplying and Dividing Rational Expressions Warm Up Simplify each expression. Assume all variables are nonzero. 1. x 5 x 2 3. x 6 x 2 x 7 Factor each expression. 2. y 3 y 3 y 6 x 4 4. y 2 1 y 5 y 3 5.

More information

Getting to Know Maple

Getting to Know Maple Maple Worksheets for rdinary Differential Equations Complimentary software to accompany the textbook: Differential Equations: Concepts, Methods, and Models (00-00 Edition) Leigh C. Becker Department of

More information

61A Lecture 6. Friday, September 7

61A Lecture 6. Friday, September 7 61A Lecture 6 Friday, September 7 Lambda Expressions >>> ten = 10 An expression: this one evaluates to a number >>> square = x * x Also an expression: evaluates to a function >>> square = lambda x: x *

More information

Algorithms and Programming I. Lecture#12 Spring 2015

Algorithms and Programming I. Lecture#12 Spring 2015 Algorithms and Programming I Lecture#12 Spring 2015 Think Python How to Think Like a Computer Scientist By :Allen Downey Installing Python Follow the instructions on installing Python and IDLE on your

More information

What advantages has it?

What advantages has it? by What advantages has it? The Reasons for Choosing Python Python is free It is object-oriented It is interpreted It is operating-system independent It has an excellent optimization module It offers modern

More information

Lists How lists are like strings

Lists How lists are like strings Lists How lists are like strings A Python list is a new type. Lists allow many of the same operations as strings. (See the table in Section 4.6 of the Python Standard Library Reference for operations supported

More information

PHY224 Practical Physics I. Lecture 2

PHY224 Practical Physics I. Lecture 2 PHY224 Practical Physics I Python Review Lecture 2 Sept. 19 20 20, 2013 Summary Functions and Modules Graphs (plotting with Pylab) Scipy packages References M H. Goldwasser, D. Letscher: Object oriented

More information

Long (or LONGMATH ) floating-point (or integer) variables (length up to 1 million, limited by machine memory, range: approx. ±10 1,000,000.

Long (or LONGMATH ) floating-point (or integer) variables (length up to 1 million, limited by machine memory, range: approx. ±10 1,000,000. QuickCalc User Guide. Number Representation, Assignment, and Conversion Variables Constants Usage Double (or DOUBLE ) floating-point variables (approx. 16 significant digits, range: approx. ±10 308 The

More information

MAT128A: Numerical Analysis Lecture Two: Finite Precision Arithmetic

MAT128A: Numerical Analysis Lecture Two: Finite Precision Arithmetic MAT128A: Numerical Analysis Lecture Two: Finite Precision Arithmetic September 28, 2018 Lecture 1 September 28, 2018 1 / 25 Floating point arithmetic Computers use finite strings of binary digits to represent

More information

Warm Up Simplify each expression. Assume all variables are nonzero.

Warm Up Simplify each expression. Assume all variables are nonzero. Warm Up Simplify each expression. Assume all variables are nonzero. 1. x 5 x 2 3. x 6 x 2 x 7 x 4 Factor each expression. 2. y 3 y 3 y 6 4. y 2 1 y 5 y 3 5. x 2 2x 8 (x 4)(x + 2) 6. x 2 5x x(x 5) 7. x

More information

4. Modules and Functions

4. Modules and Functions 4. Modules and Functions The Usual Idea of a Function Topics Modules Using import Using functions from math A first look at defining functions sqrt 9 3 A factory that has inputs and builds outputs. Why

More information

An introduction to scientific programming with. Session 2: Numerical Python and plotting

An introduction to scientific programming with. Session 2: Numerical Python and plotting An introduction to scientific programming with Session 2: Numerical Python and plotting So far core Python language and libraries Extra features required: fast, multidimensional arrays plotting tools libraries

More information

Functional Programming. Big Picture. Design of Programming Languages

Functional Programming. Big Picture. Design of Programming Languages Functional Programming Big Picture What we ve learned so far: Imperative Programming Languages Variables, binding, scoping, reference environment, etc What s next: Functional Programming Languages Semantics

More information

Exercises for a Numerical Methods Course

Exercises for a Numerical Methods Course Exercises for a Numerical Methods Course Brian Heinold Department of Mathematics and Computer Science Mount St. Mary s University November 18, 2017 1 / 73 About the class Mix of Math and CS students, mostly

More information

Part VI. Scientific Computing in Python. Alfredo Parra : Scripting with Python Compact Max-PlanckMarch 6-10,

Part VI. Scientific Computing in Python. Alfredo Parra : Scripting with Python Compact Max-PlanckMarch 6-10, Part VI Scientific Computing in Python Compact Course @ Max-PlanckMarch 6-10, 2017 63 Doing maths in Python Standard sequence types (list, tuple,... ) Can be used as arrays Can contain different types

More information

Defining Functions. turning expressions into functions. writing a function definition defining and using modules

Defining Functions. turning expressions into functions. writing a function definition defining and using modules Defining Functions 1 Lambda Functions turning expressions into functions 2 Functions and Modules writing a function definition defining and using modules 3 Computing Series Developments exploring an example

More information

Introduction to Engineering gii

Introduction to Engineering gii 25.108 Introduction to Engineering gii Dr. Jay Weitzen Lecture Notes I: Introduction to Matlab from Gilat Book MATLAB - Lecture # 1 Starting with MATLAB / Chapter 1 Topics Covered: 1. Introduction. 2.

More information

Logical and Function Constructions

Logical and Function Constructions Logical and Function Constructions K. 1 1 Department of Mathematics 2018 Boolean Values Many languages (including) Python use Boolean values: True/False. The invocation of Boole s name always carries an

More information

Principles of Programming Languages 2017W, Functional Programming

Principles of Programming Languages 2017W, Functional Programming Principles of Programming Languages 2017W, Functional Programming Assignment 3: Lisp Machine (16 points) Lisp is a language based on the lambda calculus with strict execution semantics and dynamic typing.

More information

Overview (4) CPE 101 mod/reusing slides from a UW course. Assignment Statement: Review. Why Study Expressions? D-1

Overview (4) CPE 101 mod/reusing slides from a UW course. Assignment Statement: Review. Why Study Expressions? D-1 CPE 101 mod/reusing slides from a UW course Overview (4) Lecture 4: Arithmetic Expressions Arithmetic expressions Integer and floating-point (double) types Unary and binary operators Precedence Associativity

More information

Combinatorics 3: Champions League draw

Combinatorics 3: Champions League draw Bachelor of Ecole Polytechnique Computational Mathematics, year 2, semester 1 Lecturer: Lucas Gerin (send mail) (mailto:lucas.gerin@polytechnique.edu) Combinatorics 3: Champions League draw Table of contents

More information

Numerical Integration

Numerical Integration Numerical Integration 1 Functions using Functions functions as arguments of other functions the one-line if-else statement functions returning multiple values 2 Constructing Integration Rules with sympy

More information

ERTH3021 Exploration and Mining Geophysics

ERTH3021 Exploration and Mining Geophysics ERTH3021 Exploration and Mining Geophysics Practical 1: Introduction to Scientific Programming using Python Purposes To introduce simple programming skills using the popular Python language. To provide

More information

Module 01: Introduction to Programming in Python

Module 01: Introduction to Programming in Python Module 01: Introduction to Programming in Python Topics: Course Introduction Introduction to Python basics Readings: ThinkP 1,2,3 1 Finding course information https://www.student.cs.uwaterloo.ca/~cs116/

More information

CSSE 120 Introduction to Software Development Practice for Test 1 paper-and-pencil part Page 1 of 6

CSSE 120 Introduction to Software Development Practice for Test 1 paper-and-pencil part Page 1 of 6 CSSE 120 Introduction to Software Development Practice for Test 1 paper-and-pencil part Page 1 of 6 Name: Use this quiz to help you prepare for the Paper-and-Pencil portion of Test 1. Complete it electronically

More information

Introduction to Programming

Introduction to Programming Introduction to Programming Department of Computer Science and Information Systems Tingting Han (afternoon), Steve Maybank (evening) tingting@dcs.bbk.ac.uk sjmaybank@dcs.bbk.ac.uk Autumn 2017 Week 4: More

More information

PHY224 Practical Physics I. Lecture 2

PHY224 Practical Physics I. Lecture 2 PHY224 Practical Physics I Python Review Lecture 2 Sept. 15 16 16, 2014 Summary Functions and Modules Graphs (plotting with Pylab) Scipy packages References M H. Goldwasser, D. Letscher: Object oriented

More information

Introduction to Computer Programming with MATLAB Calculation and Programming Errors. Selis Önel, PhD

Introduction to Computer Programming with MATLAB Calculation and Programming Errors. Selis Önel, PhD Introduction to Computer Programming with MATLAB Calculation and Programming Errors Selis Önel, PhD Today you will learn Numbers, Significant figures Error analysis Absolute error Relative error Chopping

More information

ERTH2020 Introduction to Geophysics

ERTH2020 Introduction to Geophysics ERTH2020 Practical:: Introduction to Python Page 1 ERTH2020 Introduction to Geophysics 2018 Practical 1: Introduction to scientific programming using Python, and revision of basic mathematics Purposes

More information

16.50 RANDPOLY: A random polynomial generator

16.50 RANDPOLY: A random polynomial generator 743 16.50 RANDPOLY: A random polynomial generator This package is based on a port of the Maple random polynomial generator together with some support facilities for the generation of random numbers and

More information

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s.

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s. Using Monte Carlo to Estimate π using Buffon s Needle Problem An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s. Here s the problem (in a simplified form). Suppose

More information

MS6021 Scientific Computing. TOPICS: Python BASICS, INTRO to PYTHON for Scientific Computing

MS6021 Scientific Computing. TOPICS: Python BASICS, INTRO to PYTHON for Scientific Computing MS6021 Scientific Computing TOPICS: Python BASICS, INTRO to PYTHON for Scientific Computing Preliminary Notes on Python (v MatLab + other languages) When you enter Spyder (available on installing Anaconda),

More information

John Perry. Spring 2017

John Perry. Spring 2017 MAT 305: Introduction to Sage University of Southern Mississippi Spring 2017 Outline 1 2 3 4 Outline 1 2 3 4 Sage? Software for Algebra and Geometry Exploration Computer Algebra System started by William

More information

differentiation techniques

differentiation techniques differentiation techniques 1 Callable Objects delayed execution of stored code 2 Numerical and Symbolic Differentiation numerical approximations for the derivative storing common code in a parent class

More information

Ph3 Mathematica Homework: Week 1

Ph3 Mathematica Homework: Week 1 Ph3 Mathematica Homework: Week 1 Eric D. Black California Institute of Technology v1.1 1 Obtaining, installing, and starting Mathematica Exercise 1: If you don t already have Mathematica, download it and

More information

Maple for Math Majors. 12. Data Structures in Maple

Maple for Math Majors. 12. Data Structures in Maple Maple for Math Majors Roger Kraft Department of Mathematics, Computer Science, and Statistics Purdue University Calumet roger@calumet.purdue.edu 12.1. Introduction 12. Data Structures in Maple We have

More information

CSE 251 PROJECT 1. Andrew Christlieb. Monday Class AND Friday Class Abstract. Web:

CSE 251 PROJECT 1. Andrew Christlieb. Monday Class AND Friday Class Abstract. Web: CSE 51 PROJECT 1 Andrew Christlieb Monday Class 0-03-14 AND Friday Class 01-31-14 Abstract Web: http://www.cse.msu.edu/ cse51 Project 1 due date: (Monday Class) 0-17-14 AND (Friday Class)0-14-14, time:

More information

CS1 Lecture 2 Jan. 16, 2019

CS1 Lecture 2 Jan. 16, 2019 CS1 Lecture 2 Jan. 16, 2019 Contacting me/tas by email You may send questions/comments to me/tas by email. For discussion section issues, sent to TA and me For homework or other issues send to me (your

More information

ARTIFICIAL INTELLIGENCE AND PYTHON

ARTIFICIAL INTELLIGENCE AND PYTHON ARTIFICIAL INTELLIGENCE AND PYTHON DAY 1 STANLEY LIANG, LASSONDE SCHOOL OF ENGINEERING, YORK UNIVERSITY WHAT IS PYTHON An interpreted high-level programming language for general-purpose programming. Python

More information

#To import the whole library under a different name, so you can type "diff_name.f unc_name" import numpy as np import matplotlib.

#To import the whole library under a different name, so you can type diff_name.f unc_name import numpy as np import matplotlib. In [1]: #Here I import the relevant function libraries #This can be done in many ways #To import an entire library (e.g. scipy) so that functions accessed by typing "l ib_name.func_name" import matplotlib

More information

CMSC 201 Computer Science I for Majors

CMSC 201 Computer Science I for Majors CMSC 201 Computer Science I for Majors Lecture 02 Intro to Python Syllabus Last Class We Covered Grading scheme Academic Integrity Policy (Collaboration Policy) Getting Help Office hours Programming Mindset

More information

Introduction to Classic Maple by David Maslanka

Introduction to Classic Maple by David Maslanka Introduction to Classic Maple by David Maslanka Maple is a computer algebra system designed to do mathematics. Symbolic, numerical and graphical computations can all be done with Maple. Maple's treatment

More information

Lecture 1 August 9, 2017

Lecture 1 August 9, 2017 Programming in Haskell S P Suresh http://www.cmi.ac.in/~spsuresh Lecture 1 August 9, 2017 Administrative Mondays and Wednesdays at 9.10 am at Lecture Hall 6 Evaluation: Quizzes, 4 5 programming assignments,

More information

CHAPTER 3: CORE PROGRAMMING ELEMENTS

CHAPTER 3: CORE PROGRAMMING ELEMENTS Variables CHAPTER 3: CORE PROGRAMMING ELEMENTS Introduction to Computer Science Using Ruby A variable is a single datum or an accumulation of data attached to a name The datum is (or data are) stored in

More information

1. Variables 2. Arithmetic 3. Input and output 4. Problem solving: first do it by hand 5. Strings 6. Chapter summary

1. Variables 2. Arithmetic 3. Input and output 4. Problem solving: first do it by hand 5. Strings 6. Chapter summary Topic 2 1. Variables 2. Arithmetic 3. Input and output 4. Problem solving: first do it by hand 5. Strings 6. Chapter summary Arithmetic Operators C++ has the same arithmetic operators as a calculator:

More information

Introduction. What is Maple? How to use this tutorial. Where can I find Maple?

Introduction. What is Maple? How to use this tutorial. Where can I find Maple? Introduction What is Maple? Maple is a computer program for people doing mathematics. Using Maple to do your calculations should make the work more interesting, allow you to focus more on the concepts,

More information

Lecture 07. (with solutions) Summer 2001 Victor Adamchik. 2 as an infinite product of nested square roots. M #'((((((((((((((((((((((((((((( 2 ] # N

Lecture 07. (with solutions) Summer 2001 Victor Adamchik. 2 as an infinite product of nested square roots. M #'((((((((((((((((((((((((((((( 2 ] # N Lecture 07 (with solutions) Summer 00 Victor Adamchik Off#General::spell'; Off#General::spell'; $Line 0; Exercise Vieta's formula, developed in 593, expresses cccc as an infinite product of nested square

More information

Computer Applications for Engineers ET 601

Computer Applications for Engineers ET 601 Computer Applications for Engineers ET 601 Asst. Prof. Dr. Prapun Suksompong prapun@siit.tu.ac.th Random Variables 1 Office Hours: (BKD 3601-7) Wednesday 9:30-11:30 Wednesday 16:00-17:00 Thursday 14:40-16:00

More information

C++ PROGRAMMING. For Industrial And Electrical Engineering Instructor: Ruba A. Salamh

C++ PROGRAMMING. For Industrial And Electrical Engineering Instructor: Ruba A. Salamh C++ PROGRAMMING For Industrial And Electrical Engineering Instructor: Ruba A. Salamh CHAPTER TWO: Fundamental Data Types Chapter Goals In this chapter, you will learn how to work with numbers and text,

More information

Symbols. Anscombe s quartet, antiderivative, 200. bar charts for exercise, for expenses, Barnsley fern, drawing,

Symbols. Anscombe s quartet, antiderivative, 200. bar charts for exercise, for expenses, Barnsley fern, drawing, Index Symbols + (addition operator), 2 {} (curly brackets), to define a set, 122 δ (delta), 184 / (division operator), 2 ε (epsilon), 192, 197 199 == (equality operator), 124 e (Euler s number), 179 **

More information

12 whereas if I terminate the expression with a semicolon, the printed output is suppressed.

12 whereas if I terminate the expression with a semicolon, the printed output is suppressed. Example 4 Printing and Plotting Matlab provides numerous print and plot options. This example illustrates the basics and provides enough detail that you can use it for typical classroom work and assignments.

More information

Introduction to: Computers & Programming Defining Identifiers: Objects with Names

Introduction to: Computers & Programming Defining Identifiers: Objects with Names Introduction to: Computers & Programming Defining Identifiers: Objects with Names Adam Meyers New York University Outline The types of objects with names Functions, Variables, Programs, Modules, etc. Defining

More information

Introduction to Python and programming. Ruth Anderson UW CSE 160 Winter 2017

Introduction to Python and programming. Ruth Anderson UW CSE 160 Winter 2017 Introduction to Python and programming Ruth Anderson UW CSE 160 Winter 2017 1 1. Python is a calculator 2. A variable is a container 3. Different types cannot be compared 4. A program is a recipe 2 0.

More information

Floating-Point Arithmetic

Floating-Point Arithmetic Floating-Point Arithmetic 1 Numerical Analysis a definition sources of error 2 Floating-Point Numbers floating-point representation of a real number machine precision 3 Floating-Point Arithmetic adding

More information

Unit 3. Operators. School of Science and Technology INTRODUCTION

Unit 3. Operators. School of Science and Technology INTRODUCTION INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.

More information

Variables. Substitution

Variables. Substitution Variables Elements of Programming Languages Lecture 4: Variables, binding and substitution James Cheney University of Edinburgh October 6, 2015 A variable is a symbol that can stand for another expression.

More information

Operators and Expressions:

Operators and Expressions: Operators and Expressions: Operators and expression using numeric and relational operators, mixed operands, type conversion, logical operators, bit operations, assignment operator, operator precedence

More information

MAT 003 Brian Killough s Instructor Notes Saint Leo University

MAT 003 Brian Killough s Instructor Notes Saint Leo University MAT 003 Brian Killough s Instructor Notes Saint Leo University Success in online courses requires self-motivation and discipline. It is anticipated that students will read the textbook and complete sample

More information

, has the form T i1i 2 i m. = κ i1i 2 i m. x i1. 1 xi2 2 xim m (2)

, has the form T i1i 2 i m. = κ i1i 2 i m. x i1. 1 xi2 2 xim m (2) CS61B, Fall 2002 Project #1 P. N. Hilfinger Due: Friday, 4 October 2002 at 2400 This first project involves writing a calculator program that can perform polynomial arithmetic. We ll do only a very limited

More information

9 abcd = dcba b + 90c = c + 10b b = 10c.

9 abcd = dcba b + 90c = c + 10b b = 10c. In this session, we ll learn how to solve problems related to place value. This is one of the fundamental concepts in arithmetic, something every elementary and middle school mathematics teacher should

More information

NumPy. Arno Proeme, ARCHER CSE Team Attributed to Jussi Enkovaara & Martti Louhivuori, CSC Helsinki

NumPy. Arno Proeme, ARCHER CSE Team Attributed to Jussi Enkovaara & Martti Louhivuori, CSC Helsinki NumPy Arno Proeme, ARCHER CSE Team aproeme@epcc.ed.ac.uk Attributed to Jussi Enkovaara & Martti Louhivuori, CSC Helsinki Reusing this material This work is licensed under a Creative Commons Attribution-

More information

Scientific Computing: Lecture 1

Scientific Computing: Lecture 1 Scientific Computing: Lecture 1 Introduction to course, syllabus, software Getting started Enthought Canopy, TextWrangler editor, python environment, ipython, unix shell Data structures in Python Integers,

More information

Calculus III. 1 Getting started - the basics

Calculus III. 1 Getting started - the basics Calculus III Spring 2011 Introduction to Maple The purpose of this document is to help you become familiar with some of the tools the Maple software package offers for visualizing curves and surfaces in

More information

Computational Physics

Computational Physics Computational Physics Objects : Lists & Arrays Prof. Paul Eugenio Department of Physics Florida State University Jan 24, 2019 http://hadron.physics.fsu.edu/~eugenio/comphy/ Announcements Read chapter 3

More information

Chapter 5 : Informatics Practices. Class XII ( As per CBSE Board) Numpy - Array. New Syllabus Visit : python.mykvs.in for regular updates

Chapter 5 : Informatics Practices. Class XII ( As per CBSE Board) Numpy - Array. New Syllabus Visit : python.mykvs.in for regular updates Chapter 5 : Informatics Practices Class XII ( As per CBSE Board) Numpy - Array New Syllabus 2019-20 NumPy stands for Numerical Python.It is the core library for scientific computing in Python. It consist

More information

John Perry. Fall 2013

John Perry. Fall 2013 MAT 305: University of Southern Mississippi Fall 2013 Outline 1 2 3 4 Outline 1 2 3 4 Download, install to your How to get latest version at www.sagemath.org Windows? need LiveCD or VirtualBox player:

More information

2.1.1 Fixed-Point (or Integer) Arithmetic

2.1.1 Fixed-Point (or Integer) Arithmetic x = approximation to true value x error = x x, relative error = x x. x 2.1.1 Fixed-Point (or Integer) Arithmetic A base 2 (base 10) fixed-point number has a fixed number of binary (decimal) places. 1.

More information