Expand description
Root finding algorithms
This module provides methods for finding roots of scalar functions of one or more variables.
§Example
use scirs2_core::ndarray::{array, Array1, Array2};
use scirs2_optimize::roots::{root, Method};
// Define a function for which we want to find the root
fn f(x: &[f64]) -> Array1<f64> {
let x0 = x[0];
let x1 = x[1];
array![
x0.powi(2) + x1.powi(2) - 1.0, // x^2 + y^2 - 1 = 0 (circle equation)
x0 - x1 // x = y (line equation)
]
}
// Optional Jacobian function that we're not using in this example
fn jac(x: &[f64]) -> Array2<f64> {
Array2::zeros((2,2))
}
// Initial guess
let x0 = array![2.0, 2.0];
// Find the root - with explicit type annotation for None
let result = root(f, &x0, Method::Hybr, None::<fn(&[f64]) -> Array2<f64>>, None)?;
// The root should be close to [sqrt(0.5), sqrt(0.5)]
assert!(result.success);
Structs§
- Options
- Options for the root finder.
Enums§
- Method
- Root finding methods.
Functions§
- root
- Find a root of a vector function.