quad-rs
This crate provides an implementation of adaptive Gauss-Kronrod integration. It aims to provide a suite of integration methods including:
- Adaptive integration with high-accuracy
- Native support for complex integrals and paths
- Native support for contour integration in the complex plane
- Native support for integration of vector and scalar valued functions
- Optional storage and return of the integrand at the evaluation points
Overview
A problem to be integrated needs to implement the Integrable trait. This has one method integrand, which takes the integration variable as an argument and returns the integrand. The type of the integration variable Input and the integrand Output must also be defined.
use Integrable;
To solve the problem an Integrator is used
use Integrator;
let integrator = default
.with_maximum_iter
.relative_tolerance;
let range = Range ;
let solution = integrator.integrate.unwrap;
Example - Real Integration
use ;
let integrator = default
.with_maximum_iter
.relative_tolerance;
let range = Range ;
let solution = integrator.integrate.unwrap;
let analytical_result = E - 1. / E;
assert_relative_eq!
Example - Complex Integration
use ;
use Complex;
use Range;
let integrator = default
.with_maximum_iter
.relative_tolerance;
let range = Range ;
let solution = integrator.integrate.unwrap;
Example - Real to Complex Integration
use ;
use Complex;
use Range;
let integrator = default
.with_maximum_iter
.relative_tolerance;
let range = Range ;
let solution = integrator
.integrate_real_complex
.unwrap;
let result = solution.result.result.unwrap;
let analytical_result = E - 1. / E;
dbg!;
Example - Contour Integration
use
use Complex;
let x_range =-5f64..5f64;
let y_range = -5f64..5f64;
let contour = generate_rectangular;
let integrator = default
.with_maximum_iter
.relative_tolerance;
let solution = integrator.contour_integrate.unwrap;