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

circuit analysiscurrent-sourceresistorsvoltage

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 🙁

enter image description here
enter image description here

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.

Best Answer

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

enter image description here