Start with condition number
+use std::marker::PhantomData;
+use crate::structure::ad::{AD, AD1, AD2};
+use State::{P, I};
+
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum RootFind {
Bisection,
@@ -12,20 +16,29 @@ enum State {
}
#[derive(Debug, Clone)]
-struct RootFinder<F: Fn(f64) -> f64> {
+struct RootFinder<T, F>
+where T: AD, F: Fn(T) -> T {
init: State,
curr: State,
f: Box<F>,
+ _marker: PhantomData<T>
}
-//impl RootFinder<F: Fn(f64) -> f64> {
-// fn condition_number(&self) -> f64 {
-// match self.curr {
-// P(p) => {
-// let z = p;
-// let y = self.f(z);
-// let dy =
-// }
-// }
-// }
-//}
+impl<T, F> RootFinder<T, F>
+where T: AD, F: Fn(T) -> T {
+ fn condition_number(&self) -> f64 {
+ match self.curr {
+ P(p) => {
+ let z = AD1::from(p);
+ let fz = (self.f)(z.into()).to_ad1();
+ p * fz.d1 / fz.d0
+ }
+ I(a, b) => {
+ let p = (a + b) / 2f64;
+ let z = AD1::from(p);
+ let fz = (self.f)(z.into()).to_ad1();
+ p * fz.d1 / fz.d0
+ }
+ }
+ }
+}
