You are on page 1of 7

1250 Matlab® Lecture 2 In-class Problems/Solutions

S 14

1. The equation for a diode's current versus voltage is exponential:


( )
i = I 0 ev/vT − 1

where I0 = 20 pA is a constant, vT ≈ 26 mV is a constant, v is the voltage drop across


the diode, and i is the current through the diode.
Find i for following v's: v = -∞ V (or –2 V for a practical value), v = 0 V, v = vT
solution: i = –I0 = –20 pA, i = 0, i ≈ I0*1.7 = 34 pA

We plot these values in MATLAB by making vectors.

>> v = [-2, 0, 25e-3] % We put all the voltages in one vector.


v =
-2.0000 0.0000 0.0250
>> Use square brackets for the array.
>> i_vec = [-20e-12, 0, 34e-12]
i_vec =
1e-10*
-0.2000 0.0000 0.3400
>> % Don't call it 'i' because 'i' is for complex #'s.
>> plot(v,i_vec) % Plotting is simple, but the v and i_vec must be
>> % the same size. Try it!
2. Find Node-V equations for following circuit. This is a simple D/A converter. Inputs
are 0 V or 5 V, representing 0's or 1's. A three-digit binary number is converted to a
voltage proportional to the input number. This is how your MP3 player converts
binary numbers representing music to the voltages that drive your earbuds.

We have two nodes, vA and vB. We may ignore the vout, since it is only a
point of measurement and not an extraordinary node. Once we have
solved for vB, we can solve for vout using superposition, as is explained
later. On the other hand, we could add it as a third node and solve for its
voltage. We can always add nodes, even if they are not extraordinary
nodes. If we are solving with MATLAB®, there is no harm in adding vout
as a third node, since complexity is less of an issue. First, we will solve
the problem using only two nodes.

We sum the currents out of each node:


vA vA − v2 vA − vB
+ + = 0A This is the vA node.
2R 2R R
vB − vA vB − v1 vB − v0
+ + = 0A This is the vB node.
R 2R 3R
We group the terms multiplying vA and vB:
⎛ 1 1 1⎞ ⎛ −1 ⎞ v
vA ⎜ + + ⎟ + vB ⎜ ⎟ = 2
⎝ 2R 2R R ⎠ ⎝ R ⎠ 2R

⎛ −1 ⎞ ⎛1 1 1 ⎞ v1 v0
vA ⎜ ⎟ + vB ⎜ + + = +
⎝ R⎠ ⎝ R 2R 3R ⎟⎠ 2R 3R

Let R=1, and let v0 = 5 V, v1 = 0 V, v2 = 5 V. This is just for example. It


turns out that the value of R will cancel out. Now our two node equations
are the following:
⎛ 1 1 1⎞ ⎛ −1 ⎞ 5
vA ⎜ + + ⎟ + vB ⎜ ⎟ =
⎝ 2 2 1⎠ ⎝ 1⎠ 2

⎛ −1 ⎞ ⎛ 1 1 1⎞ 0 5
vA ⎜ ⎟ + vB ⎜ + + ⎟ = +
⎝ 1⎠ ⎝ 1 2 3⎠ 2 3

or
5
vA ( 2 ) + vB ( −1) =
2
⎛ 11 ⎞ 5
vA ( −1) + vB ⎜ ⎟ =
⎝ 6⎠ 3

We write these equations in matrix form. Recall that matrix multiplication


is the row of the left matrix times the column of the right matrix. Row i of
the left matrix times column j of the right matrix gives the row i column j
entry of the resulting matrix.
⎡ 5 ⎤
⎡ 2 −1 ⎤ ⎡ ⎢ ⎥
⎢ ⎥ ⎢ vA ⎤⎥ = ⎢ 2 ⎥
⎢ −1 11 ⎥ ⎢ v ⎥ ⎢ 5 ⎥
⎢⎣ 6 ⎥⎦ ⎣ B ⎦ ⎢ ⎥
⎣ 3 ⎦

In MATLAB:
>> A = [2,-1;-1,11/6]; % We can call it what we like.
>> b = [5/2; 5/3];
>> v = inv(A)*b % To solve for vA and vB.
v =
2.3440
2.1880

This problem is simple enough to check by hand. The inverse of a 2x2


matrix is fairly simple to compute:
−1
⎡ a b ⎤ 1 ⎡ d −b ⎤
⎢ ⎥ = ⎢ ⎥
⎣ c d ⎦ ad − bc ⎣ −c a ⎦

−1 ⎡ 11 3 ⎤
⎡ 2 −1 ⎤ ⎡ 11 ⎤ ⎡ 11 ⎤ ⎢ ⎥
⎢ ⎥ =
1 ⎢ 1 ⎥ 3⎢
=
1 ⎥ ⎢ 16
=
8 ⎥
⎢ −1 11 ⎥ 22 ⎢ 6 ⎥ 8⎢ 6 ⎥ ⎢ 3 3 ⎥
⎢⎣ 6 ⎥⎦ −1⎢ 1 2 ⎥ ⎢⎣ 1 2 ⎥⎦ ⎢
6 ⎣ ⎦ ⎥
⎣ 8 4 ⎦

⎡ 11 3 ⎤⎡ 5 ⎤ ⎡ 75 ⎤
⎢ ⎥⎢ ⎥ ⎢ ⎥
⎢ 16 8 ⎥⎢ 2 ⎥=⎢ 32 ⎥ which is 2.344 and 2.188, so it works!
⎢ 3 3 ⎥⎢ 5 ⎥ ⎢ 35 ⎥
⎢ 8 4 ⎥⎢ 3 ⎥ ⎢ 16 ⎥
⎣ ⎦⎣ ⎦ ⎣ ⎦

Using symbolic v0, v1, and v2, we have

⎡ 11 3 ⎤⎡ v2 ⎤ ⎡ 11 3 1 ⎤
⎢ ⎥⎢ ⎥ ⎢ v2 + v1 + v0 ⎥
⎢ 16 8 ⎥⎢ 2 ⎥ = ⎢ 32 16 8 ⎥.
⎢ 3 3 ⎥ ⎢ v1 v0 ⎥ ⎢ 3 3 1 ⎥
⎢ +
⎥ ⎢ 2 3 ⎥ ⎢ 16 v2 + v1 + v0 ⎥
⎣ 8 4 ⎦⎣ ⎦ ⎣ 8 4 ⎦

Now we use superposition to find vout. Knowing vB, we may treat that
node as though it is connected to ground by a voltage source of value vB.
We may then ignore all the other circuitry to the left and below that node.
This leaves us with two sources, vB and v0, and two resistances, R and 2R,
with vout in between.

We turn on one node at a time to find the corresponding vout. Then we


add the two values of vout to get the true vout.
2R 2
vout1 = vB = vB
2R + R 3
R 1
vout2 = v0 = v0
2R + R 3

2 1
vout = vB + v0
3 3

Using our general solution from earlier, we have an expression for vout
that turns binary number v0v1v2 into a corresponding binary weighted
voltage:
2⎛ 3 3 1 ⎞ 1 1 1 1
vout = ⎜ v2 + v1 + v0 ⎟ + v0 = v2 + v1 + v0
3 ⎝ 16 8 4 ⎠ 3 8 4 2

In MATLAB we use the formula for vout from the top of the page with
numbers:
>> vout = 2/3*2.188 + 1/3*5
vout =
3.1250

This is the same as 101(binary for 5)/8 * 5 V.

Note that v0 is actually the most significant digit in the binary number. v2
is the last digit, and it has the least impact on the value of vout.

Note also that R-2R ladders are the standard way of constructing Digital-
to-Analog (D/A) converters. While it is hard to control the value of R on a
chip, the ratio of R's can be controlled fairly well, and only the ratio
matters in the final answer.

Solution using three nodes:

We treat vout as the third node.

We sum the currents out of each node:


vA vA − v2 vA − vB
+ + = 0A The vA node equation is as before.
2R 2R R
vB − vA vB − v1 vB − vout
+ + = 0A The 3rd term changes for vB node.
R 2R R
vout − vB vout − v0
+ = 0A This is the vout node.
R 2R
We group the terms multiplying vA, vB, and vout:

⎛ 1 1 1⎞ ⎛ −1 ⎞ v
vA ⎜ + + ⎟ + vB ⎜ ⎟ + vout (0) = 2 Note how vout term appears.
⎝ 2R 2R R ⎠ ⎝ R⎠ 2R

⎛ −1 ⎞ ⎛ 1 1 1⎞ ⎛ −1 ⎞ v
vA ⎜ ⎟ + vB ⎜ + + ⎟ + vout ⎜ ⎟ = 1
⎝ R⎠ ⎝ R 2R R ⎠ ⎝ R ⎠ 2R

⎛ −1 ⎞ ⎛ 1 1 ⎞ v0
vA ( 0 ) + vB ⎜ ⎟ + vout ⎜ + =
⎝ R⎠ ⎝ R 2R ⎟⎠ 2R

Let R=1, and let v0 = 5 V, v1 = 0 V, v2 = 5 V. Now our three node


equations are the following:
⎛ 1 1 1⎞ ⎛ −1 ⎞ 5
vA ⎜ + + ⎟ + vB ⎜ ⎟ + vout (0) = A
⎝ 2 2 1⎠ ⎝ 1⎠ 2

⎛ −1 ⎞ ⎛ 1 1 1⎞ ⎛ −1 ⎞ 0
vA ⎜ ⎟ + vB ⎜ + + ⎟ + vout ⎜ ⎟ = A
⎝ 1⎠ ⎝ 1 2 1⎠ ⎝ 1⎠ 2

⎛ −1 ⎞ ⎛1 1⎞ 5
vA ( 0 ) + vB ⎜ ⎟ + vout ⎜ + ⎟ = A
⎝ 1⎠ ⎝1 2⎠ 2

or
5
vA ( 2 ) + vB ( −1) + vout (0) = V
2
⎛ 5⎞
vA ( −1) + vB ⎜ ⎟ + vout (−1) = 0 A
⎝ 2⎠

⎛ 3⎞ 5
vA ( 0 ) + vB ( −1) + vout ⎜ ⎟ = V
⎝ 2⎠ 2

We write these equations in matrix form. Recall that matrix multiplication


is the row of the left matrix times the column of the right matrix. Row i of
the left matrix times column j of the right matrix gives the row i column j
entry of the resulting matrix. Note that the matrix on the left is symmetric.

⎡ 2 −1 0 ⎤⎡ vA ⎤ ⎡ 5 / 2 ⎤
⎢ ⎥⎢ ⎥
vB ⎥ = ⎢ 0 ⎥ V
⎢ −1 5 / 2 −1 ⎥⎢ ⎢ ⎥
⎢⎣ 0 −1 3 / 2 ⎥⎦ ⎢ vout ⎥ ⎢⎣ 5 / 2 ⎦⎥
⎣ ⎦
In MATLAB:
>> A = [2,-1,0;-1,5/2,-1;0,-1,3/2];
>> b = [5/2;0;5/2];
>> v = inv(A)*b % To solve for vA and vB.
v =
2.3438
2.1875
3.1250

The third entry is vout. In retrospect, this approach seems preferable, as it


directly produces the value for vout and the numbers in our matrices are
simpler.

You might also like