Documente Academic
Documente Profesional
Documente Cultură
Date: 22/1/18
Aim:
To understand arithmetic and simple matrix operations using SCILAB.
4) - - > y=[1;2;5]
y=
1.
2.
5.
5) - - > z=[2 1 3]
z=
1. 1. 3.
9) - - > k=[2]
k=
2.
- - > a.*k ans=
4. 4. 18.
16) Try equation of straight line y=mx+c in SCILAB where m and c are constant which are slope and
intercept m=0.5, c=2 compute y coordinates of line for given slope and intercept x= co-ordinates
given below
- - > x=[0 1.5 3 4 5 7 9 10]
x=
0 1.5 3. 4. 5. 7. 9. 10.
- - > m=[0.5]
m=
0.5
- - > c=[2]
c=
2.
- - > y=[m.*x+c]
y=
2. 2.75 3.5 4. 4.5 5.5 6.5 7.
b) - - > y=[(t-1)/(t+1)]
y=
0. 0.333333 0.5 0.6 0.666667
0.7142852 0.75 0.777778 0.8
0.8181818
c) - - > z=sin(t.^2)/(t.^2)
z=
0.81414710 -0.1892006 0.457904
-0.0179940 -0.0052941 -0.0275494
-0.0194643 0.6143754 -0.607764
-0.0050637
c) Length of t
- - > length(t)
ans=
11.
d) Size of t
- - > size(t)
ans=
0. 11.
-->size(A)
ans =
3. 3.
-->y=int(rand(3,3)*100)
y =
6. 72. 23.
56. 19. 23.
66. 54. 21.
To solve above equation matrix can be used to do so, it can write above equation in the matrix form
as
5x-3y+2z=10
-3x+8y+4z=20
2x+4y-9z=9
24)
Ans. -->clear.
26) When do you think it is useful to use semicolon (;)?
Ans. -->B=A(:,$)
31) Replace the even numbered columns of matrix A having 3X5 with ones.
Ans. -->a=eye(x,y)
b. Diagonal matrix
Ans. -->a=diag(x)
c. Determinant of square matrix
Ans. -->det(a)
Ans. -->sqrt(a)
1. 2. 3. 12. []
4. 5.
6. 7. 8. -->y(3,2) -->size(a)
9. 10. ans = ans =
11. 12. 13.
14. 15. 12. 0. 0.
-->size(y) -->y(1,5)
ans = ans = -->a=[1 2 3;4 5 6]
a =
3. 5. 5.
1. 2. 3.
-->length(y) -->1:5 4. 5. 6.
ans = ans =
-->b=a(2,2)
15. 1. 2. 3. b =
4. 5.
-->y(1) 5.
ans =
-->a=[1:5] -->a(2,2)=100
1. a = a =
-->y(2) 1. 2. 3. 1. 2. 3.
ans = 4. 5. 4. 100. 6.
6. -->c=[0:2:10]
c =
0. 2. 4.
6. 8. 10.
-->a(3:4,2:5)=zeros(2,4)
a = -->a=rand(5,3)
a =
66. 6. 54. 65.
36. 59. 40. 41. 0.1121355 0.4062025
62. 56. 23. 30. 0.5618661
29. 50. 91. 28. 0.6856896 0.4094825
84. 0. 0. 0. 0.5896177
0. 43. 4. 12. 0.1531217 0.8784126
68. 0. 0. 0. 0.6853980
0. 26. 48. 77. 0.6970851 0.1138360
87. 19. 88. 31. 0.8906225
33. 63. 26. 21. 0.8415518 0.1998338
0.5042213
-->c=a(:,2:3)
c =
-->s=sum(a,'r')
6. 54. s =
56. 23.
0. 0. 2.4895836 2.0077673
0. 0. 3.2317255
19. 88.
-->p=sum(a,'c')
-->a(3:4,2:5)=b(1:2,1:4) p =
a =
1.080204
66. 6. 54. 65. 1.6847899
36. 59. 40. 41. 1.7169322
62. 56. 23. 30. 1.7015435
29. 50. 91. 28. 1.5456069
-->a(:,3:$) -->sd=stdev(a,1)
ans = sd =
Result:
Thus, we practiced and understood the following operations in SCILAB:
a. Creating matrices and simple matrix operations
b. Sub-matrices