Vous êtes sur la page 1sur 8

Electrical And

Electronic
Benghazi
Collage
Six term communication department
Homework 1

Digital Communication
laboratory

Mohammed A.A.Muftah
C-121031
Solutions:A (1) the result will be ass following:4^2-1
= 15
4^ (2-1) = 4
2\3
= 1.5
4*2-9/3 = 5
-3
=-3
>> 4^2-1
ans =
15
>> 4^ (2-1)
ans =
4
>> 2\3
ans =
1.5000
>> 4*2-9/3
ans =
5
>> -3
ans =
-3
"Command window of MATLAB"

A (2) the following function do:>> help fix


fix Round towards zero.
fix(X) rounds the elements of X to the nearest integers
towards zero.
See also floor, round, ceil.
Overloaded methods:
codistributed/fix

Reference page in Help browser


doc fix
floor Round towards minus infinity.
floor(X) rounds the elements of X to the nearest integers
towards minus infinity.
See also round, ceil, fix.
Overloaded methods:
codistributed/floor
Reference page in Help browser
doc floor
ceil Round towards plus infinity.
ceil(X) rounds the elements of X to the nearest integers
towards infinity.
See also floor, round, fix.
Overloaded methods:
codistributed/ceil
Reference page in Help browser
doc ceil
round Round towards nearest integer.
round(X) rounds the elements of X to the nearest integers.
See also floor, ceil, fix.
Overloaded methods:
codistributed/round
Reference page in Help browser
doc round
"Command window of MATLAB"

Experiments:
>> a = fix (-2.5)
a=
-2
>> a = fix (2.5)
a=
2
>> a = fix (0.4)
a=
0
>> a = fix (0.7)
a=
0
>> b = floor (3.75)

b=
3
>> b = floor (-3.75)
b=
-4
>> b = floor (0.6)
b=
0
>> b = floor (-0.6)
b=
-1
>> c = ceil (-1.5)
c=
-1
>> c = ceil (1.5)
c=
2
>> c= ceil (0.3)
c=
1
>> c = ceil (-.07)
c=
0
>> d = round (2.25)
d=
2
>> d = round (-2.25)
d=
-2
>> d = round (-0.5)
d=
-1
>> d = round (0.5)

d=
1
"Command window MATLAB"

A (3) (a) The range of integers that can be stored as following:unit16: 0 65535
int16: -32768 32767
>> intmin ('uint16')
ans =
0
>> intmax ('uint16')
ans =
65535
>> intmin ('int16')
ans =
-32768
>> intmax ('int16')
ans =
32767
"Command window of MATLAB"

A (3) (b) Some assignment statement in variable types then changed it values and
types as below:>> character='A';
>> num=5;
>> logicVar=false;
>> num2=int16 (num);
>> whos
Name
Size
character
logicVar
num
num2

1x1
1x1
1x1
1x1

Bytes Class
2 char
1 logical
8 double
2 int16

>> character = 5;
>> num='Z';
>> logicVar=true;
>> num2=uint32 (character);
>> whos
Name
Size
Bytes Class
character
logicVar
num
num2

1x1
1x1
1x1
1x1

Attributes

Attributes

8 double
1 logical
2 char
4 uint32
"Command window of MATLAB"

A (4) (a) generate a random real number in the range from 0 to 1


>> rand
ans =
0.0975
"Command window of MATLAB"

A (4) (b) generate a random real number in the range from 0 to 50


>> rand*50
ans =
13.9249
"Command window of MATLAB"

A (4) (b) generate a random real number in the range from 10 to 20


>> rand*(20-10) +10
ans =
15.4688
"Command window of MATLAB"

A (4) (c) generate a random real number in the range from 1 to 10


>> rand*(10-1) +1
ans =
9.6176
"Command window of MATLAB"

A (5) (a) The numerical equivalent of the character't'


>> numequiv=double('t')
numequiv =
116
"Command window of MATLAB"

A (5) (b) The character equivalent of 112.


>> char(112)
ans =
p
"Command window of MATLAB"

A (6)
pv=2:2:8
pv (4) =33

Great a vector using colon operate (step=2)


change the forth element from 8 to store value 33

pv (6) =11
Add value 11 to store in element sixth and fifth element filled in 0s
Prac=pv (3:5)
Great vector from third to fifth element"
linspace (4, 12, 3) Great a vector witch has 3 values linearly spaced from 4 to 12
including 4&12"
>> pv=2:2:8
pv =
2

>> pv (4) =33


pv =
2

6 33

>> pv (6) =11


pv =
2

6 33

0 11

>> prac=pv (3:5)


prac =
6 33

>> linspace (4, 12, 3)


ans =
4

8 12
"Command window of MATLAB"

A (7)
m= [1:4; 3 11 7 2] this function will make a matrix in first row it been from 1 to 4
(step=1) in second row it puts the ready row 3 11 7 2".
m (2,3) its show the element from column 2 and row 3.
m (:,3) its show the third column.
m(4) its show the element from colum2 an row 2.
size(m) it returns number of rows and columns of m matrix.
numel(m) show the number of elements for m matrix.
reshape(m,1,numel(m)) it reshape the matrix to row vector use first column,
second, third then forth column has same number of m element.
vec=m(1,:) make new vector use same values of first row from m matrix.
vec(2)=5 change the second value to sore 5.
vec(3) = [] delete the third element then numbered again.
vec(5) =8 store 8 in fifth and filled in forth element 0.
vec= [vec 11] add ll value to store in last element.
>> m= [1:4;3 11 7 2]
m=
1 2
3 11
>> m(2,3)

3
7

4
2

ans =
7
>> m(:,3)
ans =
3
7
>> m(4)
ans =
11
>> size(m)
ans =
2

>> numel(m)
ans =
8
>> reshape(m,1,numel(m))
ans =
1

2 11

>> vec=m(1,:)
vec =
1

>> vec(2)=5
vec =
1

>> vec(3)=[]
vec =
1

>> vec(5)=8
vec =
1

>> vec=[vec 11]


vec =
1

8 11
"Command window of MATLAB"

Vous aimerez peut-être aussi