Home    Course Archive    Video/Audio Library     Papers Archive    CV    My Keeper Shelf    Cultural References in Class Quotes

smh: COSC 120 Computational Principles for Mathematics and the Sciences
WINTER 2017


0. Basics
  1. Required Textbook:
    Shapiro, Scientific Computation: Python Hacking for Math Junkies, Sherwood Forest Books, January 2015, 978-0692366936.

  2. Good tutorial: https://www.tutorialspoint.com/python/index.htm

  3. Syllabus

  4. Coding Standards (Keep it clean. Keep it readable. Keep it honest. Keep it simple.)
    Points will be subtracted for bad readability (use of white space, choice of variable names) as well as for lack of functionality and poor design.

  5. Office Hours: M W 1:00 - 3:30pm
    See instructor home page



1. Homework
Distributed Due Identifier /
Link
Precis
4/11 4/13 Implement the dragon curve
You may find it easiest to cannibalize the sierpinski code
3/30 4/4 (Tues) Practical loops -- Homework 3/30 (1) how a for loop and a while loop are similar things,
(2)three "practical problems" using loops and lists
3/28 3/28 (in class) InClass 03/28 Do Exercises 1, 2 from Chapter 11 (map function)
3/23 3/23 InClass 03/23 See Lecture on 3/23 (operator precedence, associativity ... mostly)
3/9 3/13
via email!
Supply appropriate page numbers for the exam topics. Spreadsheet
Exam question will be drawn from those pages
Group work is allowed -- each person submits a spreadsheet.
Exam study
3/7 3/16 Simple sort Sort
2/28 3/7 Guessing game User guesses roll of two dice
2/14 3/7 Homework 2/14 Estimate area under curve using (1) Reimann sum and (2) Monte Carlo method
2/9 2/14 Homework 2/9 Built the format string for plots using string concatenate
2/2 2/9 2/14 Homework 2/2 Python scripts for three distinct models.
1/31 2/2 make a plot of 10 cos( 3t + 5) for 3 periods. Use red dashed line, and mark the points with '+'.
You need at least 45 points
(You have to import the module where the cos function is defined)
1/26 1/30 HW 01/26 swap a pair of tuples
1/234 1/26 Implement Babylonian algorithm, execute the loop 10 times
1/17 1/19 Complete the "in class lab" of 1/17
-- Turn in a printout of various0.py with fixed names and documentation describing what each function does, and
a printout of the de-scrambled scrambledUp.py
-- Demo the functions to Bojin or Haynes
Improving code
1/12 1/17 Homework 1/12 Assorted simple coding problems
1/5 1/10 babylonian algorithm, Chpt 2, pp 17 - 19.
Do a modification of p 20, Exercise 1. Estimate 201/2 to 3 significant digits. Compare with correct answer. How many iterations were needed? How many additional digits do you get on each iteration.
Use calculator or spreadsheet or any programming language.



2. Lectures

q
Date Topic Reading Notes
4/13 Reading and writing to a file: See Ullman page 160:
   ds = np.loadtxt("file.txt", delimiter=",")
   np.savetxt("newfile.txt", ds)
   save figure to png file: plt.savefig("filename.png") simple numpy array operation

In class, read this csv data in: HIV data , then plot it
See HERE
4/11 Stepped through Chpt 41 code for (1)Weierstrass function, (2) Sierpinski triangle, (3) Koch curve
Paying special attention to use of map and unpacking arguments with *
Chpt 41
    In lab review (no demo needed):
  1. Enter Sierpinski code -- fix all your typos
  2. Run with various inputs
  3. Run with various inputs after commenting out two of three recursive calls
Review map(), zip() and unpacking arguments in book
4/6 Lists (slicing, indexing, mutable), Tuples (not mutable), Strings (using %d and %f),
numpy arrays. Recursion, review of map function, zip function, introduction to lambda function
Chpt 14, 15 (Lists, tuples). Chpt 16 (Strings) . Chpt 22 (numpy). Chpt 26(recursion): Example. Enter code for Weierstrass function and for Koch curve (Chpt 41 Fractals). Get the code to work properly
4/4 Shapiro: chapter 13 (while loop), chapter 19 (for loop)
3/28 Identifiers, Simple statement Shapiro: chapter 10 (identifiers), 11 (simple statements, 12 (conditionals)
3/23 "Engineering notation" (not in book), Fundamentals of Big-Oh (Shapiro: chpt 9), Operators, identifiers, precedence (Shapiro: chpt 10) Shapiro: 8, 9, 10 Do today: Choose any five problems from Shapiro, Chpt 10, Exercise 1: a - o.
Answer by hand, then run Python. Turn in to Bojin
3/21 "Numbers in Computers" Shapiro: chpt 7, 8
3/14 MIDTERM
3/9 Prep for Exam -- see homework
3/7 Nest loop, beginning sort Do today: exercise slicing:
Using strings: HERE
Using list of numbers: HERE
Another write-up: HERE
3/2 More plotting functions:
Example: HERE
Modifed in class: HERE
Another simple I/O example: HERE
Shapiro, chapter 23
2/28 Random numbers, histograms, probability distributions Shapiro: 31.1
2/16 Laboratory Exercises
2/14 (1) Python script to demonstrate roll of die
(2) Estimate area under curve (the integral) using rectangles
(3) Estimate area under curve (the integral) using Monte Carlo method
2/9 Sample code: 1.py x(t+1) = x(t) + 1/(t^2)
points on a circle
building a format string using concatenate
2/7 Sample code: s1.py models harmonic series
s2.py models series using mod 3
2/2 Sample code: oscillation.py
exponential_growth.py
1/31 build a list, basic plotting
  import matplotlib.pyplot as plt
  plt.plot(x, y)
  plt.show()
  
1/26 Tuples, slicing
1/24 Review of flowcharting -- actual work-thru of examples
Draw flowcharts for various0.py functions
f0
f05
f1
f2
f4 -- fix f4!
f5
f7
See draw.io for a flowchart drawing program
1/17 Working with ONE partner at a time, each person turns in his own copy of the solutions:
  • Using a mixture of reading the code and trying it out, figure out what each function does AND change names to improve readability: various0.py
  • Using a mixture of reading the code and trying it out, unscramble each scrambled up function: scrambledUp.py. Note for function truesAndFalses, only the middle 4 lines have been scrambled
1/17 STOP!! No class today. water over ice!
1/12 Chapter 2 A Byte of Python tutorial
Read ahead Chapter 20
1/10 Assignments. Using functions. Flowcharting, Babylonian Algorithm Shapiro: chpt 2 - 4 In class: Write a Python function, input a, b, c (of quadratic eqn), return first answer.
Write second Python function, input a, b, c (of quadratic eqn), return second answer Write third Python function, input a, b, c (of quadratic eqn), return both answers
1/5 Course Orientation, Python environment Shapiro, Chpt 4 In class: Write a Python script with 3 functions: (1) square the parameter, (2) cube the parameter (3) dealer's choice





Resources

Last changed: