0% found this document useful (0 votes)
11 views7 pages

Introduction to Matlab+EXPERIMENT 1

Uploaded by

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

Introduction to Matlab+EXPERIMENT 1

Uploaded by

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

ETC 324: Information Theory and coding 2018

INTRODUCTION TO MATLAB- PREREQUISITE


Q. Solve the following using Matlab commands:

1) Generate and Display a sequence of 10 numbers.


COMMAND: V = 1:1:10
OUTPUT: V =
1 2 3 4 5 6 7 8 9 10
2) Display a sequene of 20 numbers with an interval of 2
COMMAND: B = 1:2:40
OUTPUT: B =
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
3) Write a row vector
COMMAND: C = [1,2,3,4]
OUTPUT: C=
1 2 3 4
4) Write a Column vector
COMMAND: D = [1;2;3;4]
OUTPUT: D = 1
2
3
4
5) Write a matrix 3*3
COMMAND: E = [1,2,3;4,5,6;7,8,9]
OUTPUT: E =
1 2 3
4 5 6
7 8 9
6) Add 2 Matrix.
COMMAND: X = [1,2,3;4,5,6] ; Y = [6,5,4;3,2,1]
F = X+Y

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

(3) What happens: (1) B = A; B(3,3) = 10; (2) x = [1:50] ’; x(length(x))


(3) D = [1 1; 2 2]
E = [5 10; 5 10]
F = [D E D; E D E]
G = [F, rand(4,1) ]
COMMAND: 1 ) B = A; B(3,3) = 10; (2) x = [1:50] ’; x(length(x))
(3) D = [1 1; 2 2]
E = [5 10; 5 10]
F = [D E D; E D E]
G = [F, rand(4,1) ]
OUTPUT: (1) B =
1 2 3
4 5 6
7 8 10
(2) ans =
50
(3) D =
1 1
2 2
E=
5 10
5 10

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)

COMMAND: 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 ], [1 3]) 9. a = A(:, 2) 10. a = A(:) 11. A(2,end)
OUTPUT:
1 ans =
1 9. a =
2.ans = 2
4 5
3.ans = 8
9
4.ans = 10. a =
1 1
5.ans = 4
2 7
6.ans = 2
4 5
7.ans = 8
2 3
5 6
8 9
8.ans = 11. ans =
1 3 6
7 9

11
ETC 324: Information Theory and coding 2018

11) Create a 3x4 matrix for the following


1. random matrix 2. zero matrix 3. ones matrix 4. identity matrix
COMMAND: 1. rand(3,4) 2.zeros(3,4) 3.ones(3,4) 4. eye(3,4)
OUTPUT: 1. ans =
0.6324 0.5469 0.1576 0.4854
0.0975 0.9575 0.9706 0.8003
0.2785 0.9649 0.9572 0.1419
2.ans =
0 0 0 0
0 0 0 0
0 0 0 0
3.ans =
1 1 1 1
1 1 1 1
1 1 1 1
4.ans =
1 0 0 0
0 1 0 0
0 0 1 0

12) Create a magic matrix of 3x3.


COMMAND: MAGIC(3)
OUTPUT: 8 1 6
3 5 7
4 9 2

13) Create 3D 3x3 ones matrix.


COMMAND: y=ones(3,3,3)
OUTPUT: y(:,:,1) =
1 1 1
1 1 1
1 1 1
y(:,:,2) =
1 1 1
1 1 1
1 1 1
y(:,:,3) =
1 1 1
1 1 1
1 1 1
14) Write command to delete second row of A.
COMMAND: A(2,:)=[]
OUTPUT: A=
1 2 3
7 8 9
15) Write a command to delete 3rd through 5th column of 6x6 matrix. For this create a 6x6
matrix.
COMMAND:
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(:,3:5)=[]

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

16) Write the commands/programs and calculations wherever applicable:


1. Area=pi*r^2, (where r=(pi^(1/3 )-1))
2.Calculate and compare for:1. exp((pi/2)*i) 2. exp(pi/2i)
3. e^3 4. ln(e^3) 5. log10(e^3) 6. log10(10^5) 7. e^(pi*sqrt(163))
8.solve for 3^x=17
COMMAND: 1. Area= pi*((pi^(1/3))-1)^2 2.1 exp((pi/2)*i) 2.2 . exp(pi/2i)
3.exp(3) 4. Log(exp(3)) 5. Log10(exp(3)) 6. Log10(10^5) 7.
exp(pi*sqrt(163))
8. x=log(17)/log(3)

OUTPUT: 1. Area = 2.1. ans = 2.2 ans=


0.6781 0.0000 + 1.0000i 0.0000 - 1.0000i
3. ans = 4. ans = 5. ans = 6. ans= 7. ans=
20.0855 3 1.3029 5 2.6254e+017
8. x=
2.5789
17) Create a vector x whose entries are the square root of natural numbers 1 to 10 (use’ for’
statement)
COMMAND: for i=1:10
x(i)=i^2
end
OUTPUT: x=
1 4 9 16 25 36 49 64 81 100

13
ETC 324: Information Theory and coding 2018

INFORMATION THEORY AND CODING TECHNIQUES

EXPERIMENT NO. 1
Determination of Entropy

Aim: To find information and entropy of a given source.


Apparatus: PC, Matlab s/w
Theory: (1) What is discrete memory less source?
(2) Write definition, formula and units for the following
i) Information
ii) Entropy
iii) Information rate.
(3).What are the different types of entropies?
Algorithm:
1. Enter no. of symbols.
2. Input the probabilities of symbols resp.
3. Calculate the entropy of the channel input. i.e. H(x) using the formula:
H(x)=

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy