Title: Matrix Operation
1Matrix Operation
- ??.??.?????? ???????
- Anan Phonphoem
- http//www.cpe.ku.ac.th/anan
- anan_at_cpe.ku.ac.th
2Outline
- Creating Matrices
- Matrix Transpose
- Array Addressing
- Array Functions
- Arithmetic Operators
- Problem Solving
3Creating Matrices
gtgtA 1 2 3 4 5 6 7 8 9 10
gtgtA 1,2,3,4,5 6,7,8,9,10
gtgtA1 2 3 4 5 6 7 8 9 10
A 1 2 3 4 5 6 7
8 9 10
gtgtA1 2 3 4 5 6 7 8 9 10
gtgtA 115 6110
gtgtA 15 610
4Transpose
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
gtgtB A
B AT Size of B 5X2
5Array Addressing
gtgtA(2)
6
A 1 2 3 4 5 6 7
8 9 10
gtgtA(3)
2
6 2 7 3
gtgtA(25)
gtgtA(,2)
2 7
gtgtA(2,)
6 7 8 9 10
gtgtB A(12,45)
4 5 9 10
6Array Functions
gtgt B size(A)
A 7 3 12 -1 20 8 2
9 -4 0 2 6
B 4 3
gtgt B max(A)
B 7 20 12
gtgt B min(A)
B -1 2 -4
gtgt B sum(A)
B 8 34 22
7Array Functions
gtgt find non-zero elements gtgt X,Y,Z find(B)
B 7 3 0 -1 20 8 2
0 -4 0 2 6
8Arithmetic Operators
Operator Description Example
Plus S T
Unary plus 3
- Minus S T
- Unary minus -C
Matrix Multiply S T
. Array Multiply (member) S . T
/ Left Matrix Divide (SINV(T)) S / T
./ Left Array Divide S ./ T
\ Right Matrix Divide (INV(S)T) S \ T
.\ Right Array Divide S .\ T
Matrix Power S 2
. Array Power S . 3
9Element-by-Element Operation
10Problem Solving I
Car Traveling Trip Trip Trip Trip
Car Traveling 1 2 3 4
Speed(Km/hr) 80 120 100 130
Time(hr) 2 2.5 5 3
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?
11Problem Solving I
gtgtSpeed80 120 100 130 gtgtTime 2 2.5 5 3
Car Traveling Trip Trip Trip Trip
Car Traveling 1 2 3 4
Speed(Km/hr) 80 120 100 130
Time(hr) 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
12Problem 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 ?
13Problem Solving II
gtgthourly_cost30 36 52 27 gtgthour1 6 2 3
4 Q1. What is the cost for each process to
produce one unit of product 1?
gtgtprocess_cost1 hourly_cost . hour1
180 72 156 108
14Problem Solving II
gtgthourly_cost30 36 52 27 gtgthour1 6 2 3
4 Q2. What is the total cost for each product?
gtgthour2 5 3 2 0 gtgthour3 4 1 5 3
gtgtHOUR hour1 hour2 hour3
gtgtunit_cost hourly_cost HOUR
516 362 497 Q3. What is the cost of
production for 5xproduct 1, 10xproduct 2,
and 3xproduct 3 ? gtgtunits 5 10 3
gtgtTotal_cost units unit_cost 7691