Nodal analysis

In electric circuits analysis, nodal analysis, node-voltage analysis, or the branch current method is a method of determining the voltage (potential difference) between "nodes" (points where elements or branches connect) in an electrical circuit in terms of the branch currents.
In analyzing a circuit using Kirchhoff's circuit laws, one can either do nodal analysis using Kirchhoff's current law (KCL) or mesh analysis using Kirchhoff's voltage law (KVL). Nodal analysis writes an equation at each electrical node, requiring that the branch currents incident at a node must sum to zero. The branch currents are written in terms of the circuit node voltages. As a consequence, each branch constitutive relation must give current as a function of voltage; an admittance representation. For instance, for a resistor, Ibranch = Vbranch * G, where G (=1/R) is the admittance (conductance) of the resistor.
Nodal analysis is possible when all the circuit elements' branch constitutive relations have an admittance representation. Nodal analysis produces a compact set of equations for the network, which can be solved by hand if small, or can be quickly solved using linear algebra by computer. Because of the compact system of equations, many circuit simulation programs (e.g., SPICE) use nodal analysis as a basis. When elements do not have admittance representations, a more general extension of nodal analysis, modified nodal analysis, can be used.
Examples.
Basic case1.
The only unknown voltage in this circuit is V1. There are three connections to this node and consequently three currents to consider. The direction of the currents in calculations is chosen to be away from the node.
With Kirchhoff's current law, we get:
formula_1
This equation can be solved with respect to V1:
formula_2
Finally, the unknown voltage can be solved by substituting numerical values for the symbols. Any unknown currents are easy to calculate after all the voltages in the circuit are known.
formula_3
Supernodes.
 In this circuit, we initially have two unknown voltages, V1 and V2. The voltage at V3 is already known to be VB because the other terminal of the voltage source is at ground potential.
The current going through voltage source VA cannot be directly calculated. Therefore, we cannot write the current equations for either V1 or V2. However, we know that the same current leaving node V2 must enter node V1. Even though the nodes cannot be individually solved, we know that the combined current of these two nodes is zero. This combining of the two nodes is called the supernode technique, and it requires one additional equation: V1 = V2 + VA.
The complete set of equations for this circuit is:
formula_4
By substituting V1 to the first equation and solving in respect to V2, we get:
formula_5
Matrix form for the node-voltage equation.
In general, for a circuit with formula_6 nodes, the node-voltage equations obtained by nodal analysis can be written in a matrix form as derived in the following.
For any node formula_7, KCL states formula_8 where formula_9 is the negative of the sum of the conductances between nodes formula_7 and formula_11, and formula_12 is the voltage of node formula_7.
This implies formula_14 where formula_15 is the sum of conductances connected to node formula_7. 
We note that the first term contributes linearly to the node formula_7 via formula_15, while the second term contributes linearly to each node formula_11 connected to the node formula_7 via formula_21 with a minus sign.
If an independent current source/input formula_22 is also attached to node formula_7, the above expression is generalized to formula_24.
It is readily to show that one can combine the above node-voltage equations for all formula_6 nodes, and write them down in the following matrix form
or simply
The matrix formula_28 on the left hand side of the equation is singular since it satisfies formula_29 where formula_30 is a formula_31 column matrix. This corresponds to the fact of current conservation, namely, formula_32, and the freedom to choose a reference node (ground). In practice, the voltage is the reference node is taken to be 0. Consider it is the last node, formula_33. In this case, it is straightforward to verify that the resulting equations for the other formula_34 nodes remain the same, and therefore one can simply discard the last column as well as the last line of the matrix equation. This procedure results in a formula_35 dimensional non-singular matrix equation with the definitions of all the elements stay unchanged.