0% found this document useful (0 votes)
69 views14 pages

2004 03 Matrix Operation

Problem Solving Creating Matrices Matrix Transpose Array Addressing Array Functions Arithmetic Operators Operator + +. /. +. . + Unary plus Minus Unary minus Matrix Multiply Array Multiply (member) Left Matrix Divide Left Array Divide (INV(S) T) Right Array Divide Matrix Power (S INV(T))

Uploaded by

Serban Dg
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views14 pages

2004 03 Matrix Operation

Problem Solving Creating Matrices Matrix Transpose Array Addressing Array Functions Arithmetic Operators Operator + +. /. +. . + Unary plus Minus Unary minus Matrix Multiply Array Multiply (member) Left Matrix Divide Left Array Divide (INV(S) T) Right Array Divide Matrix Power (S INV(T))

Uploaded by

Serban Dg
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 14

Matrix Operation

.. Anan Phonphoem http://www.cpe.ku.ac.th/~anan [email protected]


1

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 ] >>A=[ 1,2,3,4,5; 6,7,8,9,10 ] >>A=[1 2 3 4 5 A= 6 7 8 9 10] >>A=[1 2 3 1 45 6 6789 10] >>A=[ 1:1:5; 6:1:10]
>>A=[ 1:5; 6:10]
3

2 7

3 8

4 9

5 10

Transpose
A=

Size of A = 2X5
2 7 3 8 4 9 5 10

1 6

B = AT Size of B = 5X2

B=
1 2 3 4 5 6 7 8 9 10

>>B = A

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

>>A(2,:)

>>B = A(1:2,4:5)

4 5 9 10

Array Functions
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 ]

Array Functions
B= 7 3 0 -1 20 8 2 0 -4 0 2 6

>> % find non-zero elements >> [X,Y,Z] = find(B)


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
7

X=

Y=

Z=

Arithmetic Operators
Operator
+ + * .* / ./ \ .\ ^ .^ Plus Unary plus Minus Unary minus Matrix Multiply Array Multiply (member) Left Matrix Divide Left Array Divide Right Matrix Divide (INV(S)*T) Right Array Divide Matrix Power Array Power (S*INV(T))

Description

Example
S+T +3 ST -C S*T S .* T S/T S ./ T S\T S .\ T S^2 S .^ 3
8

Element-by-Element Operation
A= 10 2 1 0 B= 3 4 -1 5

C= A.*B =

30 8 -1 0

3.3333 0.5000 C= A./B = -1.0000 0 0.3000 2.0000 C= A.\B = -1.0000 Inf 100 C= A.^B= 1 C= A^B= 4 0

C= A+2 = C= A+B = C= A-B =

12 4 3 2 13 6 0 5

7 -2 2 -5

102 20 10 2
9

Problem Solving I
Car Traveling 1 Speed(Km/hr) Time(hr) 80 2 2 120 2.5 Trip 3 100 5 4 130 3

Q1. Q2. Q3. Q4.

What is the distance for each trip? What is the total distance for all trips? What is the average speed? Which trip spends the maximum time?

10

Problem Solving I
Car Traveling
1 Speed(Km/hr) Time(hr) 80 2 2 120 2.5

Trip
3 100 5 4 130 3

>>Speed=[80 120 100 130]; >>Time =[2 2.5 5 3 ];

Q1. Q2. Q3. Q4.

Speed .* Time = [160 300 500 390] Speed * Time = 80(2)+120(2.5)+100(5)+130(3) = 1350 Average = sum(Speed)/4 = 107.5000 [MaxTime,Leg]= max(Time); MaxTime = 5 Leg =3
11

Problem Solving II
Manufacturing Cost Analysis
Hours required to produce one unit Process Lathe Grinding Hourly Cost (Baht) 30 36 Product 1 6 2 Product 2 5 3 Product 3 4 1

Milling
Welding

52
27

3
4

2
0

5
3

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 ?
12

Problem Solving II
Hours required to produce one unit Process Hourly Cost (Baht) Product 1 Product 2 Product 3

Lathe
Grinding Milling Welding

30
36 52 27

6
2 3 4

5
3 2 0

4
1 5 3

>>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]
13

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
14

You might also like