Skip to content

Approximately integrate a single variable function in rust

Notifications You must be signed in to change notification settings

xnought/integral-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Integral Rust

Approximate integration of a function from point a to b for a single variable x.

For example,

// integral of e^{-x^2}
let bell_curve = |x: f64| (-x.powi(2)).exp();

// evaluated from 0 to 2
let from = 0.0;
let to = 2.0;
let num_iterations = 100_000;

let area = integrate(bell_curve, from, to, num_iterations);

println!("{}", area);
// \int_{0}^{2} e^{-x^2} dx = 0.8820915739164501
// supposed to be 0.882081390762, so pretty good!

In desmos this is what that integration would be evaluated to Screenshot 2023-04-15 at 6 50 38 PM

About

Approximately integrate a single variable function in rust

Topics

Resources

Stars

Watchers

Forks

Languages