Struct peroxide::numerical::root::BroydenMethod
source · pub struct BroydenMethod {
pub max_iter: usize,
pub tol: f64,
pub rtol: f64,
}
Expand description
Broyden method
§Type for RootFinder
I
: freeO
: freeT
:Intv<I>
(=([f64; I], [f64; I])
)
§Arguments
max_iter
: Maximum number of iterationstol
: Absolute tolerance
§Caution
- The function should be differentiable
§Example
use peroxide::fuga::*;
use peroxide::numerical::root::{Pt, Intv};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let problem = CircleTangentLine;
let broyden = BroydenMethod { max_iter: 100, tol: 1e-6, rtol: 1e-6 };
let root = broyden.find(&problem)?;
let result = problem.function(root)?;
let norm = result.to_vec().norm(Norm::L2);
assert!(norm < 1e-6);
Ok(())
}
struct CircleTangentLine;
impl RootFindingProblem<2, 2, Intv<2>> for CircleTangentLine {
fn function(&self, x: Pt<2>) -> anyhow::Result<Pt<2>> {
Ok([
x[0] * x[0] + x[1] * x[1] - 1.0,
x[0] + x[1] - 2f64.sqrt()
])
}
fn initial_guess(&self) -> Intv<2> {
([0.0, 0.1], [-0.1, 0.2])
}
}
Fields§
§max_iter: usize
§tol: f64
§rtol: f64
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BroydenMethod
impl RefUnwindSafe for BroydenMethod
impl Send for BroydenMethod
impl Sync for BroydenMethod
impl Unpin for BroydenMethod
impl UnwindSafe for BroydenMethod
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more