The OpenD Programming Language

secantMethod

Implements the secant method for finding a root of the function fun starting from points [xn_1, x_n] (ideally close to the root). Num may be float, double, or real.

template secantMethod(alias fun)
Num
secantMethod
(
Num
)
(
Num xn_1
,
Num xn
)

Examples

import std.math.operations : isClose;
import std.math.trigonometry : cos;

float f(float x)
{
    return cos(x) - x*x*x;
}
auto x = secantMethod!(f)(0f, 1f);
assert(isClose(x, 0.865474));

Meta