2 ArrayMatrix 9172020 Puff The magic dragon live
- Slides: 83
第 2 章 陣列(Array)與矩陣(Matrix) 的運算 9/17/2020 Puff! The magic dragon, live by the sea… 1
9/17/2020 Puff! The magic dragon, live by the sea… 2
列向量 & 行向量 • Row vector 列向量 [5, 7, 2]; [3, 4, -6, 7] • Column vector 行向量 9/17/2020 Puff! The magic dragon, live by the sea… 3
陣 列 Arrays 9/17/2020 Puff! The magic dragon, live by the sea… 4
轉置 transpose 9/17/2020 Puff! The magic dragon, live by the sea… 5
Transpose matrix • g=[1; 2; 3; 4]; g 1=g’; or g=[1 2 3 4]; 9/17/2020 Puff! The magic dragon, live by the sea… 6
Transpose matrix • k=[1 -9 1 0 3; -4 4 1 1 2; 24 2 2 36 2] or k=[1, -9, 1, 0, 3; -4, 4, 1, 1, 2; 24, 2, 2, 36, 2] or k=[1 -9 1 0 3 -4 4 1 1 2 24 2 2 36 2] • k 1=k’ 9/17/2020 Puff! The magic dragon, live by the sea… 7
產生等間距大向量 x=[m: q: n] ? x=[0: 2: 8] x= 0 2 4 • ? y=[-3: 2] • y= • -3 -2 -1 9/17/2020 6 8 0 1 2 Puff! The magic dragon, live by the sea… 8
產生等間距大向量 ? z=[0: 0. 1: 2] z= Columns 1 through 7 0 0. 1000 0. 2000 0. 3000 0. 4000 0. 5000 0. 6000 Columns 8 through 14 0. 7000 0. 8000 0. 9000 1. 0000 1. 1000 1. 2000 1. 3000 1. 7000 1. 8000 1. 9000 2. 0000 Columns 15 through 21 1. 4000 9/17/2020 1. 5000 1. 6000 Puff! The magic dragon, live by the sea… 9
產生等間距大向量 ? zzz=[3: -0. 5: 0] zzz = 3. 0000 9/17/2020 2. 5000 2. 0000 1. 5000 1. 0000 Puff! The magic dragon, live by the sea… 0. 5000 0 10
linespace(x 1, x 2, n) 產生等間距列向量 • linespace(5, 8, 31) • the same as [5: 0. 1: 8] • n 表示列向量內含的元素個數 如果省略則 內定值為 1 9/17/2020 Puff! The magic dragon, live by the sea… 11
logspace(x 1, x 2, n) 產生具有對數等間距的向量 • logspace (a, b, n) • 在 10 a~10 b間(含)取的點數 • logspace(-1, 1, 4)=[0. 1, 0. 4642, 2. 1544, 10. 0] 9/17/2020 Puff! The magic dragon, live by the sea… 12
2 -Dimensional Arrays 9/17/2020 Puff! The magic dragon, live by the sea… 13
合併 矩陣(行數增加) ? A=[2, 4, 10; 16, 3, 7] A= 2 4 10 16 3 7 ? r=[1, 1; 0, 0] r= 1 1 0 0 ? B=[A r] B= 2 4 10 1 1 16 3 7 0 0 9/17/2020 矩陣A與r需具有相同的 列數 Puff! The magic dragon, live by the sea… 14
合併 矩陣(列數增加) ? A=[2, 4, 10; 16, 3, 7] A= 2 4 10 16 3 7 ? r=[1, 2, 3] r= 1 2 3 ? B=[A; r] 矩陣A與r需具有相同的 行數 B= 2 16 1 9/17/2020 4 10 3 7 2 3 Puff! The magic dragon, live by the sea… 15
Transpose matrix (complex conjugate) ? A=[3+2*i, 2+6*i; 5+4*i, 3+5*i] A= 3. 0000 + 2. 0000 i 2. 0000 + 6. 0000 i 5. 0000 + 4. 0000 i 3. 0000 + 5. 0000 i ? A' ans = 3. 0000 - 2. 0000 i 5. 0000 - 4. 0000 i 2. 0000 - 6. 0000 i 3. 0000 - 5. 0000 i 9/17/2020 Puff! The magic dragon, live by the sea… 16
Array addressing定址 1. 修改矩陣內元素 D(1, 3)=6 B= 2 4 10 16 3 7 1 2 3 ? B(2, 2)=0 B= 2 4 10 16 0 7 1 2 3 9/17/2020 Puff! The magic dragon, live by the sea… 17
Array addressing定址 2. V(: ) V向量內所有元素 ? V=[1 2 3 4 5] V= 1 2 3 4 5 ? V(: ) ans = 1 2 3 4 5 9/17/2020 Puff! The magic dragon, live by the sea… 18
Array addressing定址 3. V(2: 4) • • • V= 1 2 ? V(2: 4) ans = 2 3 V(2), V(3), V(4), V(5), V(6) 9/17/2020 3 4 5 4 Puff! The magic dragon, live by the sea… 19
Array addressing定址 4. A(: , 3) A= 3 5 17 1 2 3 ? A(: , 3) ans = 11 8 4 9/17/2020 矩陣A第三行所有的元素 11 8 4 Puff! The magic dragon, live by the sea… 20
Array addressing定址 5. A(: , 2: 3) 矩陣A第 2行至第 3行所有的元素 A= 3 5 11 17 1 8 2 3 4 ? A(: , 2: 3) ans = 5 11 1 8 3 4 9/17/2020 Puff! The magic dragon, live by the sea… 21
Array addressing定址 6. A(2: 3, 1: 3)矩陣A第 2至第 3列, 第 1至第 3行所有的元 素 (可用以分割矩陣) A= 3 5 11 17 1 8 2 3 4 ? A(2: 3, 2: 3) ans = 1 8 3 4 9/17/2020 Puff! The magic dragon, live by the sea… 22
? A=[6, 9, 4; 1, 5, 7] A= 6 9 4 1 5 7 ? A(1, 5)=3 A= 6 9 4 0 3 1 5 7 0 0 ? B=A(: , 5: -1: 1) %把A陣列行排列的次序顛倒過來 B= 3 0 4 9 6 0 0 7 5 1 9/17/2020 Puff! The magic dragon, live by the sea… 23
B= 3 0 4 9 6 0 0 7 5 1 C= -4 12 3 5 8 ? B(2, : )=C B= 3 0 4 9 6 -4 12 3 5 8 9/17/2020 Puff! The magic dragon, live by the sea… 24
? D=[3, 8, 5; 2, -6, 9] D= 3 8 5 2 -6 9 ? E=D([2, 2, 2, 1], : ) %將陣列D的第二列重複三次, 第一列重複一次 E= 2 -6 9 3 8 5 9/17/2020 Puff! The magic dragon, live by the sea… 25
Using ‘clear’ to avoid errors • clear A 9/17/2020 Puff! The magic dragon, live by the sea… 26
A= 6 9 4 1 5 7 ? max(A) ans = 6 9 7 ? [x, k]=max(A) x= 6 9 7 k = % index 1 1 2 9/17/2020 0 0 3 0 3 1 1 Puff! The magic dragon, live by the sea… 27
• B= • 6 9 4 0 3 • ? max(B) • ans = • 9 9/17/2020 Puff! The magic dragon, live by the sea… 28
? A=[6 2; -10 -5; 3 0] A= 6 2 -10 -5 3 0 ? max(A) ans = 6 2 ? min(A) ans = -10 -5 ? size(A) ans = 3 2 ? length(A) ans = 3 9/17/2020 %傳回m*n (3*2)中的最大值 Puff! The magic dragon, live by the sea… 29
? A=[6 2; -10 -5; 3+4*i 0] A= 6. 0000 2. 0000 -10. 0000 -5. 0000 3. 0000 + 4. 0000 i 0 ? max(A) ans = -10 -5 ? min(A) ans = 3. 0000 + 4. 0000 i 0 9/17/2020 Puff! The magic dragon, live by the sea… 30
A= 6. 0000 2. 0000 -10. 0000 -5. 0000 3. 0000 + 4. 0000 i 0 ? sum(A) %將同一行中的所有元素加總 ans = -1. 0000 + 4. 0000 i -3. 0000 9/17/2020 Puff! The magic dragon, live by the sea… 31
A= 6. 0000 2. 0000 -10. 0000 -5. 0000 3. 0000 + 4. 0000 i 0 ? sort(A) %依同行中元素大小順序排列 ans = 3. 0000 + 4. 0000 i 0 6. 0000 2. 0000 -10. 0000 -5. 0000 9/17/2020 Puff! The magic dragon, live by the sea… 32
9/17/2020 Puff! The magic dragon, live by the sea… 33
9/17/2020 Puff! The magic dragon, live by the sea… 34
9/17/2020 Puff! The magic dragon, live by the sea… 35
Magnitude, length, and absolute value of a Vector • Self testing p. 79 9/17/2020 Puff! The magic dragon, live by the sea… 36
多維陣列multidimensional arrays • m*n*q • m: 列(row), n: 行(column), q: 頁(page) • 第n頁的所有元素 A(: , n) 9/17/2020 Puff! The magic dragon, live by the sea… 37
? A=[4, 6, 1; 5, 8, 0; 3, 9, 2] A= 4 6 1 5 8 0 3 9 2 ? A(: , 2)=[6, 2, 9; 0, 3, 1; 4, 7, 5] A(: , 1) = 4 6 1 5 8 0 3 9 2 A(: , 2) = 6 2 9 0 3 1 4 7 5 9/17/2020 Puff! The magic dragon, live by the sea… 38
? A=[8 2; 9 5] A= 8 2 9 5 ? B=[4 6; 7 3] B= 4 6 7 3 ? C=cat(3, A, B) C(: , 1) = 8 2 9 5 C(: , 2) = 4 6 7 3 9/17/2020 Puff! The magic dragon, live by the sea… 39
cat(1, A, B)=[A; B] 一維 A= 8 2 9 5 B= 4 6 7 3 ? cat(1, A, B) ans = 8 2 9 5 4 6 7 3 9/17/2020 ? [A; B] ans = 8 2 9 5 4 6 7 3 Puff! The magic dragon, live by the sea… 40
cat(2, A, B)=[A, B] 二維 A= 8 9 B= 4 7 2 5 6 3 ? cat(2, A, B) ans = 8 2 4 9 5 7 9/17/2020 ? [A, B] ans = 8 2 9 5 4 7 6 3 Puff! The magic dragon, live by the sea… 41
cat(3, A, B) 三維 A= 8 2 9 5 B= 4 6 7 3 ? cat(3, A, B) ans(: , 1) = 8 2 9 5 9/17/2020 ans(: , 2) = 4 6 7 3 ? C(2, 1, 1) ans = 9 Puff! The magic dragon, live by the sea… 42
Array Operations A= 8 9 ? 3*A ans = 24 27 9/17/2020 2 5 6 15 ? A+1000 ans = 1008 1009 ? A/3 ans = 2. 6667 3. 0000 1002 1005 0. 6667 1. 6667 Puff! The magic dragon, live by the sea… B= 4 6 7 3 ? A+B ans = 12 8 16 8 ? A-3*B ans = -4 -16 -12 -4 43
A= 8 2 9 5 B= 4 6 7 3 • ? A*B ans = 46 54 71 69 ? A. *B ans = 32 12 63 15 9/17/2020 Array Operations ? A. /B %(B. A) ans = 2. 0000 0. 3333 1. 2857 1. 6667 ? AB %(A-1*B) ans = 0. 2727 1. 0909 0. 9091 -1. 3636 ? B. /A %(A. B) ans = 0. 5000 3. 0000 0. 7778 0. 6000 ? A/B %(A*B-1) ans = -0. 3333 1. 3333 0. 2667 1. 1333 Puff! The magic dragon, live by the sea… 44
9/17/2020 Puff! The magic dragon, live by the sea… 45
9/17/2020 Puff! The magic dragon, live by the sea… 46
9/17/2020 Puff! The magic dragon, live by the sea… 47
Take a rest! Try p. 84 ex. 2. 3 -1 9/17/2020 Puff! The magic dragon, live by the sea… 48
? x=[2, 4, -5]; y=[-7, 3, -8] ? x. *y ans = -14 12 40 ? x*y ? ? ? Error using ==> * Inner matrix dimensions must agree. 9/17/2020 ? x'*y ans = -14 6 -16 -28 12 -32 35 -15 40 ? x*y' ans = 38 Puff! The magic dragon, live by the sea… 49
p. 86, ex. 2. 3 -2 ? v=w-r v= -75 23 -10 ? r=[55, 36, 25]; ? w=[-20, 59, 15]; ? dist 1=sqrt(sum(r. *r)) dist 1 = 70. 327 9/17/2020 ? dist 2=sqrt(sum(v. *v)) dist 2 = 79. 0822 Puff! The magic dragon, live by the sea… 50
Ex. 2. 3 -3 ? t=[0: . 003: 0. 5]; ? y=exp(-8*t). *sin(9. 7*t+pi/2); ? plot(t, y), xlabel('t (sec)'), . . . ylabel('y(t)') 9/17/2020 Puff! The magic dragon, live by the sea… 51
p. 89, ex. 2. 3 -4 ? d=[560, 440, 490, 530, 370] %mile ? t=[10. 3, 8. 2, 9. 1, 10. 1, 7. 5] % hour ? speed=d. /t speed = 54. 3689 53. 6585 53. 8462 52. 4752 49. 3333 9/17/2020 Puff! The magic dragon, live by the sea… 52
Array exponentiation ? A=[4 -5; 2 3] A= 4 -5 2 3 ? B=A. ^3 B= 64 -125 8 27 9/17/2020 ? C=3. ^A C= 81. 0000 0. 0041 9. 0000 27. 0000 Puff! The magic dragon, live by the sea… 53
I=V/R, P=V^2/R ? R=[10000, 20000, 35000, 100000, 200000]; ? V=[120, 80, 110, 200, 350]; ? current=V. /R current = 0. 0120 0. 0040 0. 0031 0. 0020 0. 0018 ? power=V. ^2. /R power = 1. 4400 0. 3200 0. 3457 0. 4000 0. 6125 9/17/2020 Puff! The magic dragon, live by the sea… 54
? x=[0: . 001: 0. 6]; ? L=100*(x/0. 6). ^(0. 625). *((1 -x)/0. 4). ^(-1. 625); ? plot(L, x), grid, xlabel('L (mol)'), . . . ylabel('x (mol B/mol)'), [L, x]=ginput(1) L= 70. 0461 x= 0. 5219 9/17/2020 Puff! The magic dragon, live by the sea… 55
Multivariable functions • • • Ex-2. 3 -7 v=10, 12, 14, 16, 18, 20 m/s =50, 60, 70, 80 degrees • • • • g=9. 8; v=[10: 2: 20]; th=[50: 10: 80] thr=th*(pi/180); vel=[ ]; for k=1: length(th) vel=[vel, v']; end theta=[ ]; for k=1: length(v) theta=[theta; thr]; end h=(vel. ^2. *(sin(theta)). ^2)/(2. *g) H=[v', h]; table=[0, th; H] 9/17/2020 Puff! The magic dragon, live by the sea… 56
• 0 50. 0000 60. 0000 70. 0000 80. 0000 • 10. 0000 2. 9940 3. 8265 4. 5052 4. 9482 • 12. 0000 4. 3114 5. 5102 6. 4875 7. 1254 • 14. 0000 5. 8682 7. 5000 8. 8302 9. 6985 • 16. 0000 7. 6646 9. 7959 11. 5334 12. 6674 • 18. 0000 9. 7006 12. 3980 14. 5969 16. 0322 • 20. 0000 11. 9760 15. 3061 18. 0209 19. 7928 9/17/2020 Puff! The magic dragon, live by the sea… 57
Ax=b 9/17/2020 Puff! The magic dragon, live by the sea… 58
9/17/2020 Puff! The magic dragon, live by the sea… 59
9/17/2020 Puff! The magic dragon, live by the sea… 60
9/17/2020 Puff! The magic dragon, live by the sea… 61
Matrix operation • • • Multiplication of vectors p. 95 Vector-matrix multiplication p. 96 Matrix-matrix multiplication p. 96 The general matrix multiplication case p. 99 9/17/2020 Puff! The magic dragon, live by the sea… 62
9/17/2020 Puff! The magic dragon, live by the sea… 63
9/17/2020 Puff! The magic dragon, live by the sea… 64
9/17/2020 Puff! The magic dragon, live by the sea… 65
Special matrices • Null matrix • Identity matrix 9/17/2020 Puff! The magic dragon, live by the sea… 66
Special matrices • ? eye(3) • ? ones(3) • ans = • • • 9/17/2020 1 0 0 0 1 • • • Puff! The magic dragon, live by the sea… 1 1 1 1 1 67
Special matrices • ? zeros(3) • ? zeros(2, 3) • ans = • • • 9/17/2020 0 0 0 0 • • Puff! The magic dragon, live by the sea… 0 0 0 68
Special products • cross(A, B) ~ momentum • dot(r, F) 9/17/2020 Puff! The magic dragon, live by the sea… 69
9/17/2020 Puff! The magic dragon, live by the sea… 70
9/17/2020 Puff! The magic dragon, live by the sea… 71
polyminals • [a 1, a 2, … an-1, an+1] 9/17/2020 Puff! The magic dragon, live by the sea… 72
Polynomial algebra • f=[9, -5, 3, 7] • g=[6, -1, 2] • g=[0 g]=[0, 6, -1, 2] • h=f+g=[9, 1, 2, 9] 9/17/2020 Puff! The magic dragon, live by the sea… 73
Polynomial algebra • • • f(x)g(x)=? ? f=[9, -5, 3, 7] ? g=[6, -1, 2] ? product= conv(f, g) product = 54 -39 41 29 9/17/2020 -1 14 Puff! The magic dragon, live by the sea… 74
Polynomial algebra • • f(x)/g(x)=? ? f=[9, -5, 3, 7] ? g=[6, -1, 2] ? [quotient, remainder]=deconv(f, g) quotient = %商式 1. 5000 -0. 5833 remainder = %餘式 0 0 -0. 5833 8. 1667 9/17/2020 Puff! The magic dragon, live by the sea… 75
Polynomial algebra • • • f(0), f(2), f(4), f(6), f(8), f(10) f(x)/g(x)=? ? a=[9, -5, 3, 7]; ? x=[0: 2: 10]; ? f=polyval(a, x); • or f=polyval([9, -5, 3, 7], [0: 2: 10]) 9/17/2020 Puff! The magic dragon, live by the sea… 76
Self testing • P. 108 9/17/2020 Puff! The magic dragon, live by the sea… 77
9/17/2020 Puff! The magic dragon, live by the sea… 78
9/17/2020 Puff! The magic dragon, live by the sea… 79
9/17/2020 Puff! The magic dragon, live by the sea… 80
Summary pp. 109 • Home work 9/17/2020 Puff! The magic dragon, live by the sea… 81
9/17/2020 Puff! The magic dragon, live by the sea… 82
9/17/2020 Puff! The magic dragon, live by the sea… 83
- Lived by the sea
- Puff dansk
- Gardner dragon dragon city
- What is the theme of dragon dragon
- Blue dragon life cycle
- Live happy live healthy
- Https://quizlet.com live
- Puff den magiske drage
- Alpha pig helps build the straw house
- List three (3) method of enclosing fat in laminating dough.
- Choux flaky puff short
- Huff puff blow
- Why do turkeys puff up
- Types of puff
- Abe odd hull luck oak
- Laminated pastry
- đặc điểm cơ thể của người tối cổ
- Cách giải mật thư tọa độ
- Các châu lục và đại dương trên thế giới
- Glasgow thang điểm
- ưu thế lai là gì
- Thẻ vin
- Tư thế ngồi viết
- Cái miệng nó xinh thế
- Các châu lục và đại dương trên thế giới
- Từ ngữ thể hiện lòng nhân hậu
- Bổ thể
- Tư thế ngồi viết
- Thế nào là giọng cùng tên?
- Làm thế nào để 102-1=99
- Thể thơ truyền thống
- Chúa yêu trần thế
- Hổ sinh sản vào mùa nào
- đại từ thay thế
- Diễn thế sinh thái là
- Vẽ hình chiếu vuông góc của vật thể sau
- Công thức tính thế năng
- Thế nào là mạng điện lắp đặt kiểu nổi
- Tỉ lệ cơ thể trẻ em
- Lời thề hippocrates
- Vẽ hình chiếu đứng bằng cạnh của vật thể
- Quá trình desamine hóa có thể tạo ra
- Các môn thể thao bắt đầu bằng tiếng nhảy
- Hình ảnh bộ gõ cơ thể búng tay
- Khi nào hổ mẹ dạy hổ con săn mồi
- điện thế nghỉ
- Các loại đột biến cấu trúc nhiễm sắc thể
- Biện pháp chống mỏi cơ
- Trời xanh đây là của chúng ta thể thơ
- độ dài liên kết
- Chó sói
- Thiếu nhi thế giới liên hoan
- Phối cảnh
- Một số thể thơ truyền thống
- Thế nào là hệ số cao nhất
- Hệ hô hấp
- Số nguyên là gì
- Dragon ball chinese food
- Dragón de 3 cabezas hércules
- Dragon lights festival at moscow
- Bearded dragon predators
- Kassim and the greedy dragon
- Wawel castle dragon
- Dragon slayer consulting
- Dragon values
- Dragon of kinabalu
- The train is a dragon that roars through the dark
- Komodo dragon vomit
- Dragon holding a sword
- Dragon trail real life
- The woman and the dragon revelation 12
- Pororoca dragon ball
- London dragon boat festival
- Makedonya uygarlığı
- Threatdragon
- Flap your wings
- Microprocessor
- What was the period of disunion
- Polish legends: the dragon
- The seed of peace, not dragon's teeth.
- Dragon nat speaking
- Fire-breathing dragon фф
- St georges dragon club