Vous êtes sur la page 1sur 4

UNIVERSITY OF MASSACHUSETTS DARTMOUTH Department of Electrical and Computer Engineering

ECE 250 Fundamentals of MATLAB Midterm Exam NAME: This is an OPEN BOOK and OPEN NOTES examination. The use of a calculator is NOT allowed. The use of a computer without access to the Internet is required. SID:

Costa 03-31-2010

1. (20 points): On the Command Window, define the variable x as x = 13.5. Then, evaluate: a.

14 x 3 e3x
>> x=13.5; >> sqrt(14*x^3)/exp(3*x) ans = 4.7823e-016 >>

2 3 b. log x x

>> log(abs(x^2-x^3)) ans = 7.7311 >>

Continues on the other side

2. (10 points): On the Command Window, create the matrix shown below by using the vector notation for creating vectors with constant spacing and/or the linspace function when entering the rows.

1 4 7 10 13 16 19 22 25 72 66 60 54 48 42 36 30 24 0 0.125 0.250 0.375 0.500 0.625 0.750 0.875 1.000

>> A=[1:3:25;72:-6:24;0:0.125:1] A =
1.0000 72.0000 0 4.0000 66.0000 0.1250 7.0000 60.0000 0.2500 10.0000 54.0000 0.3750 13.0000 48.0000 0.5000 16.0000 42.0000 0.6250 19.0000 36.0000 0.7500 22.0000 30.0000 0.8750 25.0000 24.0000 1.0000

>> 3. (10 points): Solve the following problem by first writing a program in a script file and then running the file in the Command Window: Define h and k as scalars, h = 0.9, and k = 12.5, and x, y and z as the vectors x = [1 2 3 4], y = [0.9 0.8 0.7 0.6] and z = [2.5 3.0 3.5 4.0]. Then use these variables to calculate T as given below using element-by-element calculations for the vectors.
z +y x

T=

xyz

(h + k )

k 5

ke

zh

ex2prob3.m h = 0.9; k = 12.5; x = 1:4; y = 0.9:-0.1:0.6; z = 2.5:0.5:4; T = (x.*y.*z)./((h + k)^(k/5)) + (k * exp(z./x + y))./(z.^h)

>> ex2prob3 T = 164.2004 >>


2

46.3924

26.1889

17.7944

4. (20 points): Solve the following problem by first writing a program in a script file and then running the file in the Command Window: The velocity v and the distance d, as a function of time, of a car that accelerates from rest at a constant acceleration a, are given by

v (t ) = at

and

d (t ) =

1 2 at 2

Determine v and d at every second for the first 10 seconds for a car with an acceleration of a = 1.55m / s 2 . Display the results in a three-column table in which the first column is time (s), the second is distance (m), and the third is velocity (m/s).

a = 1.55; disp('Time (s) Distance (m) Velocity (m/s)') for t = 0:10 v = a * t; d = 0.5 * a * t^2; fprintf('%4d %15.2f %15.2f\n',t,d,v) end

>> ex2prob4 Time (s) 0 1 2 3 4 5 6 7 8 9 10 >>

Distance (m) 0.00 0.78 3.10 6.98 12.40 19.38 27.90 37.98 49.60 62.77 77.50

Velocity (m/s) 0.00 1.55 3.10 4.65 6.20 7.75 9.30 10.85 12.40 13.95 15.50

5. (40 points): A bandpass filter passes signals with frequencies within a certain range. In this filter, the ratio of the magnitude of the voltages is given by: Vout = Vin

mag =

(1 LC ) + (RC )
2 2

RC

where is the frequency of the input signal. a. Write a user-defined MATLAB function that calculates the magnitude ratio mag. For the function name and arguments use mag = bandpass(R, C, L, omega). The input arguments are: R is the resistance of the resistor in (Ohms), C is the capacitance of the capacitor in F (Farads), L is the inductance of the coil in H (Henrys), and omega the frequency of the input signal in rad/s. Write the function such that omega can be a vector. function mag = bandpass(R, C, L, omega) % mag = bandpass(R,C,L,omega) mag = (R*C*omega)./sqrt((1-omega.*omega*L*C).^2 + (omega*R*C).^2); b. Write a program in a script file that uses the bandpass function to generate a plot of mag as a function of for 10 2 107 rad/s. The plot is to use a logarithmic scale on the horizontal axis (). When the script file is executed, it asks the user to enter the values of R, L, and C. Label the axes of the plot. Run the script file for the following two cases: 1

R = 1100 , C = 9 F, L = 7 mH. R = 500 , C = 300 F, L = 400 mH.


Magnitude

0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 -2 10


1 0.9 0.8 0.7 Magnitude 0.6 0.5 0.4 0.3 0.2 0.1 0 -2 10
0 2 4 6 8

w = -2:0.1:7; w = 10.^w; R = input('Enter R = C = input('Enter C = L = input('Enter L = mag = bandpass(R, C, semilogx(w,mag)

'); '); '); L, w);

10

10 10 Frequency (rad/s)

10

10

xlabel('Frequency (rad/s)') ylabel('Magnitude')

10

10 10 Frequency (rad/s)

10

10

Vous aimerez peut-être aussi