I don't know about libraries but here's a simple Secant solver :
class SecantSolver
{
private int _maxSteps= 10;
private double _precision= 0.1;
public SecantSolver(int maxSteps, double precision)
{
_maxSteps= maxSteps;
_precision= precision;
if (maxSteps <= 0)
throw new ArgumentException("maxSteps is out of range; must be greater than 0!");
if (precision <= 0)
throw new ArgumentException("precision is out of range; must be greater than 0!");
}
private double ComputeNextPoint(double p0, double p1, Func<Double,Double> f)
{
double r0 = f(p0);
double r1 = f(p1);
double p2 = p1 - r1 * (p1-p0) / (r1-r0); // the basic secant formula
return p2;
}
public double Solve( double lowerBound, double upperBound, Func<Double,Double> f, out String message)
{
double p2,p1,p0;
int i;
p0=lowerBound;
p1=upperBound;
p2= ComputeNextPoint(p0,p1,f);
// iterate till precision goal is met or the maximum
// number of steps is reached
for(i=0; System.Math.Abs(f(p2))>_precision &&i<_maxSteps;i++) {
p0=p1;
p1=p2;
p2=ComputeNextPoint(p0,p1,f);
}
if (i < _maxSteps)
message = String.Format("Method converges in " + i + " steps.");
else
message = String.Format("{0}. The method did not converge.", p2);
return p2;
}
}
Usage:
SecantSolver solver= new SecantSolver(200, // maxsteps
0.00000001f/100 // tolerance
);
string message;
double root= solver.Solve(0.10, // initial guess (lower)
1.0, // initial guess (upper)
f, // the function to solve
out message
);