Downloaded 01/11/15 to 128.97.245.102. Redistribution subject to SIAM license or copyright; see http:/www.siam.org/journals/ojsa.php
Chapter 6
Randomness
6.1 Safety in Numbers
Monte Carlo Simulation
6.2 Dice and Compass
Random Walks
6.3 Order from Chaos
P
Lecture 4b
CEE/MAE M20
Introduction to Computer Programming with MATLAB
Watch: http:/youtu.be/E7DKxe_m1AM
http:/youtu.be/vuMir11YFPs
2
CEE/MAE M20
Bean Machine
Also known as Galton Board or Quincunx
A device for statistical experiments
Invented for dem
Lecture 4a
1-D Arrays and the Discrete vs. the Continuous
CEE/MAE M20
Introduction to Computer Programming with MATLAB
Week 3 Reading:
ITC Chapter 4
CEE/MAE M20
2
1-D arrays
CEE/MAE M20
3
Example: Plotting sine
Suppose we wish to plot sin(x) for 0 <= x <=
Lecture 5a
Abstraction: functions separate interface from implementation
CEE/MAE M20
Introduction to Computer Programming with MATLAB
Week 5 Reading in ITC
CEE/MAE M20
2
Two huge concepts
CEE/MAE M20
3
Two huge concepts
Interface
What job gets done?
What
Lecture 5b
Numerical Interpolation and Differentiation
CEE/MAE M20
Introduction to Computer Programming with MATLAB
Numerical Interpolation
Suppose were given as discrete set of data
2
1.5
1
y
0.5
0
-0.5
-1
-1.5
-2
0
0.5
1
x
1.5
2
2
2.5
CEE/MAE M20
Numeri
Lecture 6b
Linear algebra in action!
CEE/MAE M20
Introduction to Computer Programming with MATLAB
Solution of a linear system of equations
One of the most common tasks in computational science is to solve the
problem Ax = b for a vector x. We will restric
Lecture 6a-1
Function handles
CEE/MAE M20
Introduction to Computer Programming with MATLAB
In Homework 5, the most annoying aspect of the differentiation functions:
The name of the function that they call to evaluate f(x) is hard-coded into it
CEE/MAE M20
Newtons Method for Root Finding
CEE/MAE M20
Introduction to Computer Programming with MATLAB
February 20, 2015
Newtons Method
Question
How do we nd the zero(s) of a function using Newtons method?
Goal
Newtons Method
Question
How do we nd the zero(s) of a
Lecture 7a
Sorting
CEE/MAE M20
Introduction to Computer Programming with MATLAB
Week 7 Reading
CEE/MAE M20
2
Searching for an item in an unorganized collection?
May need to look through the whole
collection to find the target item
E.g., find value x in ve
Lecture 7b
Divide and Conquer!
CEE/MAE M20
Introduction to Computer Programming with MATLAB
Other Week 7 Reading
CEE/MAE M20
2
The Manhattan phone
book has 1,000,000+
entries.
How is it possible to
locate a name by
examining just a tiny,
tiny fraction of
Lecture 8a
Data Abstraction
CEE/MAE M20
Introduction to Computer Programming with MATLAB
Week 8 Reading
CEE/MAE M20
2
Thus far, we have learned how to store data as
Scalar variables
1-D and 2-D arrays
This is rather limiting, so wed like to enhance this
Lecture 8b
File Input/Output
CEE/MAE M20
Introduction to Computer Programming with MATLAB
Week 8 Reading+
CEE/MAE M20
2
fopen, fwritef/freadf,fgetl,fclose, etc
mat les
regexp
str2num
cell2struct?
Homework: Test on two randomly sorted arrays of same data.
Lecture 9a
The frequency domain
CEE/MAE M20
Introduction to Computer Programming with MATLAB
Week 9 Reading
CEE/MAE M20
2
Suppose we have a basic sinusoidal signal
2
1.5
F (t) = cos(2fb t)
1
f(t)
0.5
0
-0.5
-1
-1.5
-2
0
0.2
0.4
t (sec)
0.6
0.8
1
CEE/MAE M
Lecture 9b
Signal Processing and Impedance
CEE/MAE M20
Introduction to Computer Programming with MATLAB
Last time, we dealt with noisy signals and the associated spectrum
1
Fk =
n
F (t) = A cos(2fb t) + n(t)
2
1.2
n 1
X
Fj e
i2jk/n
k = 0, . . . , n
,
1
j=
Lecture 10b
Everything we didnt cover
CEE/MAE M20
Introduction to Computer Programming with MATLAB
What we covered
Programming elements and syntax
Assignment, variables, strings
Logical expressions, Booleans, conditionals
Loops and recursion
1-D and m
Lecture 10a
Images
CEE/MAE M20
Introduction to Computer Programming with MATLAB
Week 10 Reading
CEE/MAE M20
2
Working with Image Files
imread, imwrite,
imshow, uint8,
rgb2gray
Insight Through Computing
Pictures as Arrays
A black and white picture can be e
Lecture 2a
Logical expressions and conditionals
CEE/MAE M20
Introduction to Computer Programming with MATLAB
At the heart of almost any computational task are logic and conditionals
Input
Is logic
expression
true?
No
Do something
else
Yes
Do something
CEE
Lecture 3b
Predator-prey I
CEE/MAE M20
Introduction to Computer Programming with MATLAB
To be learned
Continuous and discretized
Numerical integration: forward Euler method
Flow control: for loop
2D plot
CEE/MAE M20
2
Outline
I. Fundamentals of predator-p
Discussion 1
CEE/MAE M20
Introduction to Computer Programming with MATLAB
What is MATLAB?
MATLAB = MATrix LABoratory
MathWorks (the developers of MATLAB): MATLAB is a
high-level language and interactive environment for numerical
computation, visualization
Downloaded 01/11/15 to 128.97.245.102. Redistribution subject to SIAM license or copyright; see http:/www.siam.org/journals/ojsa.php
Chapter 3
22 , 245 , 355 ,.
7 78 113
Approximation with
Fractions
3.1 22/7ths and Counting
Proximity to Pi
3.2 Not Quite P
Downloaded 01/11/15 to 128.97.245.102. Redistribution subject to SIAM license or copyright; see http:/www.siam.org/journals/ojsa.php
Chapter 2
Limits and Error
2.1 Tiling a Disk
Summation
2.2 Inside/Outside Polygons
Sequences
The number is a never-ending
Downloaded 01/11/15 to 128.97.245.102. Redistribution subject to SIAM license or copyright; see http:/www.siam.org/journals/ojsa.php
Chapter 4
The Discrete versus
the Continuous
4.1 Connect the Dots
Plotting Continuous Functions
4.2 From Cyan to Magenta
C
Downloaded 01/11/15 to 128.97.245.102. Redistribution subject to SIAM license or copyright; see http:/www.siam.org/journals/ojsa.php
Chapter 5
Abstraction
5.1 Reshaping Rectangles
A Square and a Root
5.2 Oval Odometer
Ellipse Perimeter
5.3 The Betsy Ross
Downloaded 01/11/15 to 128.97.245.102. Redistribution subject to SIAM license or copyright; see http:/www.siam.org/journals/ojsa.php
Chapter 8
Reordering
8.1 Cut and Deal
The Perfect Shufe
8.2 Size Place
Sorting
Shufing a deck of n cards, alphabetizing a
Downloaded 01/11/15 to 128.97.245.102. Redistribution subject to SIAM license or copyright; see http:/www.siam.org/journals/ojsa.php
A
B
C
D
E
F
G
H
I
K
L
M
A
B
C
D
E
F
G
H
I
K
L
A
B
C
D
E
F
G
H
I
K
L
M
A
B
C
D
E
F
G
H
I
K
L
M
Chapter 9
M
Search
9.1 Patte
Downloaded 01/11/15 to 128.97.245.102. Redistribution subject to SIAM license or copyright; see http:/www.siam.org/journals/ojsa.php
C
Chapter 10
B
Points, Polygons,
and Circles
A
10.1 How Far?
Distance Metrics
10.2 Fenced in Twice?
Intersection
10.3 Not
Downloaded 01/11/15 to 128.97.245.102. Redistribution subject to SIAM license or copyright; see http:/www.siam.org/journals/ojsa.php
Chapter 11
Text File Processing
11.1 Latitude and Daylight
Data Acquisition and Conversion
11.2 Nearby Millions
Writing an
Downloaded 01/11/15 to 128.97.245.102. Redistribution subject to SIAM license or copyright; see http:/www.siam.org/journals/ojsa.php
Chapter 15
Optimization
15.1 Shortest Route
The Combinatoric Explosion
15.2 Best Bike
Constraints and Objective Functions
Downloaded 01/11/15 to 128.97.245.102. Redistribution subject to SIAM license or copyright; see http:/www.siam.org/journals/ojsa.php
Chapter 14
Divide and Conquer
14.1 Patterns within Patterns
Recursive Tiling
14.2 N and Half N
Merge Sort
14.3 Looking for