https://github.com/tsmith023/rusty-rootsearch
A WIP library for performing multi-root searching of one-dimensional transcendental equations using auto-differentiation in Rust
https://github.com/tsmith023/rusty-rootsearch
auto-differentiation newtons-method rust
Last synced: 10 months ago
JSON representation
A WIP library for performing multi-root searching of one-dimensional transcendental equations using auto-differentiation in Rust
- Host: GitHub
- URL: https://github.com/tsmith023/rusty-rootsearch
- Owner: tsmith023
- License: mit
- Created: 2023-04-04T16:39:02.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-06T10:59:21.000Z (almost 2 years ago)
- Last Synced: 2025-03-08T01:16:26.429Z (10 months ago)
- Topics: auto-differentiation, newtons-method, rust
- Language: Rust
- Homepage:
- Size: 16.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rusty-rootsearch
This is a small Rust-package that performs Newton's method for finding the roots of a function using the method of bisections.
It stands completely on the shoulders of the [num_dual](https://docs.rs/num-dual/latest/num_dual/) crate that implements
auto-differentation for floating point numbers.
In an effort to generalise the implementation, the traits `Derivable` and `Coercable` are defined that allow the user to
define their own types that can be used within the `root_search`, `newton`, and `find_bisections` functions. The `Derivable` trait is used to
define the derivative of a number, which in the current implementation works well with the `num_dual` crate. The `Coercable`
trait is used to convert a floating point number into the type that is derivable. This is useful for example when using
the `f64` type, which is not derivable, but can be converted to a `Dual` type exposed by the `num_dual` crate.
## Example
```rust
use rusty_rootsearch::{root_search};
use num_dual::*;
fn find_sine_roots() {
fn sine>(x: D) -> D {
x.sin()
}
let roots = root_search::<_,Dual32,f32>(&sine, -5.0, 5.0, 2000, 1000, 0.0001);
for root in &roots.0 {
println!("root: {}", root);
}
assert_eq!(roots.0.len(), 3);
assert!(roots.0.contains(&std::f32::consts::PI));
assert!(roots.0.contains(&(-std::f32::consts::PI)));
assert!(roots.0.contains(&0.0));
}
```