Sei sulla pagina 1di 3

1250 Homework MATLAB 7

S 14

QOD: How do phasors allow us to correctly model the basic component equations:
di dv
v = iR , v = L , and i = C ?
dt dt

1. a) Write an expression for vL(t > 0) for the circuit shown below. Hint: the L looks
like an open circuit for t = 0 and a wire for t -> ∞. Also, τ = L/R for an inductor.

b) Correct the MATLAB code below to plot your v(t) versus t from part (a).

% ECE1250S14_HW7p1.m Script file to plot HW7 prob 1 solution.

vs = 2; % vs = 2 V
R = 10; % R = 10 ohms
L = 100e-3; % L = 100 mH
tau = L/R; % Time constant = L/R

t = 0:1e-3:10e-3; % time goes from 0 to 10 ms, steps 1 ms

% Calculate array of v(t) values.


vL_t = vs(1 - exp(-t/tau)); % Wrong vL(t)! Fix it.

% Plot the v(t)


plot(t,v_t,'b-')
xlabel('time (sec)')
ylabel('vL(t) (V)')
title('Inductor voltage for ECE 1250 HW 7 problem 1')

2. a) Modify the MATLAB code below to create a function that calculates the phasor
for the sum of two sinusoids represented by phasors.
function [A3,phi3] = PhasorAdd(A1,phi1,A2,phi2)
% Usage [A3,phi3] = PhasorAdd(A1,phi1,A2,phi2)
% Calculates the phasor for the sum of two phasors.
% A1, phi1 = magnitude and phase shift in radians of 1st sine
wave (note the 1st phase is "phi one" (not phi el))
% A2, phi2 = magnitude and phase shift in radians of 2nd sine
wave
% A3, phi3 = magnitude and phase shift of sum of sinusoids
% Calculate the phasor sum. Not quite right--fix it!
phasor_sum = A1*e^(j*phi1) + A2*e^(j*phi2);

% Find the magnitude of the phasor for the sum.


A3 = abs(phasor_sum);
% Find the phase angle of the phasor for the sum. Fix this!
phi3 = atan2(real(A3),imag(A3));

end

b) Use the function from part (a) to calculate the sum of the following two sinusoids.
Add code to also plot the resulting sinusoid.
6 cos(200π t + 60°) + 8 cos(200π t − 30°)

3. a) Patch up the MATLAB code below to create a function that calculates parallel
impedance. (The code is the same for resistance and impedance.)
function Ztot = Zpar(Zvec)
% Usage Ztot = Zpar(Zvec)
% Calculates the parallel impedance of the values in Zvec

% The following formula is not quite right. Fix it!


Ztot = 1 ./ Zvec;
t = 0:1e-3:10e-3; % time goes from 0 to 10 ms, steps 1 ms

b) Use addition and your function from part (a) to find the numerical value of the
total impedance of the circuit shown below. You will need to convert from L and
C values to impedances first. Note that ω = 1 krad/s.
4. a) Write the node-voltage equations for nodes A and B in the circuit shown below.

b) Rewrite the node-voltage equations from part (a) in matrix form. That is, write
MATLAB code similar in flavor to the code below to create a matrix equation for
the circuit in part (a).
% Example code for putting node-V equations in matrix form for
% some circuit, (not the same circuit as in part (a)!).

% Define component values.


vs = 6; (V)
R1 = 8; (ohms)
R2 = 10; (ohms)
R3 = 15; (ohms)
is1 = 1; (A)
is2 = 2; (A)

i_vec = [vs/R1 - is1; -is2]; % Constant terms on right side of


eq'n
A = [1/R1 + 1/R2, -1/R2; -1/R2, 1/R2 + 1/R3];

c) Use MATLAB to solve for the node voltages, as in the code below:
% Solve for vA and vB
v_vec = inv(A)*i_vec

Potrebbero piacerti anche