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: free
  • O: free
  • T: Intv<I> (=([f64; I], [f64; I]))

§Arguments

  • max_iter: Maximum number of iterations
  • tol: 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§

source§

impl<const I: usize, const O: usize> RootFinder<I, O, ([f64; I], [f64; I])> for BroydenMethod

source§

fn max_iter(&self) -> usize

source§

fn tol(&self) -> f64

source§

fn find<P: RootFindingProblem<I, O, Intv<I>>>( &self, problem: &P, ) -> Result<Pt<I>>

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V