blob: 6d23576cce768da7e94fc4cbcb8689ee418172c6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
Use a bisection criterion for a start
Hybrid Method: combine Bisection and Higher Order Method:
- Newton's Method
- Secant Method (Newton's method with secant approx.)
#+BEGIN_SRC c
fa = f(a)
fb = f(b)
if (fa * fb >= 0) return
error = 10 * tol
iter = 0
while (error > tol && iter < maxiter) {
x0 = 0.5 * (a + b)
x1 = x0 - f(x0) / f'(x0)
if (abs(x1 - x0) > 0.5 * (b - a)) {
// do bisection
} else{
// do newton's method
}
}
#+END_SRC
|