| 2 Newton method in 2D. |
2 Newton method in 2D. |
| 3 */ |
3 */ |
| 4 |
4 |
| 5 use alg_tools::types::*; |
5 use alg_tools::types::*; |
| 6 |
6 |
| |
7 /// Approximately solves $f(x)=b$ using Newton's method in 1D. |
| |
8 /// |
| |
9 /// The function `g` should return $(f'(x), f(x))$. |
| |
10 /// The initial iterate will be `x`, and exactly `iters` iterations are taken. |
| 7 #[inline] |
11 #[inline] |
| 8 pub fn newton_sym1x1<F : Float>( |
12 pub fn newton_sym1x1<F : Float>( |
| 9 g : impl Fn(F) -> (F, F), |
13 g : impl Fn(F) -> (F, F), |
| 10 mut x : F, |
14 mut x : F, |
| 11 iters : usize |
15 iters : usize |
| 15 x -= b / a |
19 x -= b / a |
| 16 } |
20 } |
| 17 x |
21 x |
| 18 } |
22 } |
| 19 |
23 |
| |
24 /// Approximately solves $f(x)=b$ using Newton's method in "D. |
| |
25 /// |
| |
26 /// The function `g` should return $(∇f(x), f(x))$. |
| |
27 /// The Hessian $A=∇f(x)$ should be symmetric and given in the form $[A_{11}, A_{12}, A_{22}]$. |
| |
28 /// The initial iterate will be `[x1, x2]`, and exactly `iters` iterations are taken. |
| 20 #[inline] |
29 #[inline] |
| 21 pub fn newton_sym2x2<F : Float>( |
30 pub fn newton_sym2x2<F : Float>( |
| 22 g : impl Fn(F, F) -> ([F; 3], [F; 2]), |
31 g : impl Fn(F, F) -> ([F; 3], [F; 2]), |
| 23 [mut x1, mut x2] : [F; 2], |
32 [mut x1, mut x2] : [F; 2], |
| 24 iters : usize |
33 iters : usize |