pub struct Integraal<X: Scalar> { /* private fields */ }
Expand description
Main integral computation structure
This structure is used as the entrypoint for integral definition and computation. It follows a pseudo-builder patterns where the function description is reset after a computation. This is the preferred behavior as many different integrals may be computed over the same domain in scientific applications.
§Usage
§Components
The structure is made up of three components that are used to describe the integral the user wishes to compute:
- a
DomainDescriptor
instance, used to describe the space over which the integral span - a
FunctionDescriptor
instance, used to describe the integrated function - a
ComputeMethod
instance, used to choose which numerical integration method will be used for value approximation
In the future, another object might be included to control the execution backend.
§Example
// describe domain; 0 to 1, with a step of 10^-5
let domain = DomainDescriptor::Uniform {
start: 0.0,
step: 0.00001,
n_step: 100_001,
};
// decribe the function; f(x) = 2 * x
let function = FunctionDescriptor::Closure(Box::new(|x: f64| 2.0 * x));
// choose the numerical integration method
let method = ComputeMethod::Trapezoid;
// build the integral & compute it
let mut integral = Integraal::default()
.domain(domain)
.function(function)
.method(method);
assert!(integral.compute().is_ok())
Implementations§
Source§impl<X: Scalar> Integraal<X>
impl<X: Scalar> Integraal<X>
Sourcepub fn domain(self, domain_descriptor: DomainDescriptor<X>) -> Self
pub fn domain(self, domain_descriptor: DomainDescriptor<X>) -> Self
Set the domain descriptor.
Sourcepub fn function(self, function_descriptor: FunctionDescriptor<X>) -> Self
pub fn function(self, function_descriptor: FunctionDescriptor<X>) -> Self
Set the function descriptor.
Sourcepub fn method(self, compute_method: ComputeMethod) -> Self
pub fn method(self, compute_method: ComputeMethod) -> Self
Set the numerical integration method.
Sourcepub fn compute(&mut self) -> Result<X, IntegraalError>
pub fn compute(&mut self) -> Result<X, IntegraalError>
This method attempts to compute the integral. If it is successful, it will clear the
internal FunctionDescriptor
object before returning the result.
§Return / Errors
This method returns a Result
taking the following values:
Ok(X: Scalar)
– The computation succeeded.Err(IntegraalError)
– The computation failed for the reason specified by the enum.