# Node analysis with voltage source in matrix form

simulate this circuit – Schematic created using CircuitLab

Can you please check if my reasoning is correct?

The sum of currents leaving node k is: $$I_k = \sum_{i = 0}^{n} I_{ki} = \sum_{i = 0}^{n} G_{ki}(V_k - V_i)$$ Assuming the system is linear: $$I_k = \sum_{i = 0 (i \neq k)}^{ n} G_{ki} V_k - \sum_{i = 1 ( i \neq k)}^{n} G_{ki}V_i = G_{kk}V_k - \sum_{i = 1 ( i \neq k)}^{n} G_{ki} V_i$$ where: $$G_{kk} = \sum_{i = 0 (i \neq k)}^{n} G_{ki}$$ then we have: $$I_n = -G_{n1}V_1 - G_{n2} ... + G_{nn}V_n$$ which in matrix form gives: $$\begin{bmatrix}I_1 \\ I_2 \\. \\ . \\ . \\ I_n\end{bmatrix} = \begin{bmatrix} G_{11}& -G_{12}& -G_{13} ... &-G_{1n} \\ -G_{21}& G_{22}& -G_{23} ... &-G_{2n} \\ .&.&.&. \\ .&.&.&. \\ .&.&.&. \\ -G_{n1}& -G_{n2}& -G_{n3} ... &G_{nn} \end{bmatrix}\begin{bmatrix}V_1 \\ V_2 \\. \\ . \\ . \\ V_n\end{bmatrix}$$ In case there is an ideal voltage source connected between a node and the reference, then the voltage of that node is equal to the EMF of that voltage source. So in matrix form we have(if for example node 1 was connected to an ideal voltage source): $$\begin{bmatrix}E_1 \\ I_2 \\. \\ . \\ . \\ I_n\end{bmatrix} = \begin{bmatrix} 1& 0& 0 ... &0 \\ -G_{21}& G_{22}& -G_{23} ... &-G_{2n} \\ .&.&.&. \\ .&.&.&. \\ .&.&.&. \\ -G_{n1}& -G_{n2}& -G_{n3} ... &G_{nn} \end{bmatrix}\begin{bmatrix}V_1 \\ V_2 \\. \\ . \\ . \\ V_n\end{bmatrix}$$ However, if we have an ideal voltage source between two nodes (neither of them being the reference), for example between nodes 1 and 3 we have E, then we have: $$\begin{bmatrix}I_1 \\ I_2 \\E \\ . \\ . \\ I_n\end{bmatrix} = \begin{bmatrix} G_{11}& -G_{12}& -G_{13} ... &-G_{1n} \\ -G_{21}& G_{22}& -G_{23} ... &-G_{2n} \\ -1&0&1&0 \\ .&.&.&. \\ .&.&.&. \\ -G_{n1}& -G_{n2}& -G_{n3} ... &G_{nn} \end{bmatrix}\begin{bmatrix}V_1 \\ V_2 \\. \\ . \\ . \\ V_n\end{bmatrix}$$ My professor claimed that the third case had a more elegant solution which included adding an imaginary node and a new current, but I cannot understand what he meant, any insight?

The "third case" your professor mentioned deals with the issue that you don't always want to replace an existing KCL equation with the voltage source equation. This is especially true in circuit simulators, where an extra equation doesn't mean much. In that case, you want to add the voltage source equation, while keeping all the other KCL equations, but then you end up with $$\n+1\$$ equations for $$\n\$$ unknowns.
$$\left(\begin{matrix} G_{11} & \dots & G_{1A} & \dots & G_{1B} & \dots & G_{1n} & 0 \\ \vdots & & \vdots & & \vdots & & \vdots & \vdots \\ G_{A1} & \dots & G_{AA} & \dots & G_{AB} & \dots & G_{An} & 1 \\ \vdots & & \vdots & & \vdots & & \vdots & \vdots \\ G_{B1} & \dots & G_{BA} & \dots & G_{BB} & \dots & G_{Bn} & -1 \\ \vdots & & \vdots & & \vdots & & \vdots & \vdots \\ G_{n1} & \dots & G_{nA} & \dots & G_{nB} & \dots & G_{nn} & 0 \\ 0 & \dots & 1 & \dots & -1 & \dots & 0 & 0 \end{matrix}\right)\left( \begin{matrix} V_1 \\ \vdots \\ V_A \\ \vdots \\ V_B \\ \vdots \\ V_n \\ I_V \end{matrix}\right) = \left(\begin{matrix} I_1 \\ \vdots \\ I_A \\ \vdots \\ I_B \\ \vdots \\ I_n \\ V \end{matrix}\right)$$
where the voltage source is connected between nodes $$\A\$$ and $$\B\$$, and $$\I_V\$$ is the current flowing through the voltage source. If either A or B are grounded, then you can remove row and column A or B respectively.