Vous êtes sur la page 1sur 7

COMPUTER AIDED DESIGN AND

SIMULATION
ASSIGNMENT 2

NAME :K.S.Samarakoon

INDEX NO. :080436M

DATE OF SUB. :2011.01.18


Q1) Bessel functions are the solutions of following differential equation.

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);

>> grid on;

>> set(g,'LineWidth',2);

b)

>> xlabel('X axis');

>> ylabel('Y axis');

c)

>> title('Bessel Function');

>> 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

Q2) Matlab codes

k = 5;

n = 2^k - 1;

theta = pi * (-n : 2 : n)/n ;

phi=(pi/2) * (-n : 2 : n)/n ;

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

Assign ‘5’ as the value of variable ‘k’

n = 2^k - 1;

Assign ‘2^k - 1’ as the value of variable n.

According to the previous command k = 5. So n = 31

theta = pi * (-n : 2 : n)/n ;

Assign ‘theta’ as a row vector in the range –n <= theta <= n

phi=(pi/2) * (-n : 2 : n)/n ;

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

row vector ‘cos(theta)’

Y = [cos(phi)]'* [sin(theta)];

Assign ‘Y’ as the vector product of column vector ‘transpose of cos(phi)’ and

row vector ‘sin(theta)’


Z = [sin(phi)]'* ones(size(theta));

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);

Creates a shaded surface of X,Y,Z with colors defined by 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

>> x=[0:0.8:36] ';

>> polar(sin(x),cos(x),'r');

>> title('K.S.Samarakoon - 080436M');


K.S.Samarakoon - 080436M
90
1
120 60
0.8

0.6
150 30
0.4

0.2

180 0

210 330

240 300
270

Q4)

MATLAB codes and functions

th = (0:127)/128*2*pi;

Assigns a row vector for ‘th’

x = cos(th);

Assigns the row vector of cos(th) to x

y = sin(th);

Assigns the row vector of sin(th) to y

f = abs(fft(ones(5,1),128));

ones(5,1) command returns a 5 by 1 matrix with ones.

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.

abs returns the absolute value of the corresponding element.

stem3(x,y,f','d','fill');

Plots the data sequence f’(transpose of function f) at values specified by x and y.


x, y, and f’ are vectors of the same size.

‘d’ – mark all the points of the graph in diamond shape.

‘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.

Output of the above code

1 1

0.5
0
0
1
0.5 -0.5
0
-0.5
-1 -1

Vous aimerez peut-être aussi