AI as Research Assistant: Upscaling Content Analysis to Identify Patterns of ...
Matlab
1. ASSIGNMENT – 2
Ques1 : Equation of a straight line : The equation of a line is y = mx+c where m and c are
constants. Compute y-coordinates of a line with m= 0.5 and c=-2 at following x-coordinates
:
0, 1.5, 3, 4, 5, 7, 9, 10.
Sol :
>> x = [0, 1.5, 3, 4, 5, 7, 9, 10]
x=
Columns 1 through 7
0 1.5000 3.0000 4.0000 5.0000 7.0000 9.0000
Column 8
10.0000
>> m = 0.5;
>> c = -2;
>> y = m * x + c
y=
Columns 1 through 7
-2.0000 -1.2500 -0.5000 0 0.5000 1.5000 2.5000
Column 8
3.0000
Ques2: Multiply, Divide and Exponentiate vectors : Create a vector t with 10 elements : 1
to 10. And then calculate the following quantities.
Sol :
(a) X = t * sin(t)
>> t = 1:1:10
t=
1 2 3 4 5 6 7 8 9 10
>> x = t.*sin(t)
x=
Columns 1 through 7
0.8415 1.8186 0.4234 -3.0272 -4.7946 -1.6765 4.5989
Columns 8 through 10
7.9149 3.7091 -5.4402
2. (b) X = (t-1) / (t+1)
x = (t-1) ./ (t+1)
x=
Columns 1 through 7
0 0.3333 0.5000 0.6000 0.6667 0.7143 0.7500
Columns 8 through 10
0.7778 0.8000 0.8182
(c) X = sin(t2) / (t2)
>> x = sin(t.*t)./(t.*t)
x=
Columns 1 through 7
0.8415 -0.1892 0.0458 -0.0180 -0.0053 -0.0275 -0.0195
Columns 8 through 10
0.0144 -0.0078 -0.0051
Ques3: Points on a circle : All points with coordinates x = r cosθ and y = r sinθ where r is a
constant, lie on a circle with radius r, i.e. if they satisfy x2 + y2 = r2. Create a column vector
for θ with values 0, π/4 , π/2 , 3 π/4, π and 5 π/4.
Take r = 2 and compute values of x and y. Also check that x and y satisfy the equation of
circle.
Sol :
>> theta = 0:pi/4:5*pi/4
theta =
0 0.7854 1.5708 2.3562 3.1416 3.9270
>> r = 2;
>> x = r .* cos(theta)
x=
2.0000 1.4142 0.0000 -1.4142 -2.0000 -1.4142
>> y = r .* sin(theta)
y= 0 1.4142 2.0000 1.4142 0.0000 -1.4142
3. >> r = (x .* x + y .* y) .^ (1/2)
r= 2 2 2 2 2 2
Ques4 : The geometric Series.
Sol :
(a)
>> n = 0:1:10
n= 0 1 2 3 4 5 6 7 8 9 10
>> r = 0.5
r=
0.5000
>> x = r .^ n
x=
Columns 1 through 7
1.0000 0.5000 0.2500 0.1250 0.0625 0.0313 0.0156
Columns 8 through 11
0.0078 0.0039 0.0020 0.0010
>> s = sum(x)
s = 1.9990
>> s = 1/(1-r)
s=2
(b)
>> n = 0:1:50;
>> r = 0.5;
>> x = r .^ n;
>> s = sum(x)
s = 2.0000
4. >> s = 1 /(1-r)
s=2
(c)
>> n = 0:1:100;
>> r = 0.5;
>> x = r .^ n;
>> s = sum(x)
s= 2
>> s = 1 /(1-r)
s=2
Ques5 : Create a vector and a matrix with following commands : v = 0:0.2:12; and M =
[sin(v) ; cos(v)]; Find the sizes of v and M using the size command. Now extract the first 10
elements of each row of the matrix and display them as column vectors.
Sol :
>> v = 0:0.2:12;
>> M = [sin(v) ; cos(v)];
>> size(v)
ans = 1 61
>> size(M)
ans = 2 61
>> M1 = M(1,1:10)
M1 =
Columns 1 through 7
0 0.1987 0.3894 0.5646 0.7174 0.8415 0.9320
Columns 8 through 10
0.9854 0.9996 0.9738
>> M1'
ans =