Académique Documents
Professionnel Documents
Culture Documents
SIMULATION
ASSIGNMENT 2
NAME :K.S.Samarakoon
V – a real constant
Matlab commands
a)
>> t = 36;
>> x = (0:0.2:36)';
>> Y1 = bessel(1,x);
>> Y2 = bessel(2,x);
>> Y3 = bessel(3,x);
>> g = plot(x,Y1,x,Y2,x,Y3);
>> set(g,'LineWidth',2);
b)
c)
>> legend(g,'Y1','Y2','Y3');
Graph
Bessel Function
0.6
Y1
0.5 Y2
Y3
0.4
0.3
0.2
Y ax is
0.1
-0.1
-0.2
-0.3
-0.4
0 5 10 15 20 25 30 35 40
X axis
k = 5;
n = 2^k - 1;
X = [cos(phi)]'* [cos(theta)];
Y = [cos(phi)]'* [sin(theta)];
Z = [sin(phi)]'* ones(size(theta));
colormap([0 0 0; 1 1 1]);
C = hadamard(2^k);
surf(X,Y,Z,C);
axis square;
Corresponding Graph
k = 5;
0.5
-0.5
-1
1
0.5 1
0 0.5
0
-0.5
-0.5
-1 -1
n = 2^k - 1;
Assign ‘phi’ as a row vector in the range –n/2 <= phi <= n/2
X = [cos(phi)]'* [cos(theta)];
Assign ‘X’ as the vector product of column vector ‘transpose of cos(phi)’ and
Y = [cos(phi)]'* [sin(theta)];
Assign ‘Y’ as the vector product of column vector ‘transpose of cos(phi)’ and
Ones(size(theta)) – this command returns an array of 1s which is equal to the size of vector
‘theta’
Complete command assigns the vector product of column vector ‘transpose of sin(phi)’ and
row vector containing 1s similar to size of vector ‘theta’ as the value of ‘Z’
colormap([0 0 0; 1 1 1]);
This command selects colors to the surface. [0 0 0] RGB vector represents black color and
[1 1 1] RGB vector represents white color.
C = hadamard(2^k);
Assigns the hadamard matrix of order (2^k = 32) as the value of ‘C’
surf(X,Y,Z,C);
axis square;
Makes the current axis region square. It adjusts the x-axis, y-axis, and z-axis so that they have
equal lengths and adjusts the increments between data units accordingly.
Q3)
Matlab commands
>> polar(sin(x),cos(x),'r');
0.6
150 30
0.4
0.2
180 0
210 330
240 300
270
Q4)
th = (0:127)/128*2*pi;
x = cos(th);
y = sin(th);
f = abs(fft(ones(5,1),128));
fft(ones(5,1),128) command returns the 128-point Discrete Fourier Transform. Here the length
of the columns of the matrix is less than 128, therefore it is padded with trailing zeros to length
128.
stem3(x,y,f','d','fill');
‘fill’ - specifies to color the interior of the diamond at the end of the stem.
view([-65 30])
This command sets the viewing angle for a three-dimensional plot. 65, is the horizontal rotation
about the z-axis as measured in degrees from the negative y-axis. 30 is the vertical elevation of
the viewpoint in degrees. Because it is a Positive value it indicates that the object is moving
above.
1 1
0.5
0
0
1
0.5 -0.5
0
-0.5
-1 -1