{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CS 100 M Lecture 12

CS 100 M Lecture 12 - 12 Still More on Arrays Functions...

Info iconThis preview shows pages 1–17. Sign up to view the full content.

View Full Document Right Arrow Icon
12. Still More on Arrays Functions with array parameters. Row and column vectors Built-Ins: length, zeros, std Revisit: rand, randn, max
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Row and Column Vectors >> v = [1 2 3] v = 1 2 3 >> v = [1 ; 2 ; 3] v = 1 2 3 Observe semicolons
Background image of page 2
zeros( , ) >> x = zeros(3,1) x = 0 0 0 >> x = zeros(1,3) x = 0 0 0
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
rand( , ) >> x = rand(3,1) x = 0.2618 0.7085 0.7839 >> x = rand(1,3) x = 0.9862 0.4733 0.9028
Background image of page 4
randn( , ) >> x = randn(1,3) x = 0.2877 -1.1465 1.1909 >> x = randn(3,1) x = 1.1892 -0.0376 0.3273
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Normal Distribution with Zero Mean and Unit STD -3 -2 -1 0 1 2 3 0 10000 20000 30000 40000 50000 60000 70000 80000 90000 100000 110000 Distribution of randn(1000000,1)
Background image of page 6
Affirmations >> n = 1000000; >> x = randn(n,1); >> ave = sum(x)/n ave = -0.0017 >> standDev = std(x) standDev = 0.9989
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
length >> v = randn(1,5); >> n = length(v) n = 5 >> u = rand(5,1); >> n = length(u) n = 5 The length function doesn’t care about row or column orientation.
Background image of page 8
Augmenting Row Vectors >> x = [10 20] x = 10 20 >> x = [x 30] x = 10 20 30 >>
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Augmenting Column Vectors >> x = [10;20] x = 10 20 >> x = [x ; 30] x = 10 20 30 Observe semicolons!
Background image of page 10
“Concatenating” Row Vectors >> x = [10 20] x = 10 20 >> y = [30 40 50] y = 30 40 50 >> z = [x y] z = 10 20 30 40 50
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
“Concatenating” Column Vectors >> x = [10 ; 20]; >> y = [30 ; 40 ; 50]; >> z = [ x ; y ] z = 10 20 30 40 50 Observe semicolons!
Background image of page 12
Application x = linspace(0,2*pi,100); y = sin(x); x = [x x+2*pi]; y = [y y]; plot(x,y) Plot sine across [0,4*pi] and use the fact that it has period 2pi.
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
0 2 4 6 8 10 12 14 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 x = linspace(0,2*pi,100); x = [ x x+2*pi ]; linspace(2*pi,4*pi,100)]
Background image of page 14
The Empty Vector x = [ ]; for k=1:50 if floor(sqrt(k))==sqrt(k) x = [x; k]; end end x = x x = 1 4 9 16 25 36 49
Background image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Array Hints & Errors
Background image of page 16
Image of page 17
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}