Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Matrix Operation ผศ. ดร. อนันต์ ผลเพิ่ม Anan Phonphoem

Similar presentations


Presentation on theme: "1 Matrix Operation ผศ. ดร. อนันต์ ผลเพิ่ม Anan Phonphoem"— Presentation transcript:

1 1 Matrix Operation ผศ. ดร. อนันต์ ผลเพิ่ม Anan Phonphoem http://www.cpe.ku.ac.th/~anan anan@cpe.ku.ac.th

2 2 Outline Creating Matrices Matrix Transpose Array Addressing Array Functions Arithmetic Operators Problem Solving

3 3 Creating Matrices A = 1 2 3 4 5 6 7 8 9 10 A = 1 2 3 4 5 6 7 8 9 10 >>A=[ 1 2 3 4 5; 6 7 8 9 10 ] >>A=[ 1,2,3,4,5; 6,7,8,9,10 ] >>A=[1 2 3 4 5 6 7 8 9 10] >>A=[1 2 3 … 4 5 6 7 8 9 … 10] >>A=[ 1:1:5; 6:1:10] >>A=[ 1:5; 6:10]

4 4 Transpose A = 1 2 3 4 5 6 7 8 9 10 A = 1 2 3 4 5 6 7 8 9 10 B = 1 6 2 7 3 8 4 9 5 10 B = 1 6 2 7 3 8 4 9 5 10 Size of A = 2X5 >>B = A ’ B = A T Size of B = 5X2

5 5 Array Addressing A = 1 2 3 4 5 6 7 8 9 10 A = 1 2 3 4 5 6 7 8 9 10 >>A(2) 6 >>A(3) 2 >>A(2:5) 6 2 7 3 >>A(:,2)2727 >>A(2,:)6 7 8 9 10 >>B = A(1:2,4:5) 4 5 9 10

6 6 Array Functions A = 7 3 12 -1 20 8 2 9 -4 0 2 6 A = 7 3 12 -1 20 8 2 9 -4 0 2 6 >> B = size(A) B = [ 4 3 ] >> B = max(A) B= [ 7 20 12 ] >> B = min(A) B= [ -1 2 -4 ] >> B = sum(A) B= [ 8 34 22 ]

7 7 Array Functions B = 7 3 0 -1 20 8 2 0 -4 0 2 6 B = 7 3 0 -1 20 8 2 0 -4 0 2 6 X = 1 2 3 1 2 4 2 3 4 Y = 1 2 3 Z = 7 2 3 20 2 8 -4 6 >> % find non-zero elements >> [X,Y,Z] = find(B)

8 8 Arithmetic Operators OperatorDescriptionExample +Plus S + T +Unary plus+3 -MinusS – T -Unary minus-C *Matrix MultiplyS * T.*Array Multiply (member)S.* T /Left Matrix Divide (S*INV(T))S / T./Left Array DivideS./ T \ Right Matrix Divide (INV(S)*T) S \ T.\Right Array DivideS.\ T ^Matrix PowerS ^ 2.^Array PowerS.^ 3

9 9 Element-by-Element Operation 102 1 0 3 4 -1 5 A=B= C= A+B = 13 6 0 5 C= A-B = 7 -2 2 -5 C= A+2 = 12 4 3 2 C= A.*B = 30 8 -1 0 C= A./B = 3.3333 0.5000 -1.0000 0 C= A.\B = 0.3000 2.0000 -1.0000 Inf C= A.^B= 100 4 1 0 C= A^B= 102 20 10 2

10 10 Problem Solving I Car TravelingTrip 1234 Speed(Km/hr)80120100130 Time(hr)22.553 Q1. What is the distance for each trip? Q2. What is the total distance for all trips? Q3. What is the average speed? Q4. Which trip spends the maximum time?

11 11 Problem Solving I >>Speed=[80 120 100 130]; >>Time =[2 2.5 5 3 ]; Q1. Speed.* Time = [160 300 500 390] Q2. Speed * Time ’ = 80(2)+120(2.5)+100(5)+130(3) = 1350 Q3. Average = sum(Speed)/4 = 107.5000 Q4. [MaxTime,Leg]= max(Time); MaxTime = 5 Leg = 3 Car TravelingTrip 1234 Speed(Km/hr)80120100130 Time(hr)22.553

12 12 Problem Solving II Manufacturing Cost Analysis 30427Welding 52352Milling 13236Grinding 45630Lathe Product 3Product 2Product 1Hourly Cost (Baht)Process Hours required to produce one unit Q1. What is the cost for each process to produce one unit of product 1? Q2. What is the total cost for each product? Q3. What is the cost of production for 5xproduct 1, 10xproduct 2, and 3xproduct 3 ?

13 13 Problem Solving II 30427Welding 52352Milling 13236Grinding 45630Lathe Product 3Product 2Product 1Hourly Cost (Baht)Process Hours required to produce one unit >>hourly_cost=[30 36 52 27]; >>hour1 =[6 2 3 4]; Q1. What is the cost for each process to produce one unit of product 1? >>process_cost1 = hourly_cost.* hour1; = [180 72 156 108]

14 14 Problem Solving II >>hourly_cost=[30 36 52 27]; >>hour1 =[6 2 3 4]; Q2. What is the total cost for each product? >>hour2 =[5 3 2 0]; >>hour3 =[4 1 5 3]; >>HOUR =[hour1’ hour2’ hour3’]; >>unit_cost = hourly_cost * HOUR; = [516 362 497] Q3. What is the cost of production for 5xproduct 1, 10xproduct 2, and 3xproduct 3 ? >>units = [5 10 3]; >>Total_cost = units * unit_cost’ = 7691


Download ppt "1 Matrix Operation ผศ. ดร. อนันต์ ผลเพิ่ม Anan Phonphoem"

Similar presentations


Ads by Google