Anda di halaman 1dari 6

# FALL - 2011

## 1st Midterm Examination

Course Code: TLC212 Course Title: PROGRAMMING IN TELECOM Teachers Name: Muhammad Azam Total Marks: 50 Date & Time: 11:00 AM, Oct 20, 2011 Total Time: 90 Minutes Students Name: Registration No: Note: This is a programming based exam. You need to solve all the questions using Matlab and email your code to me at azam@iqraisb.edu.pk before 12:30. Your email title should be Your Name Iqra ID Mid1. Question 01: [1 + 2 + 3 + 4 + 4 + 6 = 20 marks] a) [1 marks] Create a row vector a_1 in which the first element is 2 and the last element is 37, with an increment of 5 between the elements (2, 7, 12, , 37). Solution: a_1 = 2:5:37; b) [2 marks] Create a column vector b_1 with 15 equally spaced elements in which the first element is 21 and the last element is 12. Solution: b_1 = linspace(-21,12,15); c) [3 marks] Create the following matrix A by using vector notation for creating vectors with constant spacing or the linspace command. Do not type individual elements explicitly.

Solution: A = [0:5:30; 600:-100:0; linspace(0,5,7)]; d) [4 marks] Using the zeros, ones, and eye Matlab commands, create the following arrays. Do not type the individual elements directly.

Solution: d_i = [ones(2,2); zeros(2,2)]; d_ii = [eye(3,3) ones(3,3)]; d_iii = [ones(2,4); zeros(1,4); ones(1,4)];

Page 1

FALL - 2011

## e) [4 marks] Consider the matrix

i. [2 marks] Using relational operators to set all the terms of D, which are > 6 and < 0 equal to 0. ii. [2 marks] Use logical fields to select the diagonal of this matrix and save it as a vector diag. Solution: D = [7 2 3 10; -2 -3 11 4; 8 1 6 5; 18 1 11 4]; D_i = D; D_i(D>6 | D<0) = 0; d_indices = logical(eye(4,4)); diag = D(d_indices); f) [6 marks] Define the vector v = [2 4 6 8 10]. Then use the vector v in a mathematical expression to create the following vectors. Do not type individual elements explicitly. i. ii. iii. iv. = [24 43 62 81 100 ] = =
1 1 1 1 1 2 4 6 8 10 1 1 1 1 1 22 4 2 62 82 10 2

= [1 1 1 1 1]

Page 2

FALL - 2011

## Question 02: a) [1 + 4 = 5 marks] Create the following matrix H

[5 + 7 + 6 = 18 marks]

i.

ii.

[2 marks] Create a 24 matrix G such that its first row includes the first two elements and the last two elements of the first row of H, and the second row of G includes the second through the fifth elements of the third row of H. [2 marks] Create a 33 matrix K such that the first, second, and third rows are the first, fourth, and sixth columns of matrix H. Solution: H = [1.7:-.1:1.2 ; 22:2:32; 9:-1:4]; G = [H(1,[1 2 5 6]); H(3,2:5)]; K = H(:,[1 4 6])';

## b) [1 + 6 = 7 marks] Create the following matrix B.

i. ii. iii.

[2 marks] Create a six-element column vector named aa that contains the elements of the second and fifth columns of B. [2 marks] Create a seven-element column vector named bb that contains elements 3 through 6 of the third row of B and the elements of the second column of B. [2 marks] Create a nine-element column vector named cc that contains the elements of the second, fourth, and sixth columns of B. Solution: B = [18:-1:13; 12:-1:7; 6:-1:1]; aa = [B(:,2); B(:,5)]; bb = [B(3,3:6)'; B(:,2)]; cc = [B(:,2); B(:,4); B(:,6)];

c) [6 marks] For the triangle shown below, a = 200mm, b = 250mm, and c = 300mm. Define a, b, and c as variables, and then: i. ii. [2 marks] Calculate angle (in degrees) by substituting the given variables in the equation 2 = 2 + 2 2 cos i.e. it is also called Law of Cosines. [2 marks] Calculate the radius of the circle inscribed in the triangle using the formula. = iii.
Page 3

1 1 + tan 2 2

[2 marks] Calculate the radius of the circle inscribed in the triangle using the formula.

FALL - 2011

## TLC212 PROGRAMMING IN TELECOM

() ,

where =

1 2

+ +

Solution: a = .2; b = .25; c = .300; gemma_rad = acos ((a^2 + b^2 - c^2) / (2*a*b) ); % part i gemma_deg = gemma_rad*(180/pi); % radians to degrees r = (1/2) * (a + b - c) * tan(gemma_rad/2); s = (1/2) * (a + b + c); % part iii r = sqrt(s*(s-a)*(s-b)*(s-c))/s; % part ii

Page 4

FALL - 2011

## TLC212 PROGRAMMING IN TELECOM

Question 03:

[5 + 7 = 12 marks]

a) [5 marks] The current I (in amps) t seconds after closing the switch in the circuit shown is = (1

Given V = 120 volts, R = 240 ohms, and L = 0.5 henrys i. ii. [1 marks] Calculate the current I, 0.003 seconds after the switch is closed. [4 marks] Plot the current I verses time t graph with values of t ranging from 0 to 1 in steps of 0.05. Your plot should be displayed in green color and axis should be properly labeled.

Solution: V = 120; R = 240; L = 0.5; t = 0.003; I_point003 = (V/R)*(1 - exp(-(R*t)/L)); t = 0:0.05:1; I = (V/R)*(1 - exp(-(R*t)/L)); figure; plot(t,I,'g'); xlabel('time (sec)'); ylabel('Current (amperes)'); grid b) [7 marks] Consider the diode circuit shown in the figure below.

The current and the voltage can be determined from the solution of the following system of equations = 0 1 =

1 (2) = 30

## where 0 = 1014 , = 1.5, and = 1200 and

The system can be solved numerically or graphically. The graphical solution is found by plotting as a function of from both equations. The solution is the intersection of the two curves. i. [3 marks] First make the plot of as a function of using equation (1). The values of should be ranging from 0 to 3 in steps of 0.1. Your plot should be displaced in red color with solid line.
Page 5

FALL - 2011

## TLC212 PROGRAMMING IN TELECOM

ii.

iii.

[3 marks] Then make the second plot (on top of first plot) of as a function of using equation (2). Use the same range for described in (a). Your plot should be displayed in black color with dotted line. [1 marks] Find the solution by spotting the intersection of the two plots.

Solution: I0 = 10^-14; vS = 1.5; R= 1200; kT_q = 30; vD = 0:.1:3; iD1 = I0 * ( exp(-vD/kT_q) -1 ); figure; plot(vD, iD1, 'r'); iD2 = (vS - vD)/R; hold on; plot(vD, iD2, 'k:'); grid % Solution is iD = 0 for vD = 1.5 (the point of intersection)

Page 6