class BjerksundStenslandModel {

  protected double[] getBetaAdjoint(double r, double b, double sigmaSq) {
    double[] res = new double[4];
    double w1 = 0.5 - b / sigmaSq;
    double w2 = 2 * r / sigmaSq;
    double w3 = w1 * w1;
    double w4 = w3 + w2;
    if (w4 < 0) {
      throw new MathException("beta will be complex (see Jira PLAT-2944)");
    }
    double w5 = Math.sqrt(w4);
    double beta = w1 + w5;

    double w5Bar = 1.0;
    double w4Bar = 0.5 / w5 * w5Bar;
    double w3Bar = w4Bar;
    double w2Bar = w4Bar;
    double w1Bar = 1.0 + 2 * w1 * w3Bar;

    res[0] = beta;
    res[1] = 2 / sigmaSq * w2Bar; // rBar
    res[2] = -1 / sigmaSq * w1Bar; // bBar
    res[3] = b / sigmaSq / sigmaSq * w1Bar - w2 / sigmaSq * w2Bar;
    return res;
  }

}