@@ -5,7 +5,7 @@ Optional keyword arguments give the tolerances `reltol` and `abstol`.
5
5
and a `debug` boolean argument that prints out diagnostic information."""
6
6
7
7
function newton1d {T} (f:: Function , f′:: Function , x:: Interval{T} ;
8
- reltol= eps (T), abstol= eps (T), debug= false )
8
+ reltol= 10 eps (T), abstol= eps (T), debug= false )
9
9
10
10
L = Interval{T}[]
11
11
@@ -15,34 +15,50 @@ function newton1d{T}(f::Function, f′::Function, x::Interval{T};
15
15
16
16
while ! isempty (L)
17
17
X = pop! (L)
18
+
19
+ debug && (print (" Current interval popped: " ); @show X)
20
+
18
21
m = mid (X)
19
22
if (isempty (X))
20
23
continue
21
24
end
22
25
23
26
if 0 ∉ f′ (X)
27
+
28
+ debug && println (" 0 ∉ f′(X)" )
29
+
24
30
while true
25
31
m = mid (X)
26
32
N = m - (f (Interval (m)) / f′ (X))
33
+
34
+ debug && (print (" Newton step: " ); @show (X, X ∩ N))
35
+
27
36
X = X ∩ N
28
37
29
38
if isempty (X)
30
39
break
31
40
32
41
elseif 0 ∈ f (Interval (prevfloat (m), nextfloat (m)))
33
42
push! (R, Root (X, :unique ))
43
+
44
+ debug && @show " Root found" , X
45
+
34
46
break
35
47
end
36
48
end
37
49
38
50
else
39
51
# 0 ∈ f'(X)
52
+
53
+ debug && println (" 0 ∈ f'(X)" )
54
+
40
55
expansion_pt = Inf
41
56
# expansion point for the newton step might be m, X.lo or X.hi according to some conditions
42
57
43
58
if 0 ∈ f (Interval (mid (X)))
44
59
# 0 ∈ fⁱ(x)
45
- # Step 7
60
+
61
+ debug && println (" 0 ∈ fⁱ(x)" )
46
62
47
63
if 0 ∉ f (Interval (X. lo))
48
64
expansion_pt = X. lo
@@ -59,16 +75,24 @@ function newton1d{T}(f::Function, f′::Function, x::Interval{T};
59
75
continue
60
76
61
77
else
62
- push! (R, Root (X, :unique ))
78
+ push! (R, Root (X, :unknown ))
79
+
80
+ debug && @show " Multiple root found" , X
81
+
63
82
continue
64
83
end
65
84
end
66
85
67
86
else
68
87
# 0 ∉ fⁱ(x)
69
88
89
+ debug && println (" 0 ∉ fⁱ(x)" )
90
+
70
91
if (diam (X)/ mag (X)) < reltol && diam (f (X)) < abstol
71
92
push! (R, Root (X, :unknown ))
93
+
94
+ debug && @show " Tolerance root found" , X
95
+
72
96
continue
73
97
end
74
98
end
@@ -98,6 +122,9 @@ function newton1d{T}(f::Function, f′::Function, x::Interval{T};
98
122
99
123
else
100
124
N = expansion_pt - (f (Interval (expansion_pt))/ f′ (X))
125
+
126
+ debug && (print (" Newton step: " ); @show (X, X ∩ N))
127
+
101
128
X = X ∩ N
102
129
m = mid (X)
103
130
0 commit comments