0% found this document useful (0 votes)
131 views

Scilab Basics

The document demonstrates various operations on matrices in MATLAB such as creating, accessing, manipulating, and performing linear algebra operations on matrices. It defines several matrices A, B, C, D, etc. and performs operations like addition, multiplication, transpose, inverse, determinant, eigenvalues on them. It also demonstrates creation of identity and diagonal matrices, vector and matrix slicing, and arithmetic and statistical operations on vectors.

Uploaded by

rkjadriano
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views

Scilab Basics

The document demonstrates various operations on matrices in MATLAB such as creating, accessing, manipulating, and performing linear algebra operations on matrices. It defines several matrices A, B, C, D, etc. and performs operations like addition, multiplication, transpose, inverse, determinant, eigenvalues on them. It also demonstrates creation of identity and diagonal matrices, vector and matrix slicing, and arithmetic and statistical operations on vectors.

Uploaded by

rkjadriano
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

-->A=[1,-1,1,0;2,3,-1,2;-3,5,7,2]

A =
1. - 1.
1.
2.
3. - 1.
- 3.
5.
7.

0.
2.
2.

-->size(A)
ans =
3.

4.

-->A(1,1)
ans =

#gets element at row 1, col 1

1.
-->A(3,2)
ans =

#gets element at row 3, col 2

5.
-->B=[6,4,2,1;1,-1,1,1;0,1,1,2]
B =
6.
4.
1. - 1.
0.
1.

2.
1.
1.

1.
1.
2.

3.
2.
6.

3.
0.
8.

1.
3.
4.

3.
2.
6.

3.
0.
8.

1.
3.
4.

3.
2.
6.

3.
0.
8.

1.
3.
4.

6.
4.
1. - 1.
0.
1.

2.
1.
1.

1.
1.
2.

-->A+B
ans =
7.
3.
- 3.
-->C=A+B
C =
7.
3.
- 3.
-->ans
ans =
7.
3.
- 3.
-->B
B =

-->D=[2,6,1,4;1,2,-1,1;0,5,-7,2;1,2,1,4]

D =
2.
1.
0.
1.

6.
1.
2. - 1.
5. - 7.
2.
1.

4.
1.
2.
4.

-->D=[2,6,1,4;1,2,-1,1;0,5,-7,2;1,2,1,4];
-->D'
ans =
2.
1.
0.
6.
2.
5.
1. - 1. - 7.
4.
1.
2.

1.
2.
1.
4.

-->A'
ans =

#to get transposition

1.
2. - 3.
- 1.
3.
5.
1. - 1.
7.
0.
2.
2.
-->3*A
ans =
3. - 3.
3.
6.
9. - 3.
- 9.
15.
21.

0.
6.
6.

-->E=A*D
E =
1.
9.
1.

9. - 5.
17.
8.
31. - 55.

5.
17.
15.

-->F=A*B'
F =
4.
24.
18.

3.
0.
1.

0.
6.
16.

-->G=A*A'
G =

#notice that G is symmetrical

3. - 2. - 1.
- 2.
18.
6.
- 1.
6.
87.
-->A.*B
f the matrices
ans =
6. - 4.
2.
2. - 3. - 1.

#entry by entry multiplication o


#use period as operator (.)
0.
2.

0.

5.

7.

4.

-->1:7
ans =
1.

#creates row vector


2.

3.

4.

5.

6.

7.

-->(1:7)'
ans =

#creates col vector

1.
2.
3.
4.
5.
6.
7.
-->3:15
ans =
3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

14.

15.
-->2:3:11
to 11, with d=3
ans =
2.

5.

#arithmetic progression, from 2

8.

11.

-->2:3:12
ans =
2.

#same as 2:3:11
5.

8.

11.

-->2:3:15
ans =
2.

#same as 2:3:14
5.

8.

11.

14.

5.

8.

11.

14.

-->2:3:14
ans =
2.
-->X=[A,B]
X =

#augmented matrix [A|B]

1. - 1.
1.
2.
3. - 1.
- 3.
5.
7.

0.
2.
2.

-->Y=[A;B]
Y =
1. - 1.

6.
4.
1. - 1.
0.
1.

2.
1.
1.

1.
1.
2.
#augmented matrix [A over B]

1.

0.

2.
3. - 1.
- 3.
5.
7.
6.
4.
2.
1. - 1.
1.
0.
1.
1.

2.
2.
1.
1.
2.

-->X(2,3:6)
ans =
- 1.

2.

#elements in 2nd row, cols 3-6


1. - 1.

-->Y(3:5,2:4)
ans =
5.
4.
- 1.

7.
2.
1.

#partitioned matrix
2.
1.
1.

-->Y(2:4,:)
ans =
2.
- 3.
6.

#rows 2 to 4, all columns

3. - 1.
5.
7.
4.
2.

2.
2.
1.

-->trace(D)
ans =
1.
-->det(D)
ans =
75.
-->inv(D)
ans =
- 0.3333333
1.6 - 0.2666667
0.0666667
0.3333333 - 0.4
0.0666667 - 0.2666667
0.2
- 0.32 - 0.08
- 0.08
- 0.1333333 - 0.12
0.0533333
0.3866667
-->inv(F)
ans =
0.0070423
0.0563380 - 0.0211268
0.3239437 - 0.0751174
0.0281690
- 0.0281690 - 0.0586854
0.0845070
-->F*ans
ans =
1.
1.388D-17
0.

1.388D-17 - 6.939D-18
1.
0.
0.
1.

-->eye(3)
ize is parameter 3

#returns identity matrix whose s

ans =

#gives 1x1 matrix

1.
-->size(3)
ans =
1.

1.

-->eye(3,3)
3x3 identity matrix
ans =
1.
0.
0.

0.
1.
0.

#correct command for getting the

0.
0.
1.

-->eye(5,5)
ans =
1.
0.
0.
0.
0.

0.
1.
0.
0.
0.

0.
0.
1.
0.
0.

0.
0.
0.
1.
0.

0.
0.
0.
0.
1.

0.
0.
1.
0.

0.
0.
0.
1.

0.
0.
0.
0.

-->eye(4,5)
ans =
1.
0.
0.
0.

0.
1.
0.
0.

-->eye(7,3)
es
ans =
1.
0.
0.
0.
0.
0.
0.

0.
1.
0.
0.
0.
0.
0.

#reduced row-echelon form matric

0.
0.
1.
0.
0.
0.
0.

-->D
D =
2.
1.
0.
1.

6.
1.
2. - 1.
5. - 7.
2.
1.

4.
1.
2.
4.

-->eye(D)
ze is the same as of D
ans =
1.
0.

0.
1.

0.
0.

#return identity matrix whose si

0.
0.

0.
0.

0.
0.

1.
0.

0.
1.

-->spec(D)
ans =
of eigenvalues

#eigenvalues
#spectrum of a matrix is its set

- 6.4575057
6.7323421
- 1.
1.7251636
-->a=X(1,:)
a =
1. - 1.

1.

0.

6.

4.

2.

1.

-->sum(a)
vector
ans =

#adds all the elements from the

14.
-->sum(a')
ans =
14.
-->sum(A)
ans =
18.
-->mean(a)
ans =
1.75
-->a
a =
1. - 1.
-->sum(a)
ans =
14.
-->size(a)
ans =
1.
-->14/8
ans =
1.75

8.

1.

0.

6.

4.

2.

1.

-->variance(a)
ans =
5.0714286
-->sqrt(variance(a))
ans =
2.2519833
-->3^2
ans =
9.

SEE EXERCISES ON NOTEBOOK (one-liner commands)


(a.)
-->(1:7)
ans =
1.

2.

3.

4.

5.

6.

7.

-->(1:7).^3
ans =
1.

8.

27.

64.

125.

216.

343.

-->sum((1:7).^3)
ans =
784.
-->sum((1:7).^3)/43
ans =
18.232558
(b.)
-->sum(((1/1000*(0:999)).^2)*1/1000)
ans =
0.3328335
-->sum(((1/15000*(0:14999)).^2)*1/15000)
ans =
0.3333

#1/3=0.333...

You might also like