This preview shows pages 1–14. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 12. Still More on Arrays Functions with array parameters. Row and column vectors BuiltIns: length, zeros, std Revisit: rand, randn, max Row and Column Vectors >> v = [1 2 3] v = 1 2 3 >> v = [1 ; 2 ; 3] v = 1 2 3 Observe semicolons zeros( , ) >> x = zeros(3,1) x = >> x = zeros(1,3) x = 0 0 rand( , ) >> x = rand(3,1) x = 0.2618 0.7085 0.7839 >> x = rand(1,3) x = 0.9862 0.4733 0.9028 randn( , ) • >> x = randn(1,3) • x = • 0.2877 1.1465 1.1909 • >> x = randn(3,1) • x = • 1.1892 •0.0376 • 0.3273 Normal Distribution with Zero Mean and Unit STD321 1 2 3 10000 20000 30000 40000 50000 60000 70000 80000 90000 100000 110000 Distribution of randn(1000000,1) Affirmations >> n = 1000000; >> x = randn(n,1); >> ave = sum(x)/n ave =0.0017 >> standDev = std(x) standDev = 0.9989 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. Augmenting Row Vectors >> x = [10 20] x = 10 20 >> x = [x 30] x = 10 20 30 >> Augmenting Column Vectors >> x = [10;20] x = 10 20 >> x = [x ; 30] x = 10 20 30 Observe semicolons! “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 “Concatenating” Column Vectors >> x = [10 ; 20]; >> y = [30 ; 40 ; 50]; >> z = [ x ; y ] z = 10 20 30 40 50 Observe semicolons! 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. 2...
View
Full
Document
This note was uploaded on 02/23/2008 for the course CS 100 taught by Professor Fan/vanloan during the Spring '07 term at Cornell.
 Spring '07
 FAN/VANLOAN

Click to edit the document details