Nodal analysis 4

.PS
include(pstricks.m4)

scale=25.4  # Scale in mm per inch  

cct_init

vsp=20  # Vertical spacing
hsp=20  # Horizontal spacing

O: (0,0)

move to O # Move to the origin point for the circuit

Va: source(up_ vsp,V); lllabel(,v_a,); rlabel(,15\;\text{V},)
{ # Push current first location to the "stack"
  Nc: dot(at Here)
  R1: resistor(up_ vsp); llabel(,R_1,);rlabel(,4\;\text{k}\Omega,)
  { # Push current second location to the "stack"
    Na: dot(at Here)
    arrowline(up_ vsp); llabel(,I_q,)
    R4: resistor(right_ hsp); llabel(,R_4,); rlabel(,2\;\text{k}\Omega,)
    Vb: source(right_ hsp,V,,R); llabel(,v_b,); rlabel(,15\;\text{V},)
    line down to (Here.x,R1.end.y)
    dot(at Here)
  } # Return to the second location on the "stack"
  I1: source(right_ to (Vb.end.x,Here.y),I);llabel(,i_c,); rlabel(,12\;\text{mA},)
  line down to (Here.x, R1.start.y)
} # Return to the first location on the "stack"
R3: resistor(right_ to (Vb.end.x,Here.y));llabel(,R_2,); rlabel(,3\;\text{k}\Omega,)
Nb: dot(at Here)
line down to (Here.x,O.y)
R2: resistor(left_ to O); rlabel(,R_3,); llabel(,1\;\text{k}\Omega,)
dot(at Here)
ground(at Here)

# Label the nodes with their voltages
"$v_1$" at Na.w rjust
"$v_2$" at Nb.e ljust
"$v_3$" at Nc.w rjust
.PE