Home   Current Courses   Video/Audio Library     Course Archive   Papers Archive   Beyond the Box   CV   Service My Keeper Shelf   Cultural References in Class

Home page for Professor Haynes'

COSC 120 Computational Principles (MatLab)
WINTER 2014




Teaching assistant: Eddie Gurnee: egurnee @ emich . edu

Textbook: Chapman, MATLAB Programming with Applications for Engineers, ISBN: 0-495-66807-9, 2013 Cenage Learning.

1. Lecture notes
Date Topic InLab Computational Principles Reading
R 4/17 No new topic Advice for final: Chapter 1 - 6, do quizzes and first 9 exercises from each
T 4/15 Figure It Out Day
R 4/10 Elementary data structures (unsorted array, sorted array, queue, stack, binary search tree, hash table Nothing new for this weekend See Topic Next week: images
T 4/8 Extempore: What's your cipher?
mean, std, median
curve-fitting: polyfit
interpolation: polyval
See programming project # 4
T 4/1 Substitution cipher There are 26 letters in the Roman alphabet. Explore the possibility of a musical cipher using the blues scale in C ( C, D, D♯/E♭, F, F#/G♭, A, B♭). Since there are only 7 distinct notes, consider adding tones by adding another octave (gives 14 unique tones) and doubling lengths (28 unique sounds).
What does 'go dark' sound like?
Substitution and transposition ciphers
R 3/27 Just for fun: HTML, publishing to the web
Link to Eddie's page developed in class
==>> HERE <==
(See w3schools.com )
and people.emich.edu
  1. Make a home page (not graded)
    1. More messing about with sound next time
    2. Make Handel last twice the length by appending a copy of the vector to the original vector.
    3. Have the sound fade in (get louder) at the beginning of the audio and fade out (get softer at the end of the play.
    4. Go to HERE to help figure out how to create a short piece of music. The tones from ET are nice.
Read curve fitting, interpolation, etc (chapter 6)
T 3/25 switch versus if
    Continuing with user-defined functions
  • code development (what to put in a function, what to keep out)
  • pass-by-value
  • why use a function
  • recursive functions
Code developed in class HERE
  1. Write two versions of a function that will compute the sum of the first n natural numbers (1 + 2 + 3 + ... + n)
    The input argument is n
    One version will use a for loop.
    The second version will use recursion
  2. Game of Life? Grade Audit project?
pass-by-value, code development, recursion Chapter 6
R 3/20 Sound Inlab0320.txt
T 3/18 Code developed in class is HERE Whiteboard explanation of sorts: insertion, selection, merge sort, odd-even
Differing performances
R 3/3 Game of life
Code developed in class will be HERE
Finish game of life for 10 X 10
T 3/11
  1. nested loop
  2. user defined function
Code developed in class will be HERE
  • Write the code to find the sum of all elements in a 2D array
  • Write a user defined function to find the sum of all elements in a 2D array.
  • Write the code to find the minimum and maximum of elements in a 2D array. [min max]
  • Given a 4 X 4 array of integers, compute a new 4X4 array, where each element in the new array is the truncated average of its NSEW neighbors in the original array.
Demo to Eddie or Haynes
Nested loops, code reuse Nested loops and user defined functions
T 3/4
  1. for
  2. while
  3. break, continue
  4. nested loops
Code developed in class is HERE
  1. Write a for loop to find the maximum value in a list of numbers
    Convert your for loop to a while loop
  2. Write a for loop that will accept an input value.
    If the input value is >=0 output the value, else exit from the loop
    Convert your for loop to a while loop
  3. Write a while loop that will compute n! for a user-supplied value of n. This loop should go up: 1 * 2 * ... * n
    Rewrite the while loop to go down: n * (n-1) * (n-2) * ... * 1
  4. Rewrite either while loop to a for loop
Demo to Eddie or to Haynes, and *get feedback* on the elegance of your pieces of code.
Read the last part of Chapter 5 with more care
R 2/20
  1. All-Class work: Chapman's chapter 4: exercise 4.3 (p159), exercises 4.5, 4.6, 4.7, 4.8
  2. input load save
  3. Graphing demos from R2008a
Chapman: chapter 5
T 2/18
    Plotting (MatLab help: types of MATLAB plots)
  • 2D: plot, bar, area, feather, polar, scatter
  • 3d: plot3, mesh, surf, scatter3
    Example 3D plots (see Matlab help)
  • ("Viewing a penny"
  • ("contour plot")
  • ("earth's topography") (/Applications/MATLAB_R2008a/toolbox/matlab/demos)
  • Graphical approach to solving inequalities
Inlab0218.txt
T 2/11 Practice in class binary arithmetic Read Chapter 3
For next week, read over Chapter 4 ("branching")
R 2/6 *Hand generate* the generations 1, 2, 3 of [1 0 1; 0 1 0; 1 0 1] (the initial state is generation 0). Allow the grid to grow as needed.
Notice you need to have two copies of the grid: the current generation and the next generation
Check your results against the javascript implementation
Basics of cellular automata
T  2/4 Chapter2 See here and here. This has been turned into a homework. Due next class. compute x=1/2*a*t + v0*t + x0
    Development/debugging principles:
  • cannibalize from working code
  • comment and uncomment
  • solve the problem in pencil first!!!
  • Echo input
  • Code THEN DEBUG just a few statements at a time ("a few" means no more than 3)
Chapman: Chapter 3 (2D plots)
T 1/30 Combining if statement with looping
x = 1:20; x=linspace(1, 20);
Put code developed in class to Code0130
Basic flowcharts. See example
Write a script to compute the minimum value in a list of numbers ( [ 1 3 -2 0 5] ==> -2 )
Write a script to compute the sum of the numbers greater than zero in a list of numbers ( [ 1 3 -2 0 5] ==> 9 )
Flowcharts for documentation and code development Chapman: Chapter 2 (MatLab Basics)
T 1/21 if, elseif else
relational operators: == ~= > >= $lt; <=
logic operators: & (and); &&(shortcut and); | (or); ||(shortcut or); xor(exclusive or), ~(not)
See Code0121
A taxi charges $2.00 for the first mile (and any trip less than one mile), and $.75 for every mile or portion of a mile after that.
Write a script to compute the cost of a taxi ride given the miles travelled. Demonstrate on the following trips: 0.5 miles, 1.0 mile, 2.0 miles, 2.1 miles
You can ask for and/or offer help to colleagues in class.

look up floor and ceil to round down and round up.
  • Watch out for '=' versus '=='
  • Big difference in performance: && versus &, || versus |
  • Choice of initial value for a variable can have big consequences in subsequent code
  • intmin versus intmin(), pi versus pi() (they are the same thing!!)
  • Matlab lets you redefine functions (e.g. pi = 3)
  • Test non integer numbers against a range (NOT equality)
pp144 - 150, 160-164
R 1/16 for!
Give an m-file that will turn a list of numbers into a
list of -1, 0, 1, where -1 is put in place of negative number,
0 is put in place of 0, and 1 is put in place of positive number
e.g., [ -22 0 0 1.45 -3.5 22] ==> [-1 0 0 1 -1 1]
See ./Code/0116
See quiz 1/16 (link is below)
  • You should solve a problem by pencil before writing a program
  • If you notice repetition in your solution, try to use a loop in your code
Read for, if, vectors, variables
T 1/14 matrix
for !!
comparison ( if )
x = 1:n
We're writing for loops. See Code developed in class Read "Getting Started" in the Matlab environment, from start to Workspace Variables (this is mostly repetition of what you've seen)
R 1/9 Intro to Matlab environment (1)Write a script to calculate the mean of a list of four numbers
(2)Write an m-file to do the same
Read through this tutorial
what does not work on your version of Matlab?


2. Assignments

Assgn Due Spec
2/18 2/20 See #2 at Inlab0218.txt
2/4 2/6(Thurs) Inlab from 2/4. Turn in hardcopy of code. Demo.
1/30 2/4 (Tues) hw0130.txt
1/14 1/16 end of class Create an m-file (or cannibalize script6.m and script9.m) to create a vector z that will
contain the smaller of the corresponding elements in vector x and vector y.
Given vectors:
x = [ 1 2 3 4 5 ] , y = [ 10 11 -1 -1 -2 ]
Resulting z should be [ 1 2 -1 -1 -2 ]



3. Projects
Assigned Due Spec Other
4/8 4/17 Curve fitting and interpolation
3/13 3/243/27 Graduation audit
2/20 3/6 #4.11
1/21/2014 February 13 (R) pp1 - Numerical integration See the visualization Here


4. Quizzes and Tests

5. General (Syllabus, Calendar, etc.)

6. Resources


Last changed: