Professional Documents
Culture Documents
Index No : 180214J
Name: Gunathilake S.D.
Part A
Q1
syms f(x);
f(x) = cos(10*x)^2 * exp(-x^2);
xRange = (-5:0.05:5);
fxRange = f(xRange);
size_xRange = size(xRange, 2);
index = (1: size_xRange);
mat_x_fx = [index(:), xRange(:), fxRange(:)];
csvwrite('180214J.csv', mat_x_fx, 0);
mat_x_fx_csv = load("180214J.csv");
firstindex = find(mat_x_fx_csv(:,2) == -3);
lastindex = find(mat_x_fx_csv(:,2) == 3);
x_data = mat_x_fx_csv(firstindex:lastindex,2);
fx_data = mat_x_fx_csv(firstindex:lastindex,3);
plot(x_data, fx_data)
xlabel("x");
ylabel("f(x)");
Q2.
Z_min = min(min(Z));
X_min = 0;
Y_min = 0;
for i=1:1:100 %checking the global minima
X = Xrandom(i);
for j=1:1:100
Y = Yrandom(j);
Z = 20+(X).^2+(Y).^2+10.*(cos(2*pi*X)+cos(2*pi*Y));
if Z<Z_min
Z_min = Z;
X_min = X;
Y_min = Y;
end
end
end
r = zeros(1,32);
for n = 3:32
r(n) = rank(magic(n));
end
bar(r);
Line 1 create a 1x32 matrix of zeros.
Line 3 returns the rank of the magic(n) and assign it to nth number of r. magic(n) returns an n by n
matrix constructed from the integers 1 through n*2 with equal row and column sums
Q4
a)
x =(0:0.2:14);
Y1=besselj(1,x);
Y2=besselj(2,x);
Y3=besselj(3,x);
plot(x,Y1);
hold on
plot(x,Y2);
plot(x,Y3);
b)
xlabel("X");
ylabel("Y");
c)
PartB
Q5
Same as Q3
Q6.
1)
s = linspace(-5,5,100);
coeff = [1 3 3 1];
A = polyval(coeff,s);
plot(s,A);
xlabel('s');
ylabel('A(s)');
roots(coeff);
Line 3 creates the polynomial for s from the coefficients of the coeff row vector