Professional Documents
Culture Documents
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 ;
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;
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]