1 / 14

Matrix Operation

Matrix Operation. ผศ.ดร.อนันต์ ผลเพิ่ม Anan Phonphoem http://www.cpe.ku.ac.th/~anan anan@cpe.ku.ac.th. Outline. Creating Matrices Matrix Transpose Array Addressing Array Functions Arithmetic Operators Problem Solving. Creating Matrices. >> A=[ 1 2 3 4 5; 6 7 8 9 10 ].

jenaya
Download Presentation

Matrix Operation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

  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:1:5; 6:1:10] >>A=[ 1:5; 6:10]

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

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

  6. Array Functions >> B = size(A) A = 7 3 12 -1 20 8 2 9 -4 0 2 6 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. 1 2 3 1 2 4 2 3 4 1 1 1 2 2 2 3 3 3 7 -1 2 3 20 2 8 -4 6 X = Y = Z = Array Functions >> % find non-zero elements >>[X,Y,Z] = find(B) B = 7 3 0 -1 20 8 2 0 -4 0 2 6

  8. Arithmetic Operators

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

  10. Problem Solving I 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. 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

  12. Manufacturing Cost Analysis Hours required to produce one unit Process Hourly Cost (Baht) Product 1 Product 2 Product 3 Lathe 30 6 5 4 Grinding 36 2 3 1 Milling 52 3 2 5 Welding 27 4 0 3 Problem Solving II 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. Hours required to produce one unit Process Hourly Cost (Baht) Product 1 Product 2 Product 3 Lathe 30 6 5 4 Grinding 36 2 3 1 Milling 52 3 2 5 Welding 27 4 0 3 Problem Solving II >>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. 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

More Related