public virtual void ComputeSamples()
{
double requiredPower = Power;
// Attempt to locate the optimal sample size
// to attain the required power by locating
// a zero in the difference function:
double sol = BrentSearch.FindRoot(n =>
{
Samples = n;
ComputePower();
return requiredPower - Power;
},
lowerBound: 2,
upperBound: 1e+4);
// Check it
Samples = sol;
ComputePower();
double newPower = Power;
Power = requiredPower;
if (Math.Abs(requiredPower - newPower) > 1e-5)
Samples = Double.NaN;
}