def VoltageAmplifierThreePort(G, Zi, Zo, Z0=50.0):
    """VoltageAmplifierThreePort
    Three port voltage amplifier
    @param G float voltage gain
    @param Zi float or complex input impedance
    @param Zo float or complex output impedance
    @param Z0 (optional) float reference impedance (defaults to 50 ohms)
    @return list of list s-parameter matrix for a voltage amplifier
    @remark
    The three port voltage amplifier is the same as the four port voltage amplifier with
    ports two and three connected together and exposed as a single port.

    The voltage sense element senses the voltage with the plus terminal at port 1
    and and the minus terminal at port 3 shunted with impedance of Zi.

    The voltage generated by the amplifier has the plus terminal at port 2 and 
    and the minus terminal at port 3 with Zo in series.

    """
    D = -Zo * Zi - 2.0 * Zo * Z0 - 2.0 * Zi * Z0 - 3.0 * Z0 * Z0 + G * Zi * Z0
    S11 = (-Zo * Zi - 2.0 * Zi * Z0 + Z0 * Z0 + G * Zi * Z0) / D
    S12 = -2.0 * Z0 * Z0 / D
    S13 = -2.0 * Z0 * (Zo + Z0) / D
    S21 = -2.0 * Z0 * (G * Zi + Z0) / D
    S22 = (Z0 * Z0 - 2.0 * Zo * Z0 + G * Zi * Z0 - Zo * Zi) / D
    S23 = 2.0 * Z0 * (G * Zi - Zi - Z0) / D
    S31 = 2.0 * Z0 * (-Z0 + G * Zi - Zo) / D
    S32 = -2.0 * Z0 * (Zi + Z0) / D
    S33 = (-Zo * Zi + Z0 * Z0 - G * Zi * Z0) / D
    return [[S11, S12, S13], [S21, S22, S23], [S31, S32, S33]]
