# Trying to solve a circuit containing 2 current sources and 1 voltage source and resistors: what am I doing wrong?

Here is the schematic and the values given. This is for a Coursera test on Linear Circuits I am taking and where I am stuck :-(

Doing KCL and KVLs I get this:

$$\frac{V_a-V_b}{R_1}=I_1+i_B\\ i_A+I_B=I_2\\ -I_2+\frac{V_a-V_b}{R_1}+\frac{V_b}{R_3}+\frac{V_1-V_b}{R_2}=0\\ -V_1+(i_B+i_C)*R_2+(i_D+i_C)*R_3=0\\ \frac{V_b}{R_3}=i_D+i_C\\ \frac{V_1-V_b}{R_2}=i_B+i_C$$ and with iD=I1 $$V_a-V_B-i_a*R_1=R_1*I_1\\ i_a+I_B=I_2\\ V_A*\frac{1}{R_1}+V_B*(\frac{-1}{R_1}+\frac{1}{R_3}-\frac{1}{R_2})=I_2-\frac{V_1}{R_2}\\ R_2*i_B+i_C*(R_2+R_3)=V_1-I_1*R_3\\ V_B-R_3*i_C=R_3*I_1$$

This gives this matrix A*X=B with this solution in Matlab

I1=10*1e-3; I2=30*1e-3; V1=10; R1=800; R2=100; R3=300; R4=1000;

A=[1 -1 -R1 0 0; 0 0 1 1 0; 1/R1 (-1/R1+1/R3-1/R2) 0 0 0; ...
0 0 0 R2 (R2+R3);  0 1 0 0 -R3]
B=[R1*I1; I2; I2-V1/R2; V1-R1*I1; R3*I1]

X=linsolve(A,B)
X=inv(A)*B


with

X =

-103.5000  Va
-7.5000  Vb
-0.1300  iA
0.1600  iB
-0.0350  iC


Which unfortunately is wrong :-(

Where is my mistake? What am I doing wrong?

This seems such an easy circuit...

Thanks.

• In the third formula Vb/R3 must have a negative sign – Dorian Sep 18 '18 at 9:52
• Thanks. From a logical standpoint you are right. The current flows in the opposite direction. Unfortunately now it gets even worse and I get this warning: "Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 2.729154e-23." So I suspect there must be more than this one error (or the problem value are wrong - always a possibility too) – Andreas K. Sep 18 '18 at 9:59
• In first formula it should be I1+Ia not I1+Ib – Rokta Sep 18 '18 at 10:55
• Thanks. That's right. Unfortunately this only seems to be a typo as in the following equation I used iA. – Andreas K. Sep 18 '18 at 12:23

Since you've provided your own work (thanks!), here's how I'd approach the problem. You can weed through your own work, looking over mine, for your own errors. I want to leave something for you to do; that, plus some algebra work I'll also later leave for you, below.

I'm going to always start my loops (all four) from the central node of your schematic. And I will also always follow the direction of your own arrows, as I generate each equation below. And, just to be complete, I will always start each equation with an explicit $0\:\text{V}$. The indicated circuit ground is simply ignored for the following purposes:

\begin{align*} 0\:\text{V}+V_{I_2}-I_A\cdot R_4-\left(I_A+I_D\right)\cdot R_1&=0\:\text{V}\\\\ 0\:\text{V}+V_{I_2}-\left(I_B+I_C\right)\cdot R_2&=0\:\text{V}\\\\ 0\:\text{V}-\left(I_C+I_D\right)\cdot R_3+V_1-\left(I_C+I_B\right)\cdot R_2&=0\:\text{V}\\\\ 0\:\text{V}-\left(I_C+I_D\right)\cdot R_3+V_{I_1}-\left(I_A+I_D\right)\cdot R_1&=0\:\text{V}\\\\ I_1&=I_D\\\\ I_2&=I_A+I_B \end{align*}

You can either use the last two equations to substitute back into the earlier four equations and then solve for four unknown variables in four equations or else you can simply solve the above all six equations for six unknown variables. Either way works fine.

Note that I did not bother to worry about node voltages, but instead used $V_{I_1}$ and $V_{I_2}$ to represent the voltages across your two current sources.

I'm not going to bother placing the above equations into matrix form for you. It's just algebraic manipulation and I'm sure you could handle that without difficulty.

It's also left to you as an exercise.

So just let Sage provide the direct results:

sage: var('i1 i2 ia ib ic id r1 r2 r3 r4 v1 vi1 vi2')
(i1, i2, ia, ib, ic, id, r1, r2, r3, r4, v1, vi1, vi2)
sage: e1=Eq(vi2-ia*r4-(ia+id)*r1,0)
sage: e2=Eq(vi2-(ib+ic)*r2,0)
sage: e3=Eq(-(ic+id)*r3+v1-(ic+ib)*r2,0)
sage: e4=Eq(-(ic+id)*r3+vi1-(id+ia)*r1,0)
sage: e5=Eq(i2,ia+ib)
sage: e6=Eq(i1,id)
sage: ans=solve([e1,e2,e3,e4,e5,e6],[ia,ib,ic,id,vi1,vi2])
sage: ans[ia].subs({i1:10e-3,i2:30e-3,v1:10,r1:800,r2:100,r3:300,r4:1000})
-0.00213333333333333
sage: ans[ib].subs({i1:10e-3,i2:30e-3,v1:10,r1:800,r2:100,r3:300,r4:1000})
0.0321333333333333
sage: ans[ic].subs({i1:10e-3,i2:30e-3,v1:10,r1:800,r2:100,r3:300,r4:1000})
0.00946666666666666
sage: ans[id].subs({i1:10e-3,i2:30e-3,v1:10,r1:800,r2:100,r3:300,r4:1000})
0.0100000000000000
sage: ans[vi1].subs({i1:10e-3,i2:30e-3,v1:10,r1:800,r2:100,r3:300,r4:1000})
12.1333333333333
sage: ans[vi2].subs({i1:10e-3,i2:30e-3,v1:10,r1:800,r2:100,r3:300,r4:1000})
4.16000000000000


Those results will be correct, I believe. I just ran it in Spice, only after doing the above, and it produced the same figures.

LTSpice netlist:

R1 N003 N002 800
R2 N001 N003 100
R3 N003 0 300
R4 N001 N002 1k
V1 N001 0 10
I1 0 N002 10m
I2 N003 N001 30m • Thank you very much. That's way more than I wished for. And I am happy to have a different take on this problem. I'll compare your way and try to figure out my errors. The biggest problem in distance learning like Coursera is the lack of direct communication with fellow "problem solvers" ;-) Btw, do you mind to send me your Spice model for reference. I'll try to put up mine in LTSpice and then can compare it with yours? – Andreas K. Sep 18 '18 at 12:30
• @AndreasK. Added at the end. – jonk Sep 18 '18 at 12:34
• To the person providing a (-1) rating, have the courage to identify yourself and your reasoning. Cowardice isn't a virtue. – jonk Sep 18 '18 at 14:31
• @jonk I'm afraid such words are useless since those people will not only take advantage of the anonymity of the action, but also take it further in the meta (maybe not even EE meta). I don't have the link, anymore, but I know there was a very animated thread about this, with (perhaps) not surprisingly quite evenly split opinions. – a concerned citizen Sep 19 '18 at 6:39
• @aconcernedcitizen I have no control over anyone. Just offering my opinion. Of course, everyone is free to act as they choose. – jonk Sep 19 '18 at 6:43

I would use nodal analysis at for VA and VB utilizing Kirchhoff's Current Law (KCL). First, solve for the voltages, and then use the voltages to solve for the currents. Remember that all the currents going into a node equals the amount of current leaving a node, and since the elements are resistors, you can just use V=IR to get the current of a resistor. Using nodal analysis, you should have two equations with two unknowns, making it easier to work with than mesh analysis and the multiple currents. Once you have the voltages, it should be fairly simple to solve for the currents through the resistors.