Defining Functions. turning expressions into functions. writing a function definition defining and using modules
|
|
- Shavonne Cole
- 5 years ago
- Views:
Transcription
1 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 with a script series for expressions in two variables MCS 507 Lecture 7 Mathematical, Statistical and Scientific Software Jan Verschelde, 12 September 2012 Scientific Software (MCS 507) Defining Functions 12 Sep / 26
2 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 with a script series for expressions in two variables Scientific Software (MCS 507) Defining Functions 12 Sep / 26
3 evaluating expressions Suppose we want to evaluate x 2 cos(y) + 4e z sin(x). >>> from math import cos, sin, exp >>> f = lambda x,y,z: x**2*cos(y) \ *exp(z)*sin(x) >>> f(1,2,3) >>> f(z=3,y=2,x=1) In f(z=3,y=2,x=1), we call f by its keyword arguments, linking the formal parameters x, y, z to the values 1, 2, 3. Scientific Software (MCS 507) Defining Functions 12 Sep / 26
4 evaluating strings Restarting the interactive Python session, making a function for x 2 cos(y) + 4e z sin(x), stored in a string: >>> e = x**2*cos(y) + 4*exp(z)*sin(x) >>> from math import cos, sin, exp >>> f = lambda x,y,z: eval(e) >>> f(1,2,3) >>> f(z=3,x=1,y=2) Scientific Software (MCS 507) Defining Functions 12 Sep / 26
5 symbolic substitution With the substitution of sympy, we can evaluate an expression in symbolically, e.g., to permute the variables (x, y, z) (z, y, x): >>> from sympy import * >>> x,y,z = var( x,y,z ) >>> e = x**2*cos(y) + 4*exp(z)*sin(x) >>> Subs(e,(x,y,z),(z,y,x)) Subs(_x**2*cos(_y) + 4*exp(_z)*sin(_x), \ (_x, _y, _z), (z, y, x)) >>> _.doit() z**2*cos(y) + 4*exp(x)*sin(z) Scientific Software (MCS 507) Defining Functions 12 Sep / 26
6 approximating functions With series we do symbolic-numeric computation: >>> from sympy import * >>> x = var( x ) >>> sin(x).series(x,x0=0,n=7) x - x**3/6 + x**5/120 + O(x**7) Using an iterator: >>> s = sin(x).series(x,n=none) >>> L = [s.next() for i in range(3)]; L [x, -x**3/6, x**5/120] We experience the O(x**7) when evaluating: >>> S = sum(l) >>> Subs(S,(x),(0.01)).doit() >>> Subs(sin(x),(x),(0.01)).doit() Scientific Software (MCS 507) Defining Functions 12 Sep / 26
7 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 with a script series for expressions in two variables Scientific Software (MCS 507) Defining Functions 12 Sep / 26
8 a function definition def f(x,y,z): """ Returns the value of the expression x**2*cos(y) + 4*exp(z)*sin(x) for numerical values of x, y, and z. """ from math import exp, cos, sin v = x**2*cos(y) + 4*exp(z)*sin(x) return v Scientific Software (MCS 507) Defining Functions 12 Sep / 26
9 function definitions A function header (e.g., def f(x,y,z):) consists of 1 The name of the function follows def. 2 Arguments of the function are between round brackets ( and ); separated by commas. Round brackets are needed even if no arguments. 3 The colon : follows ). The documentation string (between triple quotes) is optional, but is strongly recommended. The function body may have local variables, e.g., v. Values (e.g., v) are returned with return v. Scientific Software (MCS 507) Defining Functions 12 Sep / 26
10 testing a function If we store the function definition for f in the file ourfirstmodule.py, we can do >>> from ourfirstmodule import f >>> f(1,2,3) We import the function f into an interactive Python session. Scientific Software (MCS 507) Defining Functions 12 Sep / 26
11 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 with a script series for expressions in two variables Scientific Software (MCS 507) Defining Functions 12 Sep / 26
12 help(ourfirstmodule) Help on module ourfirstmodule: NAME ourfirstmodule - # L-7 MCS 507 Wed 12 Sep 2012 : ourfir FILE /Users/jan/Courses/MCS507/Lec07/ourfirstmodule.py FUNCTIONS f(x, y, z) Returns the value of the expression x**2*cos(y) + 4*exp(z)*sin(x) for numerical values of x, y, and z. main() Prompts the user for three values for the variables x, y, z and prints x**2*cos(y) + 4*exp(z)*sin(x). Scientific Software (MCS 507) Defining Functions 12 Sep / 26
13 the main function def main(): """ Prompts the user for three values for the variables x, y, z and prints x**2*cos(y) + 4*exp(z)*sin(x). """ print v = x**2*cos(y) + 4*exp(z)*sin(x) x = input( give x : ) y = input( give y : ) z = input( give z : ) v = f(x,y,z) print v =, v Scientific Software (MCS 507) Defining Functions 12 Sep / 26
14 running main() We can also import the function main(). In order to run main() as a program at the command prompt $ $ python ourfirstmodule.py the last line in ourfirstmodule.py is if name == " main ": main() Scientific Software (MCS 507) Defining Functions 12 Sep / 26
15 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 with a script series for expressions in two variables Scientific Software (MCS 507) Defining Functions 12 Sep / 26
16 example_series.py from sympy import sin, cos, exp from sympy.abc import x, y, z e = x**2*cos(y) + 4*exp(z)*sin(x) # developing e about x = 0, 4th order print e.series(x,x0=0,n=4) # using an iterator of the series tx = e.series(x,x0=0,n=none) Lx = [tx.next() for i in range(3)] print Lx =, Lx e3x = sum(lx) # observe there is no O() in e3x print sum(lx) =, e3x produces 4*x*exp(z) + x**2*cos(y) - 2*x**3*exp(z)/3 + O(x**4) Lx = [4*x*exp(z), x**2*cos(y), -2*x**3*exp(z)/3] sum(lx) = -2*x**3*exp(z)/3 + x**2*cos(y) + 4*x*exp(z) Scientific Software (MCS 507) Defining Functions 12 Sep / 26
17 the script continued Only the middle term of Lx contains a function in y: prints # developing e3x about y = 1 ty = Lx[1].series(y,n=None) Ly = [ty.next() for i in range(2)] print Ly =, Ly e2y = sum(ly) print e2y =, e2y Ly = [x**2, -x**2*y**2/2] e2y = -x**2*y**2/2 + x**2 Scientific Software (MCS 507) Defining Functions 12 Sep / 26
18 developing in z gives print e2y =, e2y # developing z about z = 0, 3rd order tz0 = Lx[0].series(z,n=None) tz2 = Lx[2].series(z,n=None) Lz0 = [tz0.next() for i in range(2)] print Lz0 =, Lz0 Lz2 = [tz2.next() for i in range(2)] print Lz2 =, Lz2 s = sum(lz0) + sum(ly) + sum(lz2) print s =, s Lz0 = [4*x, 4*x*z] Lz2 = [-2*x**3/3, -2*x**3*z/3] s = -2*x**3*z/3-2*x**3/3 - x**2*y**2/2 \ + x**2 + 4*x*z + 4*x Scientific Software (MCS 507) Defining Functions 12 Sep / 26
19 checking the series from sympy import Subs v = (0.01,1.01,0.01) ev = Subs(e,(x,y,z),v).doit() sv = Subs(s,(x,y,z),v).doit() print expression value =, ev print series value =, sv print difference =, abs(ev - sv) shows expression value = series value = difference = e-6 Scientific Software (MCS 507) Defining Functions 12 Sep / 26
20 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 with a script series for expressions in two variables Scientific Software (MCS 507) Defining Functions 12 Sep / 26
21 running define_series.py The series() of sympy does not seem to apply for functions of several variables... $ python define_series.py give an expression : sin(x)*cos(y) give pair of variables : x,y give pair of orders : 2,2 x**3*y**2/12 - x**3/6 - x*y**2/2 + x Scientific Software (MCS 507) Defining Functions 12 Sep / 26
22 the function main() def main(): """ Prompts user for an expression, a pair of variables and orders. """ e = raw_input( give an expression : ) v = raw_input( give pair of variables : ) o = input( give pair of orders : ) w = var(v) print bivariate_series(eval(e),w,o) if name ==" main ": main() Scientific Software (MCS 507) Defining Functions 12 Sep / 26
23 list comprehensions def bivariate_series(e,v,o): """ Returns a series of the expression e in the pair of variables in v of respective orders in the pair o. """ t1 = e.series(v[0],n=none) L1 = safe_expand(t1,o[0]) t2 = [a.series(v[1],n=none) for a in L1] L2 = [safe_expand(t,o[1]) for t in t2] return sum([sum(l) for L in L2]) Scientific Software (MCS 507) Defining Functions 12 Sep / 26
24 exception handling def safe_expand(t,o): """ Given an iterator, returns the list of terms up to the order o. Uses an exception handler to catch cases when there is no next term. """ L = [] for i in xrange(o): try: L.append(t.next()) except StopIteration: return L return L Scientific Software (MCS 507) Defining Functions 12 Sep / 26
25 Summary + Exercises We started chapter 3 of the text book. Exercises: 1 The function numpy.linspace(a,b,n) returns a list of n equally spaced points in [a,b]. Write your own function definition for linspace. You may assume that n is at least 2 and a < b. 2 Compute the length of a path in the plane given by a list of coordinates (as tuples), see Exercise Extend the script define_series.py so it works for expressions in three variables. Test your solution on the expression x 2 cos(y) + 4e x sin(x). Scientific Software (MCS 507) Defining Functions 12 Sep / 26
26 more exercises 4 The formula T(t) = T + (T(0) T )e kt models the temperature T in function of time t. For k > 0, T(t) declines and models how an object cools off. Define a Python function that takes as arguments T(0), T, k, t and that returns T(t). 5 Use Sage or sympy to make a series approximation for T(t) from the previous exercise. Make a Python function from the series. Take various orders and compare the values at t = 0.1. The second homework is due on Friday 21 September, at 10AM: solve exercises 1 and 3 of Lecture 4; exercises 4 and 5 of Lecture 5; exercises 1, 2 and 5 of Lecture 6; exercises 1, 2, and 4 of Lecture 7. Scientific Software (MCS 507) Defining Functions 12 Sep / 26
turning expressions into functions symbolic substitution, series, and lambdify
Defining Functions 1 Lambda Functions turning expressions into functions symbolic substitution, series, and lambdify 2 Functions and Modules writing a function definition defining and using modules where
More informationLists and Loops. defining lists lists as queues and stacks inserting and removing membership and ordering lists
Lists and Loops 1 Lists in Python defining lists lists as queues and stacks inserting and removing membership and ordering lists 2 Loops in Python for and while loops the composite trapezoidal rule MCS
More informationNumerical 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 informationLists and Loops. browse Python docs and interactive help
Lists and Loops 1 Help in Python browse Python docs and interactive help 2 Lists in Python defining lists lists as queues and stacks inserting and removing membership and ordering lists 3 Loops in Python
More informationcallback, iterators, and generators
callback, iterators, and generators 1 Adding a Callback Function a function for Newton s method a function of the user to process results 2 A Newton Iterator defining a counter class refactoring the Newton
More informationList Comprehensions and Simulations
List Comprehensions and Simulations 1 List Comprehensions examples in the Python shell zipping, filtering, and reducing 2 Monte Carlo Simulations testing the normal distribution the Mean Time Between Failures
More informationTuples and Nested Lists
stored in hash 1 2 stored in hash 3 and 4 MCS 507 Lecture 6 Mathematical, Statistical and Scientific Software Jan Verschelde, 2 September 2011 and stored in hash 1 2 stored in hash 3 4 stored in hash tuples
More informationdifferentiation 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 informationRoot Finding Methods. sympy and Sage. MCS 507 Lecture 13 Mathematical, Statistical and Scientific Software Jan Verschelde, 21 September 2011
wrap Root Finding Methods 1 2 wrap MCS 507 Lecture 13 Mathematical, Statistical and Scientific Software Jan Verschelde, 21 September 2011 Root Finding Methods 1 wrap 2 wrap wrap octave-3.4.0:1> p = [1,0,2,-1]
More informationMath 20A lecture 10 The Gradient Vector
Math 20A lecture 10 p. 1/12 Math 20A lecture 10 The Gradient Vector T.J. Barnet-Lamb tbl@brandeis.edu Brandeis University Math 20A lecture 10 p. 2/12 Announcements Homework five posted, due this Friday
More informationUser Interfaces. getting arguments of the command line a command line interface to store points fitting points with polyfit of numpy
User Interfaces 1 Command Line Interfaces getting arguments of the command line a command line interface to store points fitting points with polyfit of numpy 2 Encapsulation by Object Oriented Programming
More informationBranching and Enumeration
Branching and Enumeration 1 Booleans and Branching computing logical expressions computing truth tables with Sage if, else, and elif 2 Timing Python Code try-except costs more than if-else 3 Recursive
More informationUser Interfaces. MCS 507 Lecture 11 Mathematical, Statistical and Scientific Software Jan Verschelde, 16 September Command Line Interfaces
User 1 2 MCS 507 Lecture 11 Mathematical, Statistical and Scientific Software Jan Verschelde, 16 September 2011 User 1 2 command line interfaces Many programs run without dialogue with user, as $ executable
More informationWeb Clients and Crawlers
Web Clients and Crawlers 1 Web Clients alternatives to web browsers opening a web page and copying its content 2 Scanning Files looking for strings between double quotes parsing URLs for the server location
More informationMath 21a Tangent Lines and Planes Fall, What do we know about the gradient f? Tangent Lines to Curves in the Plane.
Math 21a Tangent Lines and Planes Fall, 2016 What do we know about the gradient f? Tangent Lines to Curves in the Plane. 1. For each of the following curves, find the tangent line to the curve at the point
More informationInteractive Computing
Interactive Computing 1 Input/Output and Complex Arithmetic interactive Python scripts complex arithmetic 2 Python Coding Style and pylint coding style static code checking with pylint 3 Programming with
More informationCh.3: Functions and branching
Ch.3: Functions and branching Ole Christian Lingjærde, Dept of Informatics, UiO September 4-8, 2017 Today s agenda A small quiz to test understanding of lists Live-programming of exercises 2.7, 2.14, 2.15
More informationlambda forms map(), reduce(), filter(), eval(), and apply() estimating π with list comprehensions
Outline 1 Guessing Secrets functions returning functions oracles and trapdoor functions 2 anonymous functions lambda forms map(), reduce(), filter(), eval(), and apply() estimating π with list comprehensions
More informationMS6021 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 informationCh.3: Functions and branching
Ch.3: Functions and branching Ole Christian Lingjærde, Dept of Informatics, UiO September 3-7, 2018 (PART 1) Today s agenda A small quiz to test understanding of lists Live-programming of exercises 2.7,
More informationoperator 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 informationOOP and Scripting in Python Advanced Features
OOP and Scripting in Python Advanced Features Giuliano Armano Emanuele Tamponi Advanced Features Structure of a Python Script More on Defining Functions Default Argument Values Keyword Arguments Arbitrary
More informationFloating-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 informationDownloaded from Chapter 2. Functions
Chapter 2 Functions After studying this lesson, students will be able to: Understand and apply the concept of module programming Write functions Identify and invoke appropriate predefined functions Create
More informationScientific Computing with MATLAB
Scientific Computing with MATLAB Dra. K.-Y. Daisy Fan Department of Computer Science Cornell University Ithaca, NY, USA UNAM IIM 2012 2 Focus on computing using MATLAB Computer Science Computational Science
More informationprocessing data with a database
processing data with a database 1 MySQL and MySQLdb MySQL: an open source database running MySQL for database creation MySQLdb: an interface to MySQL for Python 2 CTA Tables in MySQL files in GTFS feed
More informationPHYS 210: Introduction to Computational Physics Octave/MATLAB Exercises 1
PHYS 210: Introduction to Computational Physics Octave/MATLAB Exercises 1 1. Problems from Gilat, Ch. 1.10 Open a terminal window, change to directory /octave, and using your text editor, create the file
More informationInterval 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 informationPython in 10 (50) minutes
Python in 10 (50) minutes https://www.stavros.io/tutorials/python/ Python for Microcontrollers Getting started with MicroPython Donald Norris, McGrawHill (2017) Python is strongly typed (i.e. types are
More informationCS1 Lecture 3 Jan. 22, 2018
CS1 Lecture 3 Jan. 22, 2018 Office hours for me and for TAs have been posted, locations will change check class website regularly First homework available, due Mon., 9:00am. Discussion sections tomorrow
More informationMATH 2400, Analytic Geometry and Calculus 3
MATH 2400, Analytic Geometry and Calculus 3 List of important Definitions and Theorems 1 Foundations Definition 1. By a function f one understands a mathematical object consisting of (i) a set X, called
More informationIntroducing Python Modules
Introducing Python Modules Based on CBSE Curriculum Class -11 By- Neha Tyagi PGT CS KV 5 Jaipur II Shift Jaipur Region Neha Tyagi, PGT CS II Shift Jaipur Introduction A book is generally divided into chapters.
More informationCSC312 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 informationGrace days can not be used for this assignment
CS513 Spring 19 Prof. Ron Matlab Assignment #0 Prepared by Narfi Stefansson Due January 30, 2019 Grace days can not be used for this assignment The Matlab assignments are not intended to be complete tutorials,
More informationGradient and Directional Derivatives
Gradient and Directional Derivatives MATH 311, Calculus III J. Robert Buchanan Department of Mathematics Fall 2011 Background Given z = f (x, y) we understand that f : gives the rate of change of z in
More informationDiscussion 12 The MCE (solutions)
Discussion 12 The MCE (solutions) ;;;;METACIRCULAR EVALUATOR FROM CHAPTER 4 (SECTIONS 4.1.1-4.1.4) of ;;;; STRUCTURE AND INTERPRETATION OF COMPUTER PROGRAMS ;;;from section 4.1.4 -- must precede def of
More informationTriple Integrals. MATH 311, Calculus III. J. Robert Buchanan. Fall Department of Mathematics. J. Robert Buchanan Triple Integrals
Triple Integrals MATH 311, Calculus III J. Robert Buchanan Department of Mathematics Fall 211 Riemann Sum Approach Suppose we wish to integrate w f (x, y, z), a continuous function, on the box-shaped region
More informationLecture 4. while and for loops if else test Tuples Functions. Let us start Python Ssh (putty) to UNIX/Linux computer puccini.che.pitt.
Lecture 4 while and for loops if else test Tuples Functions Let us start Python Ssh (putty) to UNIX/Linux computer puccini.che.pitt.edu Launching Python > python Quick Reminder: while Loop Example >>>
More information61A 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 informationMATLAB Lecture 4. Programming in MATLAB
MATLAB Lecture 4. Programming in MATLAB In this lecture we will see how to write scripts and functions. Scripts are sequences of MATLAB statements stored in a file. Using conditional statements (if-then-else)
More informationWeb Interfaces. the web server Apache processing forms with Python scripts Python code to write HTML
Web Interfaces 1 Python Scripts in Browsers the web server Apache processing forms with Python scripts Python code to write HTML 2 Web Interfaces for the Determinant dynamic interactive forms passing data
More informationSymbolic 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 informationIntroduction 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 informationOutline. tallying the votes global and local variables call by value or call by reference. of variable length using keywords for optional arguments
Outline 1 Histograms tallying the votes global and local variables call by value or call by reference 2 Arguments of Functions of variable length using keywords for optional arguments 3 Functions using
More informationCS1 Lecture 3 Jan. 18, 2019
CS1 Lecture 3 Jan. 18, 2019 Office hours for Prof. Cremer and for TAs have been posted. Locations will change check class website regularly First homework assignment will be available Monday evening, due
More informationHigh Level Parallel Processing
High Level Parallel Processing 1 GPU computing with Maple enabling CUDA in Maple 15 stochastic processes and Markov chains 2 Multiprocessing in Python scripting in computational science the multiprocessing
More informationPYTHON. Varun Jain & Senior Software Engineer. Pratap, Mysore Narasimha Raju & TEST AUTOMATION ARCHITECT. CenturyLink Technologies India PVT LTD
PYTHON Varun Jain & Senior Software Engineer Pratap, Mysore Narasimha Raju & TEST AUTOMATION ARCHITECT CenturyLink Technologies India PVT LTD 1 About Python Python is a general-purpose interpreted, interactive,
More informationUpdated: March 31, 2016 Calculus III Section Math 232. Calculus III. Brian Veitch Fall 2015 Northern Illinois University
Updated: March 3, 26 Calculus III Section 5.6 Math 232 Calculus III Brian Veitch Fall 25 Northern Illinois University 5.6 Triple Integrals In order to build up to a triple integral let s start back at
More information2. Modules, Scripts, and I/O. Quick Note on print. The Windchill Calculation. Script Mode. Motivating Script Mode 1/22/2016
2. Modules, Scripts, and I/O Topics: Script Mode Modules The print and input statements Formatting First look at importing stuff from other modules The Windchill Calculation Let s compute the windchill
More information2. Modules, Scripts, and I/O
2. Modules, Scripts, and I/O Topics: Script Mode Modules The print and input statements Formatting First look at importing stuff from other modules The Windchill Calculation Let s compute the windchill
More informationME 121 MATLAB Lesson 01 Introduction to MATLAB
1 ME 121 MATLAB Lesson 01 Introduction to MATLAB Learning Objectives Be able run MATLAB in the MCECS computer labs Be able to perform simple interactive calculations Be able to open and view an m-file
More informationMATLAB TUTORIAL WORKSHEET
MATLAB TUTORIAL WORKSHEET What is MATLAB? Software package used for computation High-level programming language with easy to use interactive environment Access MATLAB at Tufts here: https://it.tufts.edu/sw-matlabstudent
More informationArbitrary Precision and Symbolic Calculations
Arbitrary Precision and Symbolic Calculations K. 1 1 Department of Mathematics 2018 Sympy There are several packages for Python that do symbolic mathematics. The most prominent of these seems to be Sympy.
More informationProblem 1 (a): List Operations
Problem 1 (a): List Operations Task 1: Create a list, L1 = [1, 2, 3,.. N] Suppose we want the list to have the elements 1, 2, 10 range(n) creates the list from 0 to N-1 But we want the list to start from
More informationSignals and Systems Profs. Byron Yu and Pulkit Grover Fall Homework 1
18-290 Signals and Systems Profs. Byron Yu and Pulkit Grover Fall 2018 Homework 1 This homework is due in class on Thursday, September 6, 9:00am. Instructions Solve all non-matlab problems using only paper
More informationS206E Lecture 19, 5/24/2016, Python an overview
S206E057 Spring 2016 Copyright 2016, Chiu-Shui Chan. All Rights Reserved. Global and local variables: differences between the two Global variable is usually declared at the start of the program, their
More informationPHCpack, phcpy, and Sphinx
PHCpack, phcpy, and Sphinx 1 the software PHCpack a package for Polynomial Homotopy Continuation polyhedral homotopies the Python interface phcpy 2 Documenting Software with Sphinx Sphinx generates documentation
More informationWorking with Lists 4
CS 61A Lecture 10 Announcements Lists ['Demo'] Working with Lists 4 Working with Lists >>> digits = [1, 8, 2, 8] 4 Working with Lists >>> digits = [1, 8, 2, 8] >>> digits = [2//2, 2+2+2+2, 2, 2*2*2] 4
More informationAppendix H: Introduction to Maple
Appendix H: Introduction to Maple Maple is an application that can be used to analytically solve algebraic and differential equations. The capability to differentiate, integrate and algebraically manipulate
More informationFind the specific function values. Complete parts (a) through (d) below. f (x,y,z) = x y y 2 + z = (Simplify your answer.) ID: 14.1.
. Find the specific function values. Complete parts (a) through (d) below. f (x,y,z) = x y y 2 + z 2 (a) f(2, 4,5) = (b) f 2,, 3 9 = (c) f 0,,0 2 (d) f(4,4,00) = = ID: 4..3 2. Given the function f(x,y)
More informationAutomating the Tedious Stuff (Functional programming and other Mathematica magic)
/22 Automating the Tedious Stuff (Functional programming and other Mathematica magic) Connor Glosser Michigan State University Departments of Physics & Electrical/Computer Engineering π, 2014 /22 Table
More informationPython Programming Exercises 1
Python Programming Exercises 1 Notes: throughout these exercises >>> preceeds code that should be typed directly into the Python interpreter. To get the most out of these exercises, don t just follow them
More informationOutline. general information policies for the final exam
Outline 1 final exam on Tuesday 5 May 2015, at 8AM, in BSB 337 general information policies for the final exam 2 some example questions strings, lists, dictionaries scope of variables in functions working
More informationTest #2 October 8, 2015
CPSC 1040 Name: Test #2 October 8, 2015 Closed notes, closed laptop, calculators OK. Please use a pencil. 100 points, 5 point bonus. Maximum score 105. Weight of each section in parentheses. If you need
More informationCourse Outline - COMP150. Lectures and Labs
Course Outline - COMP150 Lectures and Labs 1 The way of the program 1.1 The Python programming language 1.2 What is a program? 1.3 What is debugging? 1.4 Experimental debugging 1.5 Formal and natural languages
More informationMATH 261 EXAM I PRACTICE PROBLEMS
MATH 261 EXAM I PRACTICE PROBLEMS These practice problems are pulled from actual midterms in previous semesters. Exam 1 typically has 6 problems on it, with no more than one problem of any given type (e.g.,
More informationTesting Software with Pexpect
Testing Software with Pexpect 1 Testing Computer Algebra Systems testing software preparing the test suite replacing print with assert statements 2 Automating Tests with Pexpect testing SymPy in Sage with
More informationMath Triple Integrals in Cylindrical Coordinates
Math 213 - Triple Integrals in Cylindrical Coordinates Peter A. Perry University of Kentucky November 2, 218 Homework Re-read section 15.7 Work on section 15.7, problems 1-13 (odd), 17-21 (odd) from Stewart
More informationCS 314 Principles of Programming Languages. Lecture 16
CS 314 Principles of Programming Languages Lecture 16 Zheng Zhang Department of Computer Science Rutgers University Friday 28 th October, 2016 Zheng Zhang 1 CS@Rutgers University Class Information Reminder:
More informationSymbolic Reasoning. Dr. Neil T. Dantam. Spring CSCI-561, Colorado School of Mines. Dantam (Mines CSCI-561) Symbolic Reasoning Spring / 86
Symbolic Reasoning Dr. Neil T. Dantam CSCI-561, Colorado School of Mines Spring 2019 Dantam (Mines CSCI-561) Symbolic Reasoning Spring 2019 1 / 86 Introduction Definition: Symbolic Reasoning Inference
More informationOutline. the try-except statement the try-finally statement. exceptions are classes raising exceptions defining exceptions
Outline 1 Exception Handling the try-except statement the try-finally statement 2 Python s Exception Hierarchy exceptions are classes raising exceptions defining exceptions 3 Anytime Algorithms estimating
More informationLecture #15: Generic Functions and Expressivity. Last modified: Wed Mar 1 15:51: CS61A: Lecture #16 1
Lecture #15: Generic Functions and Expressivity Last modified: Wed Mar 1 15:51:48 2017 CS61A: Lecture #16 1 Consider the function find: Generic Programming def find(l, x, k): """Return the index in L of
More informationBasic Syntax - First Program 1
Python Basic Syntax Basic Syntax - First Program 1 All python files will have extension.py put the following source code in a test.py file. print "Hello, Python!";#hello world program run this program
More informationCSC236 Week 5. Larry Zhang
CSC236 Week 5 Larry Zhang 1 Logistics Test 1 after lecture Location : IB110 (Last names A-S), IB 150 (Last names T-Z) Length of test: 50 minutes If you do really well... 2 Recap We learned two types of
More informationDocumentation for LISP in BASIC
Documentation for LISP in BASIC The software and the documentation are both Copyright 2008 Arthur Nunes-Harwitt LISP in BASIC is a LISP interpreter for a Scheme-like dialect of LISP, which happens to have
More informationUnit testing with pytest and nose 1
Unit testing with pytest and nose 1 Hans Petter Langtangen 1,2 1 Center for Biomedical Computing, Simula Research Laboratory 2 Department of Informatics, University of Oslo Mar 23, 2015 Contents 1 Requirements
More informationENCM 339 Fall 2017 Lecture Section 01 Lab 9 for the Week of November 20
page 1 of 9 ENCM 339 Fall 2017 Lecture Section 01 Lab 9 for the Week of November 20 Steve Norman Department of Electrical & Computer Engineering University of Calgary November 2017 Lab instructions and
More informationIntroduction to Python, Cplex and Gurobi
Introduction to Python, Cplex and Gurobi Introduction Python is a widely used, high level programming language designed by Guido van Rossum and released on 1991. Two stable releases: Python 2.7 Python
More informationFunctional Programming Languages (FPL)
Functional Programming Languages (FPL) 1. Definitions... 2 2. Applications... 2 3. Examples... 3 4. FPL Characteristics:... 3 5. Lambda calculus (LC)... 4 6. Functions in FPLs... 7 7. Modern functional
More information1.5 Equations of Lines and Planes in 3-D
1.5. EQUATIONS OF LINES AND PLANES IN 3-D 55 Figure 1.16: Line through P 0 parallel to v 1.5 Equations of Lines and Planes in 3-D Recall that given a point P = (a, b, c), one can draw a vector from the
More informationLecture 4: Complex Numbers Functions, and Data Input
Lecture 4: Complex Numbers Functions, and Data Input Dr. Mohammed Hawa Electrical Engineering Department University of Jordan EE201: Computer Applications. See Textbook Chapter 3. What is a Function? A
More informationUser-Defined Function
ENGR 102-213 (Socolofsky) Week 11 Python scripts In the lecture this week, we are continuing to learn powerful things that can be done with userdefined functions. In several of the examples, we consider
More informationMATH 2650/ Intro to Scientific Computation - Fall Lab 1: Starting with MATLAB. Script Files
MATH 2650/3670 - Intro to Scientific Computation - Fall 2017 Lab 1: Starting with MATLAB. Script Files Content - Overview of Course Objectives - Use of MATLAB windows; the Command Window - Arithmetic operations
More information3. The domain of a function of 2 or 3 variables is a set of pts in the plane or space respectively.
Math 2204 Multivariable Calculus Chapter 14: Partial Derivatives Sec. 14.1: Functions of Several Variables I. Functions and Variables A. Def n : Suppose D is a set of n-tuples of real numbers (x 1, x 2,
More informationChapter 2 Writing Simple Programs
Chapter 2 Writing Simple Programs Charles Severance Textbook: Python Programming: An Introduction to Computer Science, John Zelle (www.si182.com) Software Development Process Figure out the problem - for
More informationExam 2 Preparation Math 2080 (Spring 2011) Exam 2: Thursday, May 12.
Multivariable Calculus Exam 2 Preparation Math 28 (Spring 2) Exam 2: Thursday, May 2. Friday May, is a day off! Instructions: () There are points on the exam and an extra credit problem worth an additional
More informationOUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.
1 LECTURE 3 OUTLINES Variable names in MATLAB Examples Matrices, Vectors and Scalar Scalar Vectors Entering a vector Colon operator ( : ) Mathematical operations on vectors examples 2 VARIABLE NAMES IN
More informationLesson 4: Numerical Computations; Newton's method
Lesson 4: Numerical Computations; Newton's method restart; Catastrophic cancellation in the quadratic formula One case where roundoff error can be severe is if you subtract two numbers that are very close
More informationWorksheet 6: Basic Methods Methods The Format Method Formatting Floats Formatting Different Types Formatting Keywords
Worksheet 1: Introductory Exercises Turtle Programming Calculations The Print Function Comments Syntax Semantics Strings Concatenation Quotation Marks Types Variables Restrictions on Variable Names Long
More informationLessons on Python Functions
Lessons on Python Functions Walter Didimo [ 90 minutes ] Functions When you write a program, you may need to recall a certain block of instructions several times throughout your code A function is a block
More informationEE3TP4: Signals and Systems Lab 1: Introduction to Matlab Tim Davidson Ext Objective. Report. Introduction to Matlab
EE3TP4: Signals and Systems Lab 1: Introduction to Matlab Tim Davidson Ext. 27352 davidson@mcmaster.ca Objective To help you familiarize yourselves with Matlab as a computation and visualization tool in
More informationA Brief Introduction to Mathematica
A Brief Introduction to Mathematica Objectives: (1) To learn to use Mathematica as a calculator. (2) To learn to write expressions in Mathematica, and to evaluate them at given point. (3) To learn to plot
More informationIntroduction 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 informationScientific Computing: Lecture 3
Scientific Computing: Lecture 3 Functions Random Numbers More I/O Practice Exercises CLASS NOTES Ò You should be finishing Chap. 2 this week. Ò HW00 due by midnight Friday into the Box folder Ò You should
More informationChapter 1. Fundamentals of Higher Order Programming
Chapter 1 Fundamentals of Higher Order Programming 1 The Elements of Programming Any powerful language features: so does Scheme primitive data procedures combinations abstraction We will see that Scheme
More informationMARK BOX problem points 1 a c a e bonus 4 Total 100 5/2/98 NAME:
MARK BOX problem points 1 a c 16 2 a e 16 3 16 4 a e 16 5 16 6 16 bonus 4 Total 100 Math 550A Spring 98 5/2/98 NAME: Prof. Girardi Final Exam INSTRUCTIONS: 1. To receive credit you must: a. work in a logical
More informationf x = 2e xy +y(2x+y)e xy = (2+2xy+y 2 )e xy.
gri (rg38778) Homework 11 gri (11111) 1 This print-out should have 3 questions. Multiple-choice questions may continue on the next column or page find all choices before answering. Find lim (x,y) (,) 1
More informationContents. MATH 32B-2 (18W) (L) G. Liu / (TA) A. Zhou Calculus of Several Variables. 1 Homework 1 - Solutions 3. 2 Homework 2 - Solutions 13
MATH 32B-2 (8) (L) G. Liu / (TA) A. Zhou Calculus of Several Variables Contents Homework - Solutions 3 2 Homework 2 - Solutions 3 3 Homework 3 - Solutions 9 MATH 32B-2 (8) (L) G. Liu / (TA) A. Zhou Calculus
More informationAnnouncements for this Lecture
Lecture 6 Objects Announcements for this Lecture Last Call Quiz: About the Course Take it by tomorrow Also remember survey Assignment 1 Assignment 1 is live Posted on web page Due Thur, Sep. 18 th Due
More information1 A Section A BRIEF TOUR. 1.1 Subsection Subsection 2
A BRIEF TOUR Maple V is a complete mathematical problem-solving environment that supports a wide variety of mathematical operations such as numerical analysis, symbolic algebra, and graphics. This worksheet
More information