37 template<
typename floatType>
48 typedef std::function<cmplxType(const cmplxType&)>
funcType;
67 const std::uint32_t maxIterations,
68 const floatType& epsilon ) :
89 throw std::runtime_error(
"Epsilon must be greater than zero!" );
97 if( denominator == 0.0 )
98 throw std::runtime_error(
"Zero denominator in newtons method!" );
99 curGuess -= (numerator / denominator);
100 const floatType curEpsilon{ std::abs( curGuess - prevGuess ) };
102 return( std::move( curGuess ) );
105 throw std::runtime_error(
"Newton's method not converging!" );
const floatType m_epsilon
This attribute holds the required accuracy (that is, tolerance).
~newtonsMethod()
The class destructor.
std::function< cmplxType(const cmplxType &)> funcType
This type is used to declare variables that hold functions whose zeros are being found.
std::complex< floatType > cmplxType
This type is used to declare variables that hold complex numbers.
newtonsMethod(const cmplxType &initialGuess, const funcType &f, const funcType &f_prime, const std::uint32_t maxIterations, const floatType &epsilon)
This is the constructor that must be used to create instances of this class.
const cmplxType m_initialGuess
This attribute holds the caller supplied initial guess.
const funcType m_fPrime
This attribute holds the derivative of the function whose zero is to be found.
This class implements Newton's method (the same one from your typical first year calculus class)...
const cmplxType findZero(std::uint32_t &numIters) const
This method is called to find a zero of the given function, using the given initial guess...
const std::uint32_t m_maxIterations
This attribute holds the maximum number of iterations allowed when searching for a zero...
const funcType m_f
This attribute holds the function whose zero is to be found.