Module rootfind::wrap [] [src]

Mathematical traits and generic function wrappers.

This module provides three simple traits

  • RealFnEval
  • RealDfEval
  • RealD2fEval

indicating that a functor computes f(x), df(x), and d2f(x) respectively. The rootfind library uses these type bounds to help implement generic driver routines.

Users generally do not have to care about these traits. Instead, generic structs adapt one or more supplied Fn(64) -> f64 arguments:

  • RealFn - f(x)
  • RealFnAndFirst - f(x) and df(x)
  • RealFnAndFirstSecond - f(x), df(x), and d2f(x)

Just invoke the appropriate generic struct and you're ready to go:

use rootfind::wrap;

let in_f = |x: f64| x.sin();
let in_df = |x: f64| x.cos();

let f = wrap::RealFnAndFirst::new(&in_f, &in_df);

// f can now be used in bisection or Newton-Raphson

The example's wrapped f won't compile with Halley's method because that requires the second derivative. We would need RealFnAndFirstSecond instead:

use rootfind::wrap;

let in_f = |x: f64| x.sin();
let in_df = |x: f64| x.cos();
let in_d2f = |x: f64| -x.sin();

let f = wrap::RealFnAndFirstSecond::new(&in_f, &in_df, &in_d2f);

// f can now be used in bisection, Newton-Raphson, or Halley's method

Structs

RealFn

Wraps function to implement RealFnEval.

RealFnAndFirst

Wraps functions to implement RealFnEval and RealDfEval.

RealFnAndFirstSecond

Wraps functions to implement RealFnEval, RealDfEval, and RealD2fEval.

Traits

RealD2fEval

Trait evaluating the second derivative d2f(x) with d2f: R1 ⟶R1.

RealDfEval

Trait evaluating the derivative df(x) with df: R1 ⟶ R1.

RealFnEval

Trait evaluating f(x) with f: R1 ⟶ R1.