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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

source§

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>,

source§

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.
§

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

§

fn vzip(self) -> V

§

impl<T> Ungil for T
where T: Send,