CS1371 Teaching Outlines
Summary
Homework 1 due week 1: Getting Started
Homework 2 due week 2: Basic Vectors
Homework 3 due week 3: Conditionals, Iteration and Vector
Operations
Homework 4 due week 4: Functions and Cell Arrays
Week 5: Test 1
Homework 5 due week 6: Structures, Arrays
Homework 6 due week 7: File I/O and recursion
Homework 7 due week 8: Plotting
Homework 8 due week 9: Advanced Plotting
Week 10: Test 2
Week 11: Spring Break
Homework 9 due week 12: Matrices, Images
Homework 10 due week 13: Numerical Methods
Homework 11 due week 14: Advanced Numerical Methods,
Sorting
Week 15: Test 3
Philosophy
Philosophical Notes:
- with a text book containing all the students should
know, we are free to explain the difficult parts of a chapter, but expect
the students to dig around for the rest of it.
- Having said that, many of the chapters push just a bit
further than the students really need to go, thereby challenging the top
flight students. We might have to make clear which parts are "beyond
the pale."
Lecture 1
Objective: Introduce Matlab (Ch 1 & 2)
Introductions
- Show of hands by major
- Show of hands by class year
- Introduce yourself
Course Overview
- Slide presentation
- Open class Web site
- Point them to Syllabus page
Concept: variables and assignment
- Difference between algebraic = and assignment.
- Encourage useful variable names
Lecture 2
Objective: Scripts (Ch 3)
Problem Solving
- Discuss Space Ship One (or some other problem type)
- X prize
- Carried to 50,000 ft on mother ship
- Rocket motor gives vertical velocity V
- Outer space defined as above 100 km altitude
- How would you calculate the required velocity? (v2
= u2 + 2 a s)
- $15,000 for ride into outer space
- If you had some velocity V1 (> V), how
long would you get in outer space for your money? (s = u t + 1/2 a t2
) -> quadratic equation
Matlab Introduction
- Enter some stuff into the Matlab Command Window.
- Show the variables appearing in the Workspace.
- Do the velocity problem
- 1 km = 3281 ft
- g = -9.81 m/sec2
Writing a Script
- Talk about the Current Directory (I usually work from
my Acme account)
- Open the empty script provided in the Matlab editor
- Demonstrate do-a-bit / test-a-bit strategy using the
Debug/Save and Run menu item (F5) with the velocity and time above 100 km
problems
- Solve the quadratic equation in the script explicitly
as shown in the finished solution
Lecture 3
Objective: How to do and turn in homework
Introduction to T-Square
- Show the links to T-Square
- Have a student volunteer:
- go through the registration process
- submit your script as his/her HW1
- retrieve and verify the HW1
Homework Mechanics
Walk through the following steps for doing Homework 1.
- Discuss file storage and a working directory:
- On your own computer, store files in the default
Matlab working directory Matlabr7/work.
- On a campus computer, either use the Y drive that
should be mapped to your gt account, or a floppy disk, or a memory
stick.
- Retrieving the homework file:
- Open the class web site
- Scroll down to Homework 1
- Right click on Homework 1
- Choose Save target As ...
- Navigate to your working directory (see above)
- Make sure the file has the name hw1.m
- Accept that location and let the system download
the file
- Decline the offer to open the file
- Doing the homework
- Start Matlab
- Point the current directory to your working
directory
- Double click the file -- this should open the Matlab editor
- Build and test solutions incrementally
Introduce Vectors
- Create vectors with [...], linspace(...), zeros(...),
ones(...), rand(...).
- Access the data by indexing – out of bounds below,
above the size
- Shorten vectors with [ ]
- Write a script to plot sqrt(sin(x)) or something. You
assume that functions can accept a vector and produce a vector.
Objective: Vector Operations (Ch 4)
Arithmetic expression
- Two vectors matching size, or at least one a scalar
- +, -, .*, ./, .^
Logical expression
- Two vectors matching size, or at least one a scalar
- >, <, >=, <=, ==
Vector Indexing with integer Vectors
- Indexing any vector with another vector -- end, etc.
- Examples like keeping the odd or even values,
reversing a vector
Vector Indexing with logical Vectors
- Indexing any vector with a logical vector
- Examples like all the numbers > 10, or all the even
numbers (as opposed to even locations)
Applying built-in Functions
- size, min, max with multiple return values
- ceil, floor, round, fix
- expand plotting to things like a spiral: plotting
theta .* cos(theta) vs theta .* sin(theta)
Lecture 5
Objective: Conditionals (Ch 5)
Logical expression
- Anything that returns a Boolean (true/false) result
If statements
- Simple if / else, e.g. weekend vs weekday
- elseif e.g. numerical grade -> letter grade
- If with vector operations implies all(...)
Switch statements
- selecting among finite choices -- days in a month works
well as an example
- Default use to catch exceptions -- bad form for main
thread
Lecture 6
Objective: Iteration (Ch 6)
For loops
- Simplest example: finding the max of a vector; use
for x = A first, and trace it carefully
- Debugging using the stepper
- Knowing which value -- needs "usual" form index =
1:length(A) [don't use i or j as the index -- they have values in
Matlab]
While loops
- Repeat finding the max using while
- Build a loop-and-a-half by asking for the radius and
computing the area
Lecture 7
Objective: Functions (Ch 7)
- Abstraction
- Black Box View
- Code re-use
Simple Function
- Find a root of a quadratic
- Building, testing, checking
- Illustrate variable scoping
Code Re-use
- 'th' logic should be encapsulated
More Stuff
- Returning Multiple Values
- Consuming vectors
Lecture 8
Objective: Character Strings (Ch 6)
Manipulating Strings
- As if they were vectors
- Doing math on them --casting
- Input and output -- sprintf
- Comparing strings -- strcmp(...) -- not the same as C
- Arrays of Strings must match sizes
- char(...) gets you off the hook
Lecture 9
Objectives: Cell Arrays (Ch 7)
Containers
- Limited number of operations
- Uses.
- deal(...)
- example: vectors of various lengths
- build one using rand extensively for length and
content
- process it for average length, min, max etc.
Lecture 10
Objective: Structures (Ch 7)
Structure for 1 CD
- Name fields
- Access fields
- fieldnames(.....)
- rmfield(...)
Lecture 11
Objectives: Using structure arrays as examples of problem solving
operations (Ch 10)
Structure Arrays
- Array of CD structures
- Uniformity of fields
Problem Solving
Identify each of the following and code examples from the
CD collection
- Build / Insert (implied in makeCD(...))
- Traverse -- e.g. save to a file as text – see writeCDs(...)
but don’t dig around in it…
- Map -- change all of them, like raise the prices or add
a field like value
- Filter -- choose some of them by name or price
- Fold -- summarize the whole collection – count, or
total price
- Search -- find one particular CD
- Sort -- introduce Matlab built-in sort(...) -- prepare
data using {CDs.artist} or [CDs.value]
Lecture 12
Objectives: Continue problem solving operations (Ch 10)
TEST 1
Lecture 13
Speech about not giving up:
q
changing study habits,
q
final grade replacing test average
Objective: Arrays (Ch 3)
Extending vectors to arrays
- Creating
- Accessing elements
- Removing whole rows or columns
- Scalar and logical operations
- Concatenation
- Ranges of indices
- Slicing
- Linearizing (access as if it were a vector, result of
find(...) )
Lecture 14
Objectives: File I/O with Spread Sheets (Ch 8)
Types of File I/O:
- Save and restore the workspace
- Read and Process Excel Spread Sheets
- Read and Process Comma Separated Values (numbers only)
- General-Purpose File Read and Write
Examples:
- Read grades.xls
- Computations
- Read World_Data.xls
Lecture 15
Objective: Mid-Level File I/O (Ch 8)
q
CSV Files
Objective: Low-Level File I/O (Ch 8)
q
Open, close
q
Get strings
Lecture 16
Objective: Finish up File I/O (Ch 8)
q
Tokens
Lecture 17
Objective: Understanding Recursion (Ch 9)
q
Stacks
q
Activation Stack implementation of Function Calls
q
Illustrate on the Board using Roots of a Quadratic
q
Canonical problem: factorial
o
Define the factorial
o
Identify 3 parts of recursion:
-
Clone the function
-
Terminating condition
-
Move towards termination
o
Write the code
o
Run with the Debugger for simple case
q
Wrapper functions for setup -- negative or fractional numbers?
q
Local functions
q
Graphical Root Finding
q
Palindromes
q
Fibonacci
q
Mutual recursion
q
Tail recursion (?)
Lecture 18
Objective: Complete discussion of recursion (Ch 9)
Overall, we need to have covered these topics:
q
Basic recursion -- factorial -- how it works, and why --activation
stack etc.
q
Wrapper functions -- preparing the data and checking for errors
q
Tree recursion --Fibonacci --a bad idea computationally
q
Perhaps Palindromes or other examples
q
Not tail recursion or mutual recursion
Lecture 19
Objective: Begin discussion of plotting (Ch 11)
q
There is an intercepts script to start the discussion if you want
q
2-D plotting -- line color, symbols, titles, etc. [rotate to see
the 3-D effect]
q
Parametric curves -- circle, random walk
q
plot3(...)
Lecture 20
Objective: Continue discussion of plotting (Ch 11)
q
meshgrid, surf, mesh
q
shading, lighting
Lecture 21
Objective: Bodies of Rotation (Ch 11)
q
Rotate about X-axis
q
Rotate discrete data points
Lecture 22
Objective: Finish up Bodies of Rotation (Ch 11)
q
Rotate about the vertical axis
q
Using the 4th parameter to surf
q
...
Objectives: File I/O with CSV files (Ch 8)
- Process and plot atlanta.txt – the streets
- Process and plot ttimes.txt
Lecture 23
Objective: Matrix Multiplication (Ch 12)
q
Matrix multiply
q
Coordinate rotation
q
Twinkling stars
Lecture 24
Objective: Matrix Division (Ch 12)
q
Basics of division
q
Solving Simultaneous equations
q
Resistor network
q
Chemical Composition
Lecture 25
Objectives: Introduce Images (Ch 13)
Introduce Image formats
Simple image analysis and processing
- Read volta.jpg
- Plot sections through it
- Reshape
- Change Colors
Lecture 26
Objective: Second Images lecture (Ch 13)
Use the image Volta.jpg
- Stretching / Shrinking Images
- Index vectors created with linspace
- Clipping/Mirroring Images
- Index vectors created with linspace
TEST 2
Lecture 27
Objective: Third Images Lecture (Ch 13)
- "Green Screen" masking
- Replace the grey sky in Vienna.jpg with blue sky
from Witney.jpg
- Plot the color values at row 350 to find the
thresholds
- Create a 2-D layer mask
- Build a 3-D mask from this layer
- Make the mask below 700 false
- Copy the Witney image into this masked area of
Vienna
- Write the new jpeg
- Zoom on the wire and discuss its appearance (artifact
of the JPEG compression)
Lecture 28
Objective: Begin Numerical Methods – Ch 15
- Interpolation
- Linear using interp1(x, y, val) -- supply scalar val for one pt, vector for range
- Extrapolation possible?
- Spline interpolation -- math, useful?
Lecture 29
Objective: Continue Numerical Methods (Ch 15)
- Curve Fitting
- Why? Trust the underlying physics more than the
data
- Polyfit produces the coefficients
- Polyval produces the curve
- Integration and Differentiation
- Cumsum integrates
- Diff(y) / diff(x) differentiates
Lecture 30
Objective: Continue Numerical Methods (Ch 15)
- Zero Crossings
- Estimate by shifting and multiplying (P. 261)
- Eyeball actual values by plotting
- Compute by Newton's method or geometry
- Differentiation and Integration
- Start with a 6th order polynomial
- Compute and plot the analytical slope
- Compute the gradient by diff(y) / diff(x)
- Compute and plot the analytical integral
- Compute the integral by cumsum, and by trapezoidal
rule and Simpson's Rule
Lecture 31
Objective: Problem Solving
Lecture 32
Objective: Understand Measures of Computing (Ch 16)
Big O as a measure of the work
done by an algorithm
Objective: Understand MATLAB sorting (Ch 16)
Using MATLAB internal sort of a
vector
Extracting fields from a structure
array -- numerical and sorting the array
Extracting fields from a structure
array -- strings and sorting the array
o
I really minimize this discussion
by using as an analogy the area of the space occupied by the steps in the sort
algorithms. All are N wide; Insertion Sort is also N deep, where the other two
are Log N deep.
Objective: Understand sorting algorithms (Ch 16)
Four sorting techniques:
o
Bubble Sort
o
Insertion Sort
o
Merge Sort
o
Quick Sort
Circumstances under which last
three might be used.
Students should be able to code
first three using a vector of numbers
Lecture 33
Objective: Sorting (Ch 16)
-
Complete sorting discussion
Lecture 34
Objectives: Introduce Sound (Ch 14)
Reading and Playing Sound
Changing amplitude and playback
frequency
Slicing and concatenating speech.
Lecture 35
Objective: More on Sound (Ch 14)
Instrument sounds:
o
The musical scale -- 21/12
factor between half steps
o
Octave doubles the frequency
Playing a tune by changing Fs
o
Note duration achieved by pausing
Assembling a tune by stretching /
shrinking the note
o
Note duration achieved by the
number of samples concatenated
Lecture 36
Objective: Finish up Sound (Ch 14)
- The FFT -- its parameters
- Create a 400 Hz sine wave from scratch
- Play it
- Perform the FFT
- Plot the result including the correct axes
- Discuss the results
- Add a line to the FFT (both ends)
- Perform the ifft
- Play the absolute value of the result
- Read an instrument
- Perform and plot the FFT
Lecture 37
Objective: Queues (Ch 17)
Queue
Priority Queue
TEST 3
Lecture 38
Objective: Finish Queues (Ch 17)
Lecture 39
Objective: Processing Graphs (Ch 17)
Definition of a Graph
Breadth-First Search
Dijkstra's Algorithm for Optimal
Search
Lecture 40
Objective: Lecturer’s Choice
Lecture 41
Objective: Course Overview
- List topics from book index
- Feedback session on class mechanics