/* * use R built-in root finder API :R_zeroin */ double solve(double b, double w) { // w == 0 means its really arcsinh if (w == 0) { return(b); } // precision is the same as that of b double tolerance = 2 * b * Double.Epsilon; sfun_info param = new sfun_info() { b = b, w = w }; // bracket the root double d_lo = 0; double d_hi = b; int MaxIt = 20; double d; d = R_zeroin(d_lo, d_hi, logicle_fn, param, ref tolerance, ref MaxIt); return(d); }
// f(w,b) = 2 * (ln(d) - ln(b)) + w * (b + d) double logicle_fn(double x, dynamic info) { sfun_info p = (sfun_info)info; double B = 2 * (Math.Log(x) - Math.Log(p.b)) + p.w * (p.b + x); return(B); }
/* * use R built-in root finder API :R_zeroin */ double solve(double b, double w) { // w == 0 means its really arcsinh if (w == 0) return b; // precision is the same as that of b double tolerance = 2 * b * Double.Epsilon; sfun_info param = new sfun_info() { b = b, w = w }; // bracket the root double d_lo = 0; double d_hi = b; int MaxIt = 20; double d; d = R_zeroin(d_lo, d_hi, logicle_fn, param, ref tolerance, ref MaxIt); return d; }