def TransconductanceAmplifierThreePort(G, Zi, Zo, Z0=50.0):
    """TransconductanceAmplifierThreePort
    Three port transconductance amplifier
    @param G float transconductance 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 transconductance amplifier.
    @remark
    The three port transconductance amplifier is the same as the four port transconductance 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 current generated by the amplifier enters port 3 and exits port 2 and
    is shunted with Zo.

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