You are on page 1of 15

ACTIVITY NO.

1
MATRIX OPERATIONS AND DETERMINANTS
OBJECTIVES:
To understand the different commands in Scilab
To know how to create/manipulate matrices in Scilab.
To know how to compute the determinants using different methods
such as Elementary Row/Column operations, Chios Method, and
Laplaces Expansion
PROCEDURE:
Part I. Matrix Operations
Consider the following matrices:
A=[

D=[

B=[

C=[

E=
[

Note: Write the Scilab code/command and the respective output for every item.
Evaluate the following:
1.
2.
3.
4.
5.
6.
7.

B(AC)
ACB
D+BAC
( BT CT ) AT
( B C )T + DT
Recreate matrix E using the Colon Operator.
Generate three 4x4 matrices from the elements of E. Store them under F, G,
H.
8. Generate the following matrix using the special matrices eye ( ), ones ( ), and
zeros ( ).

J=
[

Part II. Elementary Column and Row Operator


Let K = E 3 (eye (6, 6)-2*ones (6, 6))
9. Create an upper triangular matrix using series of row operations. Write the
code/command and the respective output in every step of the computation.
Note: Comments can be written using the // symbols.
i.e.

- - > A = 5 // this is comment

Part III. Determinants


Consider the matrix K. Evaluate the determinant of K.
10. Using the DET ( ) function.
11. Using the Elementary Row/Column operations
12. Using Laplace Expansions
13. Using Chios Method
Note: Show the command and the output for every step of the solution for 11,
12, and 13.

DATA AND RESULTS


Part I.
1)
B (A C)
-->B*(A*C)
ans =
2388.
356.
247.

1092.
- 43.
880.

- 2228.
- 277.
- 436.

2) A C B
-->A-C*B
ans =
- 70.
148.

193.
45.

3) D + B A C
-->D+B*A*C
ans =
2393.
359.
243.

1077.
- 50.
888.

493.
261.
- 665.

4) ( BT CT ) AT
-->(B'*C')*A'
ans =
1083.
- 1466.

- 2073.
606.

5) ( B C )T + DT
-->(B*C)'+D'
ans =
201.
49.
65.

50.
- 26.
45.

- 50.
121.
- 142.

6) Matrix E using the Colon Operator


-->E=[1:6:31;2:6:32;3:6:33;4:6:34;5:6:35;6:6:36]
E =
1.
2.
3.
4.
5.
6.

7.
8.
9.
10.
11.
12.

13.
14.
15.
16.
17.
18.

19.
20.
21.
22.
23.
24.

25.
26.
27.
28.
29.
30.

31.
32.
33.
34.
35.
36.

OR

-->E=[E(1,:);E(2,:);E(3,:);E(4,:);E(5,:);E(6,:)]
E =
1.
2.
3.
4.
5.
6.

7.
8.
9.
10.
11.
12.

13.
14.
15.
16.
17.
18.

19.
20.
21.
22.
23.
24.

25.
26.
27.
28.
29.
30.

31.
32.
33.
34.
35.
36.

7) Three 4x4 matrices from the elements of E

-->G=E([1,2],:);E(:,[3,2])=[]
E =
3.
4.
5.
6.

21.
22.
23.
24.

27.
28.
29.
30.

33.
34.
35.
36.

-->F=E([2,5],:);E([2,3],:)=[]
E =
1.
4.
5.
6.

19.
22.
23.
24.

25.
28.
29.
30.

31.
34.
35.
36.

-->H=E(1:4,1:4)
H =
1.
2.
3.
4.

7.
8.
9.
10.

13.
14.
15.
16.

19.
20.
21.
22.

8) Eye( ), Ones ( ), and Zeros ( )


-->J=(zeros(5,5)+8*eye(5,5)
+3*ones(5,5)+sparse([1,5;2,4;4,2;5,1;3,3],[2,2,2,2,5]))
J =
- 5.
3.
3.
3.
5.

3.
- 5.
3.
5.
3.

3.
3.
0.
3.
3.

3.
5.
3.
- 5.
3.

5.
3.
3.
3.
- 5.

(From Scilab Help)


*sparse - is used to build a sparse matrix. Only non-zero entries are stored.
sp = sparse(X) converts a full matrix to sparse form by squeezing out any zero elements.
(If X is already sparse sp is X).
sp=sparse(ij,v [,mn]) builds an mn(1)-by-mn(2) sparse matrix
sp(ij(k,1),ij(k,2))=v(k)
ij and v must have the same column dimension. If optionalmn parameter is not

Part II.
9) Upper triangular matrix using series of row operations
K= E 3 (eye (6, 6)-2*ones (6, 6))
-->K=E-3*(eye(6,6)-2*ones(6,6))
K =
4.
8.
9.
10.
11.
12.

13.
11.
15.
16.
17.
18.

19.
20.
18.
22.
23.
24.

25.
26.
27.
25.
29.
30.

31.
32.
33.
34.
32.
36.

37.
38.
39.
40.
41.
39.

--> K(2,:)=K(2,:)-2*K(1,:)
K =
4.
0.
9.
10.
11.
12.

13.
- 15.
15.
16.
17.
18.

19.
- 18.
18.
22.
23.
24.

25.
- 24.
27.
25.
29.
30.

31.
- 30.
33.
34.
32.
36.

37.
- 36.
39.
40.
41.
39.

--> K(3,:)=K(3,:)-9/4*K(1,:)
K =
4.
0.
0.
10.
11.
12.

13.
- 15.
- 14.25
16.
17.
18.

19.
- 18.
- 24.75
22.
23.
24.

25.
- 24.
- 29.25
25.
29.
30.

31.
- 30.
- 36.75
34.
32.
36.

37.
- 36.
- 44.25
40.
41.
39.

31.
- 30.
- 36.75
- 43.5
32.
36.

37.
- 36.
- 44.25
- 52.5
41.
39.

--> K(4,:)=K(4,:)-5/2*K(1,:)
K =
4.
0.
0.
0.
11.
12.

13.
- 15.
- 14.25
- 16.5
17.
18.

19.
- 18.
- 24.75
- 25.5
23.
24.

25.
- 24.
- 29.25
- 37.5
29.
30.

--> K(5,:)=K(5,:)-11/4*K(1,:)
K =
4.
0.
0.
0.
0.
12.

13.
15.
14.25
16.5
18.75
18.

19.
18.
24.75
25.5
29.25
24.

25.
24.
29.25
37.5
39.75
30.

31.
30.
36.75
43.5
53.25
36.

37.
36.
44.25
52.5
60.75
39.

-->K(6,:)=K(6,:)-3*K(1,:)
K =
4.
0.
0.
0.
0.
0.

13.
15.
14.25
16.5
18.75
21.

19.
18.
24.75
25.5
29.25
33.

25.
24.
29.25
37.5
39.75
45.

31.
30.
36.75
43.5
53.25
57.

37.
36.
44.25
52.5
60.75
72.

-->K(3,:)=K(3,:)-19/20*K(2,:)
K =
4.
0.
0.
0.
0.
0.

13.
- 15.
0.
- 16.5
- 18.75
- 21.

19.
18.
7.65
25.5
29.25
33.

25.
24.
6.45
37.5
39.75
45.

31.
30.
8.25
43.5
53.25
57.

37.
36.
10.05
52.5
60.75
72.

--> K(4,:)=K(4,:)-11/10*K(2,:)
K =
4.
0.
0.
0.
0.
0.

13.
- 15.
0.
0.
- 18.75
- 21.

19.
18.
7.65
5.7
29.25
33.

25.
24.
6.45
11.1
39.75
45.

31.
30.
8.25
10.5
53.25
57.

37.
36.
10.05
12.9
60.75
72.

-->K(5,:)=K(5,:)-5/4*K(2,:)
K =
4.
0.
0.
0.
0.
0.

13.
- 15.
0.
0.
0.
- 21.

19.
18.
7.65
5.7
6.75
33.

25.
24.
6.45
11.1
9.75
45.

31.
30.
8.25
10.5
15.75
57.

37.
36.
10.05
12.9
15.75
72.

31.
30.
8.25
10.5
15.75
15.

37.
36.
10.05
12.9
15.75
21.6

31.
30.
8.25
10.5
15.75
15.

37.
36.
10.05
12.9
15.75
21.6

--> K(6,:)=K(6,:)-7/5*K(2,:)
K =
4.
0.
0.
0.
0.
0.

13.
- 15.
0.
0.
0.
0.

19.
18.
7.65
5.7
6.75
7.8

25.
24.
6.45
11.1
9.75
11.4

--> K(6,:)=K(6,:)-7/5*K(2,:)
K =
4.
0.
0.
0.
0.
0.

13.
- 15.
0.
0.
0.
0.

19.
18.
7.65
5.7
6.75
7.8

25.
24.
6.45
11.1
9.75
11.4

--> K(4,:)=K(4,:)-38/51*K(3,:)
K =
4.
0.
0.
0.
0.
0.

13.
- 15.
0.
0.
0.
0.

19.
- 18.
- 7.65
2.665D-15
- 6.75
- 7.8

25.
24.
6.45
6.2941176
9.75
11.4

31.
30.
8.25
4.3529412
15.75
15.

37.
36.
10.05
5.4117647
15.75
21.6

31.
30.
8.25
4.3529412
8.4705882
15.

37.
36.
10.05
5.4117647
6.8823529
21.6

31.
30.
8.25
4.3529412
8.4705882
8.6775701

37.
36.
10.05
5.4117647
6.8823529
13.898131

31.
30.
8.25
4.3529412
5.6635514
8.6775701

37.
36.
10.05
5.4117647
3.3925234
13.898131

--> K(5,:)=K(5,:)-15/17*K(3,:)
K =
4.
0.
0.
0.
0.
0.

13.
- 15.
0.
0.
0.
0.

19.
- 18.
- 7.65
2.665D-15
1.776D-15
- 7.8

25.
24.
6.45
6.2941176
4.0588235
11.4

--> K(6,:)=K(6,:)-82/107*K(3,:)
K =
4.
0.
0.
0.
0.
0.

13.
- 15.
0.
0.
0.
0.

19.
- 18.
- 7.65
2.665D-15
1.776D-15
- 1.9373832

25.
24.
6.45
6.2941176
4.0588235
6.4570093

-->K(5,:)=K(5,:)-69/107*K(4,:)
K =
4.
0.
0.
0.
0.
0.

13.
- 15.
0.
0.
0.
0.

19.
- 18.
- 7.65
2.665D-15
5.811D-17
- 1.9373832

25.
24.
6.45
6.2941176
8.882D-16
6.4570093

-->K(6,:)=K(6,:)-58/101*K(5,:)
K =
4.
0.
0.
0.
0.
0.

13.
- 15.
0.
0.
0.
0.

19.
- 18.
- 7.65
2.665D-15
5.811D-17
- 1.187D-15

25.
- 24.
- 6.45
- 6.2941176
9.346D-10
2.376D-08

31.
30.
8.25
4.3529412
5.6635514
3.109D-08

37.
36.
10.05
5.4117647
3.3925234
5.2574258

*The following values:


2.665D-15, 5.811D-17,- 1.187D-15, 9.346D-10 2.376D-08, and 3.109D-08 are equal to zero. Since Scilab cannot show the true
value, we can verify it by solving it manually or we can try it
on Matlab also.
Part III.

10) DET( ) function


-->K
K =
4.
8.
9.
10.
11.
12.

13.
11.
15.
16.
17.
18.

19.
20.
18.
22.
23.
24.

25.
26.
27.
25.
29.
30.

31.
32.
33.
34.
32.
36.

37.
38.
39.
40.
41.
39.

-->det(K)
ans =
- 86022.

11) Elementary Row/Column operations


*we obtained the value of K (Refer to answer #9), then we can get its
determinant by getting the product of its diagonal :

-->diag(K)
K =
-

4.
15.
7.65
6.2941176
5.6635514
5.2574258

-->prod(K)
ans =
- 86022.

12) Laplace Expansions


-->E
E =
1.

7.

13.

19.

25.

31.

2.

8.

14.

20.

26.

32.

3.

9.

15.

21.

27.

33.

4.

10.

16.

22.

28.

34.

5.

11.

17.

23.

29.

35.

6.

12.

18.

24.

30.

36.

-->K
K =
4.

13.

19.

25.

31.

37.

8.

11.

20.

26.

32.

38.

9.

15.

18.

27.

33.

39.

10.

16.

22.

25.

34.

40.

11.

17.

23.

29.

32.

41.

12.
18.
24.
30.
36.
-->L= K(2:6, 1:6) // Select R1
L =

39.

8.

11.

20.

26.

32.

38.

9.

15.

18.

27.

33.

39.

10.

16.

22.

25.

34.

40.

11.

17.

23.

29.

32.

41.

12.
18.
24.
30.
36.
39.
-->P= L(1:$,2:$)//Cofactor for L11
P=
11.

20.

26.

32.

38.

15.

18.

27.

33.

39.

16.

22.

25.

34.

40.

17.

23.

29.

32.

41.

18.

24.

30.

36.

39.

-->M=(((-1)^(1+1))*(4))*det(P)
M =
76788.
-->N=(((-1)^(1+2))*(13))*det([8 20 26 3238;9
18 27 33 39;10 22 25 34 40; 11 23 29 32
41;12 24 30 36 39]) // Cofactor for L12
N =
-92664.

-->Q= (-1)^3*(19)*det([8 11 26 32 38;9 15


27 33 39;10 16 25 34 40; 11 17 29 32 41;12
18 30 36 39]) // Cofactor for L13
Q =
90801.
-->R=((-1)^(1+4))*(25)*det([8 11 20 32
38;9 15 18 33 39;10 16 22 34 40; 11 17 23
32 41;12 18 24 36 39]) // Cofactor for L14
R =
-60750.
-->S=((-1)^(1+5))*(31)*det([8 11 20 26
38;9 15 18 27 39;10 16 22 25 40; 11 17 23
29 41;12 18 24 30 39]) // Cofactor for L15
S =
-2511.
-->T=L(1:$,1:5)//Cofactor for L16
T =
8.

11.

20.

26.

32.

9.

15.

18.

27.

33.

10.

16.

22.

25.

34.

11.

17.

23.

29.

32.

12.

18.

24.

30.

36.

-->U=M+N+R+Q+S+T //Determinant of K
U =
- 86022.

13) Chios Method

E=[1 7 13 19 25 31;2 8 14 20 26 32;3 9 15 21 27 33;4


10 16 22 28 34;5 11 17 23 29 35;6 12 18 24 30 36]
E =
1.
2.
3.
4.
5.
6.

7.
8.
9.
10.
11.
12.

13.
14.
15.
16.
17.
18.

19.
20.
21.
22.
23.
24.

25.
26.
27.
28.
29.
30.

31.
32.
33.
34.
35.
36.

=
4.
8.
9.
10.
11.
12.

13.
11.
15.
16.
17.
18.

19.
20.
18.
22.
23.
24.

25.
26.
27.
25.
29.
30.

31.
32.
33.
34.
32.
36.

37.
38.
39.
40.
41.
39.

K1=1/(K(1,1)^(size(K,2)-2))
K1 =
0.0039063
K=[det(K(1:2,1:2))det(K(1:2,1:2:3))
det(K(1:2,1:3:4))det(K(1:2,1:4:5))
det(K(1:2,1:5:6));det(K(1:2:3,1:2))
det(K(1:2:3,1:2:3))det(K(1:2:3,1:3:4))
det(K(1:2:3,1:4:5))det(K(1:2:3,1:5:6));
det(K(1:3:4,1:2))det(K(1:3:4,1:2:3))
det(K(1:3:4,1:3:4))det(K(1:3:4,1:4:5))
det(K(1:3:4,1:5:6));det(K(1:4:5,1:2))
det(K(1:4:5,1:2:3))det(K(1:4:5,1:3:4))
det(K(1:4:5,1:4:5))det(K(1:4:5,1:5:6));
det(K(1:5:6,1:2))det(K(1:5:6,1:2:3))
det(K(1:5:6,1:3:4))det(K(1:5:6,1:4:5))
det(K(1:5:6,1:5:6))]
K =
-

60.
57.
66.
75.
84.

72.
99.
102.
117.
132.

96.
117.
150.
159.
180.

120.
147.
174.
213.
228.

144.
177.
210.
243.
288.

K1=K1*(1/(K(1,1))^(size(K,2)-2))
K1 =
- 1.808D-08
K=[det(K(1:2,1:2))det(K(1:2,1:2:3))
det(K(1:2,1:3:4))det(K(1:2,1:4:5));
det(K(1:2:3,1:2))det(K(1:2:3,1:2:3))
det(K(1:2:3,1:3:4))det(K(1:2:3,1:4:5));
det(K(1:3:4,1:2))det(K(1:3:4,1:2:3))
det(K(1:3:4,1:3:4))det(K(1:3:4,1:4:5));
det(K(1:4:5,1:2))det(K(1:4:5,1:2:3))
det(K(1:4:5,1:3:4))det(K(1:4:5,1:4:5))]
K =
1836.
1368.
1620.
1872.

1548.
2664.
2340.
2736.

1980.
2520.
3780.
3600.

2412.
3096.
3780.
5184.

K1=K1*(1/(K(1,1))^(size(K,2)-2))
K1 =
- 5.365D-15
K=[det(K(1:2,1:2))det(K(1:2,1:2:3))
det(K(1:2,1:3:4));det(K(1:2:3,1:2))
det(K(1:2:3,1:2:3))det(K(1:2:3,1:3:4));
det(K(1:3:4,1:2))det(K(1:3:4,1:2:3))
det(K(1:3:4,1:3:4))]
K =
2773440.
1788480.
2125440.

1918080.
3732480.
2903040.

K1=K1*(1/(K(1,1))^(size(K,2)-2))
K1 =
- 1.934D-21

2384640.
3032640.
5002560.

K=[det(K(1:2,1:2)) det(K(1:2,1:2:3));
det(K(1:2:3,1:2))det(K(1:2:3,1:2:3))]
K =
10^12 *
6.9213616
3.9746433

4.1459641
8.8058908

K1=K1*(1/(K(1,1))^(size(K,2)-2))
K1 =
- 1.934D-21
det(K)*K1
ans =
- 86022.
*The following values are - 1.934D-21,- 5.365D-15, and- 1.808D-08 considered error in
Scilab but these are equal to zero.

RECOMMENDATION
We recommend the following in conducting this activity:

Before performing it in Scilab, solve the matrices/determinants first because in


some instances the Scilab cannot display the true output.

Avoid using same variables for the representations because it will overwrite the
data obtained from the previous computation/s.

Make sure that the values entered are correct for the matrices to avoid incorrect
outputs. Include also the proper commas, parenthesis, brackets, colons and
semicolons to obtain the desired output.

Be familiar with the different codes or syntax to lessen the time being consumed
in getting the outputs. Using different techniques like the identities can also
make the task easier and simpler.

If you want to use the previous command/syntax you entered, just press the
up arrow button and you can use it again or edit without retyping it.

Whenever you encounter problem/s, press F1 for the Scilab help in order to
know some information regarding certain topic or specific command.

If there is no function available for the syntax you needed, you may create your
another function.

This activity may be performed in Matlab to compare or verify the answers


obtained in Scilab.

You might also like