mitsuba-af602c6fd98a/src/libcore/brent.cpp
/**
 * \file brent.cpp
 * \brief Brent's method nonlinear zero finder
 *
 * The implementation is transcribed from the Apache Commons
 * Java implementation.
 */
\file brent.cpp
\brief Brent's method nonlinear zero finder

The implementation is transcribed from the Apache Commons
Java implementation.
\ file brent . cpp \ brief Brent ' s method nonlinear zero finder The implementation is transcribed from the Apache Commons Java implementation .
MTS_NAMESPACE_BEGIN
BrentSolver::Result BrentSolver::solve(const boost::function<Float (Float)> &f,
		Float min, Float max) const {
	Float yMin = f(min);
	if (std::abs(yMin) <= m_absAccuracy)
		return Result(true, 0, min, yMin);
	Float yMax = f(max);
	if (std::abs(yMax) <= m_absAccuracy)
		return Result(true, 0, max, yMax);
	Float sign = yMin * yMax;
	if (sign > 0) {
		SLog(EWarn, "BrentSolver: Function values at the endpoints do not have different signs -- "
			"endpoints: [%f, %f], values: [%f, %f]", min, max, yMin, yMax);
		return Result(false, 0, 0, 0);
	} else {
		return solve(f, min, yMin, max, yMax, min, yMin);
	}
}
MTS_NAMESPACE_BEGIN BrentSolver :: Result BrentSolver :: solve ( const boost :: function < Float ( Float ) > & f , Float min , Float max ) const { Float yMin = f ( min ) ; if ( std :: abs ( yMin ) <= m_absAccuracy ) return Result ( true , 0 , min , yMin ) ; Float yMax = f ( max ) ; if ( std :: abs ( yMax ) <= m_absAccuracy ) return Result ( true , 0 , max , yMax ) ; Float sign = yMin * yMax ; if ( sign > 0 ) { SLog ( EWarn , " " " " , min , max , yMin , yMax ) ; return Result ( false , 0 , 0 , 0 ) ; } else { return solve ( f , min , yMin , max , yMax , min , yMin ) ; } }
\file brent.cpp
 \brief Brent's method nonlinear zero finder
\ file brent . cpp \ brief Brent ' s method nonlinear zero finder
// return the first endpoint if it is good enough // return the second endpoint if it is good enough // solve using only the first endpoint as initial guess