
Function: XY2
*************
  Purpose: Fit chemical shift or linebroadening for binding equilibrium such as 
    P + L <-> P:L + L <-> P:L2 when observing P and varying L. 
  Parameters: S_LM1, Kd1, S_LM2, Kd2 
    Kd1 = [P][L]/[PL] 
    Kd2 = [PL][L]/[PL2]
    S_LM1 = dPL - dFree 
    S_LM2 = dPL2 - dFree
		where d refers to chemical shift delta.

  Notes:
    This function converges easier with the Levenberg-Marquardt algorithm.
    Remember that if you do not attain convergence, try holding one or more
    parameters as a constant.  eg, try holding Kd2 constant to achieve convergence.
    This function expects 3 column data.

  Reference:
    Williams, T.C., J.G. Shelling and B.D. Sykes. NMR approaches to the characterization
    of the interaction of metal ions with proteins.  In: NMR in the Life Sciences
    (Ed. E.M. Bradbury and C. Nicolini) Plenum Publishing Co., 
    New York-London NATO-ASI Series A Life Sciences 107:93-103 (1986).

  C-code:
    b = Kd2 - 4 * Kd1;
    c = Kd2 * Kd2;
    d = (c - (4 * Kd1 * Kd2) - (2 * x2 * Kd2)) / b;
    e = ((x * Kd2 * (2*x2 - x)) - (c * (x2 + Kd1 + x))) / b;
    f = -(2*d*d*d - 9*d*e + (27 * ((x*x2*c) / b))) / 54.0;
    g = (3*e - d*d) / 3.0;
    if (g > 0) return(FALSE);
    w = f / sqrt(-(g*g*g) / 27.0);
    if ((w > 1.0) || (w < -1.0)) return(FALSE);
    h = TO_DEG * acos(w);
    x3 = (2 * sqrt(-g/3.0) * cos(((h/3.0)+240)*TO_RAD) - (d/3.0));
    answer = ((S_LM1*x3) + (S_LM2*x3 * (x-x3)/(2*x3+Kd2))) / x2;
