You are on page 1of 2

Birla Institute of Technology & Science, Pilani

Work Integrated Learning Programmes Division


Second Semester 2015-16

MidSem Exam
(EC-2 Regular)

Course No : TAZC164
Course Title : Computer Programming(in MATLAB)
Nature of Exam : Closed Book
No. of Pages = 2
Weightage : 35%
No. of Questions = 7
Duration : 2[hrs]
Date of Exam : 28/02/2016(FN)

Note:

1. Follow all the Instructions to Candidates given on the cover page of the answer book. Answer all questions.
All parts of a question should be answered consecutively. All relevant and necessary assumptions/notations
to be defined completely and clearly.
2. Question Type:

(a) Each question with Find requires numerical values(/program output) to be given in the answer.
(b) Each question with word obtain requires the answer to be given ONLY as a MATLAB script/functions.
There is no need to give any program output in terms of arrays or any other output. The default
answer to be a script. The MATLAB code to be syntactically correct.

3. (i) , denotes a definition, (ii) e ja in MATLAB is exp(j∗a); (iii) For c = mod (a, b); c the remainder of a/b.
4. Am×n denotes a matrix of m-rows and n-columns. For 1 ≤ c ≤ n, A∗c denotes the c-th column
 of A.
−1 −5 6 −5
For 1 ≤ r ≤ m, Ar∗ denotes the r-th row of A. For example A , , A∗2 = and
−10 −9 8 −9
 
A2∗ = −10 −9 8 .
5. Vectors:
 
a1
 a2   T
(a) A vector an×1 implies a ,  .  = a1 a2 · · · an ;
 
.
. 
an
 T 
(b) Example: a = −1 2 −3 4 , implies a1 = −1, a2 = 2, a3 = −3, a4 = 4 ;

6. Sequences stored in vectors:



(a) A sequence x[n] for 0 ≤ n < L implies x[n] ∈ x[0], x[1], x[2],· · ·, x[L − 1] . Also x[n] = 0, n < 0.
 T
(b) x[n] can be stored in a column vector v x , a1 a2 · · · aL as a(n+1) , x[n].

TAZC164(EC-2 Regular) Second Semester 2015-16 Page 1 of 2


1 a1 = [10:2:24];
2 c1 = gt ( a1 , 11); c2 = lt ( a1 , 20); Find
E1-1 3 c3 = and ( c1 , c2 ); c4 = not ( c3 );
4 ix1 = find ( c3 ); ix2 = find ( c4 ); [a] ix1 [b] ix2 [(1*2)-Marks]

1 a1 = [10:2:20]; a2 = [14:2:24];
2 y1 = setdiff ( a1 , a2 ); Find
E1-2 3 y2 = setdiff ( a2 , a1 );
4 b1 = [ a1 a2 ]; y3 = unique ( b1 ); [a] y1 [b] y2 [c] y3 [(1*3)-Marks]

1 a = [1 3 4 10 -3 11 -2];
2 n1 = numel ( a ); s1 = 0;
3 for c1 = 1: n1
4 if gt ( a ( c1 ) , 9) , break ; end ;
5 s1 = s1 + a ( c1 );
Find
E1-3 6 end ;
7 s2 = 0; [a] s1 [b] s2
8 for c1 = 1: n1
9 if lt ( a ( c1 ) , 0) , continue ; end ;
10 s2 = s2 + a ( c1 );
11 end ; [(2*2)-Marks]
   x
E1-4 Any point x, y on a straight line with intercepts as a1 , a2 is given by y = f (x) = a2 1− . For bi , f (xi ),
a1
 T  T
obtain b with a script, using vector operations for a = 2 4 , x = 0.1 −0.2 0.3 −0.5 .
[4-Marks]

E1-5 For a sequence x[n] = (n2 + 1), 0 ≤ n < L, L = 21, write a script which obtains the following;

[a] d[m] , x[4m] for 0 ≤ m ≤ 5;



[b] h[i] = x[0], 0, 0, 0, x[1], 0, 0, 0,· · ·, x[L − 1], 0, 0, 0 , with 0 ≤ i < 4L.
[(2*3)-Marks]

 T  T  
E1-6 For x , −1 −2 −3 −4 , a , 0.2 0.3 0.4 0.5 , yi , 1/xi , bi , 1/ai ;
n
X Yn  
(i) p1 , (xi +bi )2 ; (iii) p3 , yi +bi ;
i=1 i=1
n
Y n
X n
X 
(ii) p2 , (xi +bi ); (iv) p4 , yi bi ;
i=1 i=1 i=1
Write a script which obtains p4×1 using vector operations. [(2*4)-Marks]

1 a1 = [1:4]; a2 = [7:10];
2 a3 = [12:15]; a4 = [18:21]; Find
3 H = []; c_index = [4 3 2 1];
4 for c1 = 1:4
[a] b1
5 c2 = c_index ( c1 );
E1-7 6 s1 = sprintf ( ’a % d ’ , c2 ); [b] b2
7 v = eval ( s1 ); H ( c1 ,:) = v ;
8 end ; [c] b3
9 b1 = H (1 ,:); b2 = H (3 ,:); [d] b4
10 b3 = H (: ,1); b4 = H (: ,3); [(2*4)-Marks]

TAZC164(EC-2 Regular) Second Semester 2015-16 Page 2 of 2

You might also like