Introduction to Matlab+EXPERIMENT 1
Introduction to Matlab+EXPERIMENT 1
8
ETC 324: Information Theory and coding 2018
OUTPUT: X =
1 2 3
4 5 6
Y=
6 5 4
3 2 1
F=
7 7 7
7 7 7
7) X is row vector, change it to column vector.
COMMAND: Z = X'
OUTPUT: Z =
1 4
2 5
3 6
8) Generate the following matrix
COMMAND: A=[1,2,3;4,5,6;7,8,9]
C=[1^3,2+sqrt(3),3*sin(1);exp(2),17/3,pi+3;1/3,2-sqrt(3),-7*cos(pi/7)]
x=[1 2 3 4 5 6]'
OUTPUT: A=
1 2 3
4 5 6
7 8 9
9
ETC 324: Information Theory and coding 2018
C=
1.0000 3.7321 2.5244
7.3891 5.6667 6.1416
0.3333 0.2679 -6.3068
x=
1
2
3
4
5
6
9) Generate 5x3 matrix whose first three rows are rows of A and last two rows are all ones.
COMMAND: w=[A;ones(2,3)]
OUTPUT: w=
1 2 3
4 5 6
7 8 9
1 1 1
1 1 1
10
ETC 324: Information Theory and coding 2018
F=
1 1 5 10 1 1
2 2 5 10 2 2
5 10 1 1 5 10
5 10 2 2 5 10
G=
1.0000 1.0000 5.0000 10.0000 1.0000 1.0000 0.8147
2.0000 2.0000 5.0000 10.0000 2.0000 2.0000 0.9058
5.0000 10.0000 1.0000 1.0000 5.0000 10.0000 0.1270
5.0000 10.0000 2.0000 2.0000 5.0000 10.0000 0.9134
(10) Using matrix A, find 1.A(1) 2. A(2) 3. A(9) 4. A(1,1) 5. A(2,1) 6. A(1,2) 7. A(1:3, 2)
8. A([1 3 4], [1 3]) 9. a = A(:, 2) 10. a = A(:) 11. A(2,end)
11
ETC 324: Information Theory and coding 2018
12
ETC 324: Information Theory and coding 2018
OUTPUT: Z=
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
Z=
1 2 6
7 8 12
13 14 18
19 20 24
25 26 30
31 32 36
13
ETC 324: Information Theory and coding 2018
EXPERIMENT NO. 1
Determination of Entropy
Conclusion:
Program:
(1)% Find entropy of the source
clc;
clear all;
close all;
i=input('Enter no. of elements=');
p=input('Enter probabilities=');
sum=0;
for n=1:i
H=sum+(p(n)*log2(1/p(n)));
sum=H;
end
disp('H(x): ');
disp(H);
output:
Enter no. of elements=2
Enter probabilities=[2/3,4/5]
H(x):
0.6475
14