├── README.md
├── upload.sh
├── newton-krawczyk-time.jl
├── atahualpa.jl
├── krawczyk2d-tests.jl
├── newton-krawczyk-time.txt
├── logistic-map.jl
├── newton2d.jl
├── modules
├── NewtonMethod.jl
├── tests-krawczyk.jl
├── tests-newton.jl
├── ad-benet.jl
├── AutoDiff.jl
├── KrawczykMethod.jl
└── IntervalArithmetic.jl
├── krawczyk2d.jl
├── 2D bisection.ipynb
├── krawczyk2d-tests-solutions.nb
├── newton-sin.ipynb
├── .ipynb_checkpoints
├── newton-sin-checkpoint.ipynb
└── krawczyk2d-examples-checkpoint.ipynb
├── logistic-arbitrary.jl
├── krawczyk2d-examples.ipynb
├── LICENSE
└── newton2d-examples.ipynb
/README.md:
--------------------------------------------------------------------------------
1 | interval-methods
2 | ===========
3 |
--------------------------------------------------------------------------------
/upload.sh:
--------------------------------------------------------------------------------
1 | git push https://kriukov@github.com/kriukov/interval-methods
2 |
--------------------------------------------------------------------------------
/newton-krawczyk-time.jl:
--------------------------------------------------------------------------------
1 | using NewtonMethod
2 | using KrawczykMethod
3 |
4 | f(x) = 5040 - 3828x - 2356x^2 + 1009x^3 + 200x^4 - 62x^5 - 4x^6 + x^7
5 | a = Interval(-20, 20)
6 | @time newton(f, a, 128)
7 | @time krawczyk(f, a, 128)
8 |
9 | f(x) = x^2 - 4
10 | @time newton(f, a, 128)
11 | @time krawczyk(f, a, 128)
12 |
13 | f(x) = exp(x^2) - 4
14 | a = Interval(-4, 4)
15 | @time newton(f, a, 128)
16 | @time krawczyk(f, a, 128)
17 |
18 | f(x) = log(x^2 - 1) + x + 1
19 | a = Interval(-10, -1.1)
20 | @time newton(f, a, 128)
21 | @time krawczyk(f, a, 128)
22 |
23 | a = Interval(1.1, 10)
24 | @time newton(f, a, 128)
25 | @time krawczyk(f, a, 128)
26 |
--------------------------------------------------------------------------------
/atahualpa.jl:
--------------------------------------------------------------------------------
1 |
2 | function first_collision(irr, delta)
3 |
4 | irr0 = irr
5 |
6 | arr_a = Integer[]
7 |
8 | n = 0
9 | while n <= 38
10 | a = floor(irr)
11 | #println(a)
12 | @show push!(arr_a, a)
13 | @show irr = 1/(irr - a)
14 | n += 1
15 | end
16 |
17 |
18 | h = Integer[]
19 | push!(h, 0, 1)
20 | for i = 3:40
21 | push!(h, arr_a[i-2]*h[i-1] + h[i-2])
22 | end
23 | shift!(h)
24 | shift!(h)
25 |
26 |
27 | k = Integer[]
28 | push!(k, 1, 0)
29 | for i = 3:40
30 | push!(k, arr_a[i-2]*k[i-1] + k[i-2])
31 | end
32 | shift!(k)
33 | shift!(k)
34 |
35 | #for i = 1:length(h)
36 | # println("$(abs(irr0 - h[i]/k[i])), $(1/(sqrt(5)*(k[i])^2))")
37 | # @show abs(irr0 - h[i]/k[i]) <= 1/(sqrt(5)*(k[i])^2)
38 | #end
39 |
40 |
41 | function first_solution(alpha, delta)
42 | n = 1
43 | while k[n] < 1/(sqrt(1 + alpha^2)*sqrt(5)*delta)
44 | n +=1
45 | end
46 | [k[n], h[n]]
47 | end
48 |
49 | first_solution(irr0, delta)
50 | end
51 |
--------------------------------------------------------------------------------
/krawczyk2d-tests.jl:
--------------------------------------------------------------------------------
1 | # Exercises from the Ramon Moore book
2 |
3 | f(x) = [x[1]^2 + x[2]^2 - 1, x[1] - x[2]^2]
4 | a = [Interval(0.5, 0.8), Interval(0.6, 0.9)]
5 | krawczyk2d(f, a, 64)
6 | trueroots = [(sqrt(5) - 1)/2, sqrt((sqrt(5) - 1)/2)]
7 |
8 |
9 | f(x) = [20 - 20x[1] - x[2], x[1] - x[2]/20 - 1e-9*exp(x[2]/0.052)]
10 | a = [Interval(0.5, 1.2), Interval(0.6, 1.2)]
11 | krawczyk2d(f, a, 64)
12 | trueroots = [0.9464142468335176, 1.0717150633296477]
13 |
14 |
15 | f(x) = [0.5*(-(17.76x[1] - 103.79x[1]^2 + 229.62x[1]^3 - 226.31x[1]^4 + 83.72x[1]^5) + x[2]), 0.2*(-x[1] - 1.5x[2] + 1.2)]
16 |
17 | a = [Interval(0.01, 0.1), Interval(0.7, 0.9)]
18 | a = [Interval(0.7, 0.9), Interval(0.1, 0.3)]
19 | a = [Interval(0.11, 0.3), Interval(0.5, 0.69)]
20 |
21 | a = [Interval(0.01, 1), Interval(0.01, 1)]
22 |
23 | trueroots = [0.06263595920972119, 0.758242693860186]
24 | trueroots = [0.8844295888702942, 0.21038027408647064]
25 | trueroots = [0.2853687241300338, 0.6097541839133109]
26 |
--------------------------------------------------------------------------------
/newton-krawczyk-time.txt:
--------------------------------------------------------------------------------
1 | Comparison between Newton and Krawczyk methods made by running file newton-krawczyk-time.jl. It is seen that Newton is faster than Krawczyk (after "Function calls", the first time value is of Newton, the second is of Krawczyk)
2 |
3 | Function calls: 16
4 | elapsed time: 1.565580033 seconds (252322430 bytes allocated, 4.00% gc time)
5 | elapsed time: 9.915345432 seconds (3577530829 bytes allocated, 15.90% gc time)
6 |
7 | Function calls: 10
8 | elapsed time: 0.017599943 seconds (3370058 bytes allocated)
9 | elapsed time: 0.258211858 seconds (113664575 bytes allocated)
10 |
11 | Function calls: 11
12 | elapsed time: 0.024908051 seconds (5353331 bytes allocated)
13 | elapsed time: 0.475278221 seconds (156370354 bytes allocated, 18.42% gc time)
14 |
15 | Function calls: 11
16 | elapsed time: 0.039670328 seconds (6722259 bytes allocated)
17 | elapsed time: 0.585135394 seconds (206057476 bytes allocated, 13.86% gc time)
18 |
19 | Function calls: 6
20 | elapsed time: 0.00397811 seconds (1490223 bytes allocated)
21 | elapsed time: 0.022749604 seconds (9578812 bytes allocated)
22 |
--------------------------------------------------------------------------------
/logistic-map.jl:
--------------------------------------------------------------------------------
1 | using NewtonMethod
2 |
3 | # Function composition
4 | compose(f::Function, g::Function) = x -> f(g(x))
5 |
6 | # Logistic function T(x) of the first order
7 | T1(x) = Interval(r)*(Interval(1/4)-(x-Interval(1/2))^2)
8 |
9 | # T^p (x) function - T(T(T(...T(x)))) p times
10 | function T(x, p)
11 | F = T1
12 | for i = 1:p-1
13 | F = compose(F, T1)
14 | end
15 | return F(x)
16 | end
17 |
18 | # Equation to solve for periodic points
19 |
20 | f(x, p) = T(x, p) - x
21 |
22 | point(f) = newton(f, Interval(0.0001, 1.), 50)
23 |
24 | r = 1.5
25 | f(x) = T(x, 1) - x
26 |
27 | println("$r $(point(f))")
28 |
29 | r = 2
30 | f(x) = T(x, 1) - x
31 | println("$r $(point(f))")
32 |
33 | r = 2.5
34 | f(x) = T(x, 1) - x
35 | println("$r $(point(f))")
36 |
37 | r = 3
38 | f(x) = T(x, 1) - x
39 | println("$r $(point(f))")
40 |
41 | r = 3.2
42 | f(x) = (T(x, 2) - x)/(T(x, 1) - x)
43 | println("$r $(point(f))")
44 |
45 | r = 3.5
46 | f(x) = (T(x, 4) - x)/(T(x, 2) - x)
47 | println("$r $(point(f))")
48 |
49 | r = 3.75
50 | for i = 1:8
51 | f(x) = T(x, i) - x
52 | println("$r $(point(f))")
53 | end
54 |
--------------------------------------------------------------------------------
/newton2d.jl:
--------------------------------------------------------------------------------
1 | using IntervalArithmetic
2 | using AutoDiff
3 |
4 |
5 | function newton2d(f, a::Array{Interval, 1}, bigprec::Integer=64)
6 |
7 | set_bigfloat_precision(bigprec)
8 |
9 | # center() makes degenerate interval midpoints of the intervals in an array
10 | center(x) = make_intervals(mid(x))
11 | N(x) = center(x) - inv(jacobian(f, x))*f(center(x))
12 |
13 | # If a is symmetric, i.e., mid(a) = 0, the process may stall. The initial interval should be slightly asymmetrized then
14 | #if mid(a) == 0
15 | # a = Interval(a.lo, a.hi + 0.0001*mag(a))
16 | #end
17 |
18 | roots_array = Array{Interval, 1}[]
19 |
20 | push!(roots_array, a)
21 |
22 | k = 0
23 | while true
24 |
25 | roots_array_new = Array{Interval, 1}[]
26 |
27 | for i = 1:length(roots_array)
28 | if isectext(roots_array[i], N(roots_array[i])) != false
29 | @show roots_array_new = push!(roots_array_new, isectext(roots_array[i], N(roots_array[i])))
30 | end
31 | end
32 |
33 | # Exit criterion
34 | if roots_array_new == roots_array
35 | break
36 | end
37 |
38 | @show roots_array = roots_array_new
39 | k += 1
40 | end
41 |
42 | println("Function calls: ", k)
43 | return roots_array
44 | end
45 |
--------------------------------------------------------------------------------
/modules/NewtonMethod.jl:
--------------------------------------------------------------------------------
1 | ## Newton's method (interval) code
2 |
3 | module NewtonMethod
4 | export newton, differentiate, Interval, rad, diam, mid, mig, mag, belong, hd, hull, isect, isectext
5 |
6 | using AutoDiff
7 |
8 | println("Syntax: newton(function, Interval(lo, hi), precision [default is 64])")
9 |
10 | function newton(f::Function, a::Interval, bigprec::Integer=64)
11 |
12 | set_bigfloat_precision(bigprec)
13 |
14 | center(x) = Interval(mid(x))
15 | N(x) = center(x) - f(center(x))//differentiate(f, x)
16 |
17 | # If a is symmetric, i.e., mid(a) = 0, the process may stall. The initial interval should be slightly asymmetrized then
18 | if mid(a) == 0
19 | a = Interval(a.lo, a.hi + 0.0001*mag(a))
20 | end
21 |
22 | roots_array = Interval[]
23 |
24 | push!(roots_array, a)
25 |
26 | k = 0
27 | while true
28 |
29 | roots_array_new = Interval[]
30 |
31 | for i = 1:length(roots_array)
32 | if isectext(roots_array[i], N(roots_array[i])) != false
33 | roots_array_new = vcat(roots_array_new, isectext(roots_array[i], N(roots_array[i])))
34 | end
35 | end
36 |
37 | # Exit criterion
38 | if roots_array_new == roots_array
39 | break
40 | end
41 |
42 | roots_array = roots_array_new
43 | k += 1
44 | end
45 |
46 | println("Function calls: ", k)
47 | return roots_array
48 | end
49 |
50 | # end of module
51 | end
52 |
--------------------------------------------------------------------------------
/modules/tests-krawczyk.jl:
--------------------------------------------------------------------------------
1 | using Base.Test
2 | using KrawczykMethod
3 |
4 | # Transcendental true roots were found using Wolfram Mathematica
5 |
6 | a = Interval(-20, 20)
7 |
8 | enclosure(x) = Interval(x - 5000*eps(BigFloat), x + 5000*eps(BigFloat))
9 |
10 | function checkroots(f, trueroots)
11 | roots = krawczyk(f, a, 64)
12 | # Check if both ends of the found interval lie within the 10eps-enclosure of the true root
13 | n = 0
14 | for i = 1:length(roots)
15 | if belong(roots[i][1].lo, enclosure(trueroots[i])) == false && belong(roots[i][1].hi, enclosure(trueroots[i])) == false
16 | n += 1
17 | end
18 | end
19 | n == 0
20 | end
21 |
22 | f(x) = x^2 - 4
23 | trueroots = [-2, 2]
24 | @test checkroots(f, trueroots)
25 |
26 | f(x) = 5040 - 3828x - 2356x^2 + 1009x^3 + 200x^4 - 62x^5 - 4x^6 + x^7
27 | trueroots = [-6, -4, -2, 1, 3, 5, 7]
28 | @test checkroots(f, trueroots)
29 |
30 | f(x) = exp(x^2) - 4
31 | a = Interval(-4, 4)
32 | trueroots = [-sqrt(log(4)), sqrt(log(4))]
33 | @test checkroots(f, trueroots)
34 |
35 | # The next function is undefined in [-1, 1], so we split the interval manually
36 | f(x) = log(x^2 - 1) + x + 1
37 | a = Interval(-10, -1.01)
38 | trueroots = [-3.274277505524962, -1.7894889253208424]
39 | @test checkroots(f, trueroots)
40 |
41 | f(x) = log(x^2 - 1) + x + 1
42 | a = Interval(1.01, 10)
43 | trueroots = [1.0617135926109396]
44 | @test checkroots(f, trueroots)
45 |
46 |
47 |
--------------------------------------------------------------------------------
/modules/tests-newton.jl:
--------------------------------------------------------------------------------
1 | using Base.Test
2 | using NewtonMethod
3 |
4 | # Transcendental true roots were found using Wolfram Mathematica
5 |
6 | # Choose interval [-20, 20]
7 | a = Interval(-20, 20)
8 |
9 | enclosure(x) = Interval(x - 10*eps(), x + 10*eps())
10 |
11 | function checkroots(f, trueroots)
12 | roots = newton(f, a, 128)
13 | # Check if both ends of the found interval lie within the 10eps-enclosure of the true root
14 | n = 0
15 | for i = 1:length(roots)
16 | if belong(roots[i].lo, enclosure(trueroots[i])) == false && belong(roots[i].hi, enclosure(trueroots[i])) == false
17 | n += 1
18 | end
19 | end
20 | n == 0
21 | end
22 |
23 | f(x) = x^2 - 4
24 | trueroots = [-2, 2]
25 | @test checkroots(f, trueroots)
26 |
27 | f(x) = 5040 - 3828x - 2356x^2 + 1009x^3 + 200x^4 - 62x^5 - 4x^6 + x^7
28 | trueroots = [-6, -4, -2, 1, 3, 5, 7]
29 | @test checkroots(f, trueroots)
30 |
31 | f(x) = exp(x^2) - 4
32 | a = Interval(-4, 4)
33 | trueroots = [-sqrt(log(4)), sqrt(log(4))]
34 | @test checkroots(f, trueroots)
35 |
36 | # The next function is undefined in [-1, 1], so we split the interval manually
37 | f(x) = log(x^2 - 1) + x + 1
38 | a = Interval(-10, -1.11)
39 | trueroots = [-3.274277505524962, -1.7894889253208424]
40 | @test checkroots(f, trueroots)
41 |
42 | f(x) = log(x^2 - 1) + x + 1
43 | a = Interval(1.01, 10)
44 | trueroots = [1.0617135926109396]
45 | @test checkroots(f, trueroots)
46 |
47 |
48 |
--------------------------------------------------------------------------------
/modules/ad-benet.jl:
--------------------------------------------------------------------------------
1 | ## Automatic differentiation
2 |
3 | #=
4 | type Dual{T <: Real}
5 | fun::T
6 | der::T
7 | end
8 | =#
9 |
10 | type Dual
11 | fun
12 | der
13 | end
14 |
15 |
16 | # Basic arithmetic
17 | +(u::Dual, w::Dual) = Dual(u.fun + w.fun, u.der + w.der)
18 | -(u::Dual, w::Dual) = Dual(u.fun - w.fun, u.der - w.der)
19 | *(u::Dual, w::Dual) = Dual(u.fun*w.fun, u.der*w.fun + u.fun*w.der)
20 | function /(u::Dual, w::Dual)
21 | ff = u.fun/w.fun
22 | dd = (u.der - ff*w.der)/w.fun
23 | Dual(ff, dd)
24 | end
25 |
26 | # Power; two functions for power because it is less costly
27 | ^(u::Dual, a::Integer)= Dual(u.fun^a, a*u.fun^(a-1)*u.der)
28 |
29 | function ^(u::Dual, a::Real)
30 | ff = u.fun^(a-1)
31 | Dual(ff*u.fun, a*ff*u.der)
32 | end
33 |
34 | # Enable dual-real operations as normal
35 | for op in (:+, :-, :*, :/)
36 | @eval begin
37 | $op(u::Dual, c::Real) = $op(u, Dual(c))
38 | $op(c::Real, u::Dual) = $op(Dual(c), u)
39 | end
40 | end
41 | +(u::Dual) = u
42 | -(u::Dual) = Dual(-u.fun, -u.der)
43 |
44 |
45 | #= Trying to add intervals - unnecessary???
46 | for op in (:+, :-, :*, :/)
47 | @eval begin
48 | $op(u::Dual, c::Interval) = $op(u, Dual(c))
49 | $op(c::Interval, u::Dual) = $op(Dual(c), u)
50 | end
51 | end
52 | =#
53 |
54 | # Dual(constant)
55 | Dual{T<:Real}(c::T) = Dual{T}(c, zero(T))
56 |
57 | # Elementary functions and their derivatives
58 | for (ff, dd) in ((:(Base.exp), :(Base.exp)), (:(Base.log), :(x->1/x)), (:(Base.sin), :(Base.cos)), (:(Base.cos), :(x->-sin(x))), (:(Base.tan), :(x->(sec(x))^2)))
59 | @eval begin
60 | function $ff(u::Dual)
61 | Dual($ff(u.fun), u.der*$dd(u.fun))
62 | end
63 | end
64 | end
65 |
66 | # Differentiating function f at point a
67 |
68 | #=
69 | function differentiate(f, a)
70 | deriv(a) = f(Dual(a, one(a))).der
71 | if typeof(a) != Interval
72 | return deriv(a)
73 | else return Interval(min(deriv(a.lo), deriv(a.hi)), max(deriv(a.lo), deriv(a.hi)))
74 | end
75 | end
76 | =#
77 |
78 | differentiate(f, a) = f(Dual(a, one(a))).der
79 |
80 |
81 | #diff(f, a) =
82 |
83 | #diff(f, a::Interval) = Interval(diff(f, a.lo), diff(a.hi))
84 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/modules/AutoDiff.jl:
--------------------------------------------------------------------------------
1 | ## Automatic differentiation (interval version)
2 |
3 | module AutoDiff
4 | export differentiate, Ad, Interval, rad, diam, mid, mig, mag, belong, hd, hull, isect, isectext, lo, hi, make_intervals, det2
5 |
6 | using IntervalArithmetic
7 |
8 | type Ad
9 | u
10 | up
11 | end
12 |
13 | Ad(c) = Ad(c, Interval(0))
14 |
15 | # Arithmetic between two Ad
16 | +(x::Ad, y::Ad) = Ad(x.u + y.u, x.up + y.up)
17 | -(x::Ad, y::Ad) = Ad(x.u - y.u, x.up - y.up)
18 | *(x::Ad, y::Ad) = Ad(x.u*y.u, x.u*y.up + y.u*x.up)
19 | function /(x::Ad, y::Ad)
20 | ff = x.u/y.u
21 | dd = (x.up - ff*y.up)/y.u
22 | Ad(ff, dd)
23 | end
24 |
25 | # Power; two functions for power because it is less costly
26 | # Commented out because it gave errors
27 | ^(x::Ad, a::Integer)= Ad(x.u^a, a*x.u^(a-1)*x.up)
28 |
29 | function ^(x::Ad, a::Real)
30 | ff = x.u^(a-1)
31 | Ad(ff*x.u, a*ff*x.up)
32 | end
33 |
34 |
35 | # Arithmetic operations between Ad and intervals/numbers
36 |
37 | for op in (:+, :-, :*, :/)
38 | @eval begin
39 | $op(u::Ad, c::Interval) = $op(u, Ad(c))
40 | $op(c::Interval, u::Ad) = $op(Ad(c), u)
41 | $op(u::Ad, c::Real) = $op(u, Ad(c))
42 | $op(c::Real, u::Ad) = $op(Ad(c), u)
43 | end
44 | end
45 |
46 | +(x::Ad) = x
47 | -(x::Ad) = Ad(-x.u, -x.up)
48 |
49 | # Elementary functions
50 |
51 | import Base.sin
52 | sin(x::Ad) = Ad(sin(x.u), x.up*cos(x.u))
53 |
54 | import Base.cos
55 | cos(x::Ad) = Ad(cos(x.u), -x.up*sin(x.u))
56 |
57 | e^(x::Ad) = Ad(e^x.u, x.up*e^x.u)
58 |
59 | import Base.exp
60 | exp(x::Ad) = Ad(exp(x.u), x.up*exp(x.u))
61 |
62 | import Base.log
63 | log(x::Ad) = Ad(log(x.u), x.up/x.u)
64 |
65 | import Base.abs
66 | abs(x::Ad) = Ad(abs(x.u), x.up*sign(x.u))
67 |
68 | #(x::Ad)^y::Interval = Ad(x.u^y, x.up*y*x.u^(y-1))
69 |
70 |
71 |
72 |
73 | differentiate(f, a) = f(Ad(a, 1.)).up
74 |
75 | # End of module
76 | end
77 |
78 | function jacobian(f, a)
79 |
80 | f1(x) = f(x)[1]
81 | f2(x) = f(x)[2]
82 |
83 | f11(x1) = f1([x1, a[2]])
84 | J11 = differentiate(f11, a[1])
85 |
86 | f12(x2) = f1([a[1], x2])
87 | J12 = differentiate(f12, a[2])
88 |
89 | f21(x1) = f2([x1, a[2]])
90 | J21 = differentiate(f21, a[1])
91 |
92 | f22(x2) = f2([a[1], x2])
93 | J22 = differentiate(f22, a[2])
94 |
95 | [J11 J12; J21 J22]
96 |
97 | end
98 |
--------------------------------------------------------------------------------
/modules/KrawczykMethod.jl:
--------------------------------------------------------------------------------
1 | ## Krawczyk method, based on Tucker p. 86
2 |
3 | module KrawczykMethod
4 | export krawczyk, differentiate, Interval, rad, diam, mid, mig, mag, belong, hd, hull, isect, isectext, K
5 |
6 | using IntervalArithmetic
7 | using AutoDiff
8 |
9 |
10 | println("Syntax: krawczyk(function, Interval(lo, hi), precision [default is 64])")
11 |
12 | # If the derivative is 0, the constant C will return a "division by thin zero" error. We slightly change the denominator of the constant if this is the case.
13 | function C(f, x)
14 | if differentiate(f, mid(x)) == Interval(0)
15 | return Interval(1)//Interval(differentiate(f, mid(x)) + 0.0001*rad(x))
16 | else
17 | return Interval(1)//Interval(differentiate(f, mid(x)))
18 | end
19 | end
20 |
21 | K(f, x) = mid(x) - C(f, x)*f(mid(x)) + (1 - C(f, x)*differentiate(f, x))*(x - mid(x))
22 |
23 | # Outside wrapping function was made in order for it to clean up the array of roots every time
24 | function krawczyk(f::Function, a::Interval, bigprec::Integer=64)
25 |
26 | arr_a = Any[] # instead of Interval[] to put symbols at each encountered root
27 |
28 | function krawczyk_internal(f::Function, a::Interval, bigprec::Integer)
29 |
30 | set_bigfloat_precision(bigprec)
31 | tol = 1e-15 #100eps(BigFloat)
32 |
33 | # If a is symmetric, i.e., mid(a) = 0, the process may stall. The initial interval should be slightly asymmetrized then. This fix also removes the "possible" roots which correctly merge into "unique".
34 | if mid(a) == 0
35 | a = Interval(a.lo, a.hi + 0.0001*mag(a))
36 | end
37 |
38 | Ka = isect(a, K(f, a))
39 | #@show Ka
40 |
41 | if Ka != false
42 | #@show diam(a)
43 | #@show diam(K(a))
44 |
45 | if diam(Ka) < tol
46 | if inside(Ka, a) # inside
47 | println("Unique zero in $(Ka)")
48 | push!(arr_a, [Ka, :unique])
49 | else
50 | println("Maybe a zero in $(Ka)")
51 | push!(arr_a, [Ka, :possible])
52 | end
53 |
54 | else
55 | krawczyk_internal(f, Interval(Ka.lo, mid(Ka)), bigprec)
56 | krawczyk_internal(f, Interval(mid(Ka), Ka.hi), bigprec)
57 | end
58 |
59 | end
60 |
61 | return arr_a
62 | end
63 |
64 |
65 | return krawczyk_internal(f, a, bigprec)
66 | end
67 |
68 | #end of module
69 | end
70 |
--------------------------------------------------------------------------------
/krawczyk2d.jl:
--------------------------------------------------------------------------------
1 | using IntervalArithmetic
2 | using AutoDiff
3 |
4 | function all_inside(x::Array{Interval, 1}, y::Array{Interval, 1})
5 | k = 0
6 | for i = 1:length(x)
7 | if !inside(x[i], y[i])
8 | k += 1
9 | end
10 | end
11 | if k > 0
12 | return false
13 | else
14 | return true
15 | end
16 | end
17 |
18 | # Functions for bisection
19 |
20 | function lower(x::Array{Interval, 1})
21 | z = Interval[]
22 | for i = 1:length(x)
23 | push!(z, Interval(x[i].lo, mid(x[i])))
24 | end
25 | return z
26 | end
27 |
28 | function upper(x::Array{Interval, 1})
29 | z = Interval[]
30 | for i = 1:length(x)
31 | push!(z, Interval(mid(x[i]), x[i].hi))
32 | end
33 | return z
34 | end
35 |
36 | function krawczyk2d(f, a::Array{Interval, 1}, bigprec::Integer=64)
37 |
38 | arr_a = Array{Interval, 1}[]
39 |
40 | set_bigfloat_precision(bigprec)
41 | #tol = (1e-10)*eps(BigFloat)
42 | tol = 1e-10
43 |
44 | I = [Interval(1) Interval(0); Interval(0) Interval(1)]
45 | Y(x) = make_intervals(inv(mid(jacobian(f, mid(x)))))
46 | M(x) = I - Y(x)*jacobian(f, x)
47 | K(x) = make_intervals(mid(x)) - Y(x)*make_intervals(f(mid(x))) + M(x)*(x - make_intervals(mid(x)))
48 |
49 | Y1 = Array{Interval, 2}[]
50 | push!(Y1, Y(a))
51 |
52 | Kprev(x) = make_intervals(mid(x)) - Y1[k-1]*make_intervals(f(mid(x))) + (I - Y1[k-1]*jacobian(f, x))*(x - make_intervals(mid(x)))
53 |
54 |
55 | k = 1
56 |
57 | function krawczyk2d_internal(f, a::Array{Interval, 1}, bigprec::Integer)
58 |
59 | # If a is symmetric, i.e., mid(a) = 0, the process may stall. The initial interval should be slightly asymmetrized then
60 | #if mid(a) == 0
61 | # a = Interval(a.lo, a.hi + 0.0001*mag(a))
62 | #end
63 |
64 | Ka = isectext(a, K(a))
65 | if Ka != false
66 | @show a
67 | @show diam(a)
68 |
69 | d = diam(a)
70 | dK = diam(Ka)
71 |
72 | if dK[1] < tol && dK[2] < tol #d == dK
73 | if all_inside(Ka, a)
74 | println("Unique zero in $Ka")
75 | push!(arr_a, Ka)
76 | else
77 | println("Maybe a zero in $Ka")
78 | end
79 | k += 1
80 | else
81 |
82 |
83 | if k == 1
84 |
85 | if true #@show mid(det2(I - Y1[k]*jacobian(f, a))) <= mid(det2(I - Y(a)*jacobian(f, a)))
86 | k += 1
87 | push!(Y1, Y(a))
88 | @show krawczyk2d_internal(f, lower(Ka), bigprec)
89 | @show krawczyk2d_internal(f, upper(Ka), bigprec)
90 |
91 | else
92 | k += 1
93 | push!(Y1, Y(a))
94 | @show krawczyk2d_internal(f, lower(Kprev(a)), bigprec)
95 | @show krawczyk2d_internal(f, upper(Kprev(a)), bigprec)
96 |
97 | end
98 |
99 | else
100 |
101 |
102 |
103 | if mid(det2(I - Y1[k]*jacobian(f, a))) <= mid(det2(I - Y1[k-1]*jacobian(f, a)))
104 | @show k += 1
105 | push!(Y1, Y(a))
106 | krawczyk2d_internal(f, lower(Ka), bigprec)
107 | krawczyk2d_internal(f, upper(Ka), bigprec)
108 |
109 | else
110 | @show k += 1
111 | push!(Y1, Y(a))
112 | krawczyk2d_internal(f, lower(Kprev(a)), bigprec)
113 | krawczyk2d_internal(f, upper(Kprev(a)), bigprec)
114 |
115 | end
116 |
117 |
118 | end
119 |
120 |
121 | end
122 |
123 | end
124 |
125 | return arr_a
126 | end
127 |
128 | return krawczyk2d_internal(f, a, bigprec)
129 | end
130 |
131 |
--------------------------------------------------------------------------------
/2D bisection.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "metadata": {
3 | "language": "Julia",
4 | "name": "",
5 | "signature": "sha256:3d0b2c3cb6a8915ae17995f871bc029041c6e8c0706ecc6bcb4154952aac23ca"
6 | },
7 | "nbformat": 3,
8 | "nbformat_minor": 0,
9 | "worksheets": [
10 | {
11 | "cells": [
12 | {
13 | "cell_type": "code",
14 | "collapsed": false,
15 | "input": [
16 | "using IntervalArithmetic"
17 | ],
18 | "language": "python",
19 | "metadata": {},
20 | "outputs": [],
21 | "prompt_number": 1
22 | },
23 | {
24 | "cell_type": "code",
25 | "collapsed": false,
26 | "input": [
27 | "left(x::Interval) = Interval(x.lo, mid(x))\n",
28 | "right(x::Interval) = Interval(mid(x), x.hi)\n",
29 | "\n",
30 | "\n",
31 | "function bisect(xx::Vector{Interval})\n",
32 | " \n",
33 | " if length(xx) != 2\n",
34 | " error(\"Only works for 2 at the moment\")\n",
35 | " end\n",
36 | " \n",
37 | " x, y = xx\n",
38 | " \n",
39 | " @show x\n",
40 | " \n",
41 | " intervals = Vector{Interval}[]\n",
42 | " \n",
43 | " push!(intervals, [left(x), left(y)])\n",
44 | " push!(intervals, [left(x), right(y)])\n",
45 | " push!(intervals, [right(x), left(y)])\n",
46 | " push!(intervals, [right(x), right(y)])\n",
47 | " \n",
48 | " intervals\n",
49 | "end"
50 | ],
51 | "language": "python",
52 | "metadata": {},
53 | "outputs": [
54 | {
55 | "metadata": {},
56 | "output_type": "pyout",
57 | "prompt_number": 10,
58 | "text": [
59 | "bisect (generic function with 1 method)"
60 | ]
61 | }
62 | ],
63 | "prompt_number": 10
64 | },
65 | {
66 | "cell_type": "code",
67 | "collapsed": false,
68 | "input": [
69 | "a = Interval(0, 1)\n",
70 | "b = Interval(0, 1)\n",
71 | "\n",
72 | "bisect([a,b])"
73 | ],
74 | "language": "python",
75 | "metadata": {},
76 | "outputs": [
77 | {
78 | "output_type": "stream",
79 | "stream": "stdout",
80 | "text": [
81 | "x => Interval(0e+00 with 256 bits of precision,1e+00 with 256 bits of precision)"
82 | ]
83 | },
84 | {
85 | "output_type": "stream",
86 | "stream": "stdout",
87 | "text": [
88 | "\n"
89 | ]
90 | },
91 | {
92 | "metadata": {},
93 | "output_type": "pyout",
94 | "prompt_number": 11,
95 | "text": [
96 | "4-element Array{Array{Interval,1},1}:\n",
97 | " [Interval(0e+00 with 256 bits of precision,5e-01 with 256 bits of precision),Interval(0e+00 with 256 bits of precision,5e-01 with 256 bits of precision)]\n",
98 | " [Interval(0e+00 with 256 bits of precision,5e-01 with 256 bits of precision),Interval(5e-01 with 256 bits of precision,1e+00 with 256 bits of precision)]\n",
99 | " [Interval(5e-01 with 256 bits of precision,1e+00 with 256 bits of precision),Interval(0e+00 with 256 bits of precision,5e-01 with 256 bits of precision)]\n",
100 | " [Interval(5e-01 with 256 bits of precision,1e+00 with 256 bits of precision),Interval(5e-01 with 256 bits of precision,1e+00 with 256 bits of precision)]"
101 | ]
102 | }
103 | ],
104 | "prompt_number": 11
105 | },
106 | {
107 | "cell_type": "code",
108 | "collapsed": false,
109 | "input": [],
110 | "language": "python",
111 | "metadata": {},
112 | "outputs": []
113 | }
114 | ],
115 | "metadata": {}
116 | }
117 | ]
118 | }
--------------------------------------------------------------------------------
/krawczyk2d-tests-solutions.nb:
--------------------------------------------------------------------------------
1 | (* Content-type: application/mathematica *)
2 |
3 | (*** Wolfram Notebook File ***)
4 | (* http://www.wolfram.com/nb *)
5 |
6 | (* CreatedBy='Mathematica 7.0' *)
7 |
8 | (*CacheID: 234*)
9 | (* Internal cache information:
10 | NotebookFileLineBreakTest
11 | NotebookFileLineBreakTest
12 | NotebookDataPosition[ 145, 7]
13 | NotebookDataLength[ 8221, 281]
14 | NotebookOptionsPosition[ 7565, 253]
15 | NotebookOutlinePosition[ 7903, 268]
16 | CellTagsIndexPosition[ 7860, 265]
17 | WindowFrame->Normal*)
18 |
19 | (* Beginning of Notebook Content *)
20 | Notebook[{
21 |
22 | Cell[CellGroupData[{
23 | Cell[BoxData[
24 | RowBox[{"Solve", "[",
25 | RowBox[{
26 | RowBox[{"{",
27 | RowBox[{
28 | RowBox[{
29 | RowBox[{
30 | SuperscriptBox["x1", "2"], "+",
31 | SuperscriptBox["x2", "2"], "-", "1"}], "\[Equal]", "0"}], ",", " ",
32 | RowBox[{
33 | RowBox[{"x1", " ", "-", " ",
34 | SuperscriptBox["x2", "2"]}], "\[Equal]", "0"}]}], "}"}], ",",
35 | RowBox[{"{",
36 | RowBox[{"x1", ",", " ", "x2"}], "}"}]}], "]"}]], "Input",
37 | CellChangeTimes->{{3.6210166459051867`*^9, 3.621016716028469*^9}}],
38 |
39 | Cell[BoxData[
40 | RowBox[{"{",
41 | RowBox[{
42 | RowBox[{"{",
43 | RowBox[{
44 | RowBox[{"x1", "\[Rule]",
45 | RowBox[{
46 | FractionBox["1", "2"], " ",
47 | RowBox[{"(",
48 | RowBox[{
49 | RowBox[{"-", "1"}], "-",
50 | SqrtBox["5"]}], ")"}]}]}], ",",
51 | RowBox[{"x2", "\[Rule]",
52 | RowBox[{
53 | RowBox[{"-", "\[ImaginaryI]"}], " ",
54 | SqrtBox[
55 | RowBox[{
56 | FractionBox["1", "2"], " ",
57 | RowBox[{"(",
58 | RowBox[{"1", "+",
59 | SqrtBox["5"]}], ")"}]}]]}]}]}], "}"}], ",",
60 | RowBox[{"{",
61 | RowBox[{
62 | RowBox[{"x1", "\[Rule]",
63 | RowBox[{
64 | FractionBox["1", "2"], " ",
65 | RowBox[{"(",
66 | RowBox[{
67 | RowBox[{"-", "1"}], "-",
68 | SqrtBox["5"]}], ")"}]}]}], ",",
69 | RowBox[{"x2", "\[Rule]",
70 | RowBox[{"\[ImaginaryI]", " ",
71 | SqrtBox[
72 | RowBox[{
73 | FractionBox["1", "2"], " ",
74 | RowBox[{"(",
75 | RowBox[{"1", "+",
76 | SqrtBox["5"]}], ")"}]}]]}]}]}], "}"}], ",",
77 | RowBox[{"{",
78 | RowBox[{
79 | RowBox[{"x1", "\[Rule]",
80 | RowBox[{
81 | RowBox[{"-",
82 | FractionBox["1", "2"]}], "+",
83 | FractionBox[
84 | SqrtBox["5"], "2"]}]}], ",",
85 | RowBox[{"x2", "\[Rule]",
86 | RowBox[{"-",
87 | SqrtBox[
88 | RowBox[{
89 | RowBox[{"-",
90 | FractionBox["1", "2"]}], "+",
91 | FractionBox[
92 | SqrtBox["5"], "2"]}]]}]}]}], "}"}], ",",
93 | RowBox[{"{",
94 | RowBox[{
95 | RowBox[{"x1", "\[Rule]",
96 | RowBox[{
97 | RowBox[{"-",
98 | FractionBox["1", "2"]}], "+",
99 | FractionBox[
100 | SqrtBox["5"], "2"]}]}], ",",
101 | RowBox[{"x2", "\[Rule]",
102 | SqrtBox[
103 | RowBox[{
104 | RowBox[{"-",
105 | FractionBox["1", "2"]}], "+",
106 | FractionBox[
107 | SqrtBox["5"], "2"]}]]}]}], "}"}]}], "}"}]], "Output",
108 | CellChangeTimes->{3.6210167168558683`*^9}]
109 | }, Open ]],
110 |
111 | Cell[CellGroupData[{
112 |
113 | Cell[BoxData[
114 | RowBox[{"%", "//", "N"}]], "Input",
115 | CellChangeTimes->{{3.621016727579361*^9, 3.621016728906165*^9}}],
116 |
117 | Cell[BoxData[
118 | RowBox[{"{",
119 | RowBox[{
120 | RowBox[{"{",
121 | RowBox[{
122 | RowBox[{"x1", "\[Rule]",
123 | RowBox[{"-", "1.618033988749895`"}]}], ",",
124 | RowBox[{"x2", "\[Rule]",
125 | RowBox[{"0.`", "\[InvisibleSpace]", "-",
126 | RowBox[{"1.272019649514069`", " ", "\[ImaginaryI]"}]}]}]}], "}"}], ",",
127 | RowBox[{"{",
128 | RowBox[{
129 | RowBox[{"x1", "\[Rule]",
130 | RowBox[{"-", "1.618033988749895`"}]}], ",",
131 | RowBox[{"x2", "\[Rule]",
132 | RowBox[{"0.`", "\[InvisibleSpace]", "+",
133 | RowBox[{"1.272019649514069`", " ", "\[ImaginaryI]"}]}]}]}], "}"}], ",",
134 | RowBox[{"{",
135 | RowBox[{
136 | RowBox[{"x1", "\[Rule]", "0.6180339887498949`"}], ",",
137 | RowBox[{"x2", "\[Rule]",
138 | RowBox[{"-", "0.7861513777574233`"}]}]}], "}"}], ",",
139 | RowBox[{"{",
140 | RowBox[{
141 | RowBox[{"x1", "\[Rule]", "0.6180339887498949`"}], ",",
142 | RowBox[{"x2", "\[Rule]", "0.7861513777574233`"}]}], "}"}]}],
143 | "}"}]], "Output",
144 | CellChangeTimes->{3.621016729402563*^9}]
145 | }, Open ]],
146 |
147 | Cell[CellGroupData[{
148 |
149 | Cell[BoxData[
150 | RowBox[{"FindRoot", "[",
151 | RowBox[{
152 | RowBox[{"{",
153 | RowBox[{
154 | RowBox[{
155 | RowBox[{"20", "-",
156 | RowBox[{"20", "x1"}], "-", "x2"}], "\[Equal]", "0"}], ",", " ",
157 | RowBox[{
158 | RowBox[{"x1", " ", "-",
159 | RowBox[{"x2", "/", "20"}], " ", "-", " ",
160 | RowBox[{
161 | SuperscriptBox["10",
162 | RowBox[{"-", "9"}]],
163 | SuperscriptBox["\[ExponentialE]",
164 | RowBox[{"x2", "/", "0.052"}]]}]}], "\[Equal]", "0"}]}], "}"}], ",",
165 | RowBox[{"{",
166 | RowBox[{
167 | RowBox[{"{",
168 | RowBox[{"x1", ",", "0.1"}], "}"}], ",",
169 | RowBox[{"{",
170 | RowBox[{"x2", ",", "0.1"}], "}"}]}], "}"}]}], "]"}]], "Input",
171 | CellChangeTimes->{{3.621016853939192*^9, 3.62101685527419*^9}, {
172 | 3.6210169356759367`*^9, 3.621016939387439*^9}, {3.62101697036378*^9,
173 | 3.621017023967258*^9}}],
174 |
175 | Cell[BoxData[
176 | RowBox[{"{",
177 | RowBox[{
178 | RowBox[{"x1", "\[Rule]", "0.9464142468335176`"}], ",",
179 | RowBox[{"x2", "\[Rule]", "1.0717150633296477`"}]}], "}"}]], "Output",
180 | CellChangeTimes->{3.621017028188586*^9}]
181 | }, Open ]],
182 |
183 | Cell[CellGroupData[{
184 |
185 | Cell[BoxData[
186 | RowBox[{"NSolve", "[",
187 | RowBox[{
188 | RowBox[{"{",
189 | RowBox[{
190 | RowBox[{
191 | RowBox[{"0.5",
192 | RowBox[{"(",
193 | RowBox[{
194 | RowBox[{"-",
195 | RowBox[{"(",
196 | RowBox[{
197 | RowBox[{"17.76", "x1"}], "-",
198 | RowBox[{"103.79",
199 | SuperscriptBox["x1", "2"]}], "+",
200 | RowBox[{"229.62",
201 | SuperscriptBox["x1", "3"]}], "-",
202 | RowBox[{"226.31",
203 | SuperscriptBox["x1", "4"]}], "+",
204 | RowBox[{"83.72",
205 | SuperscriptBox["x1", "5"]}]}], ")"}]}], "+", "x2"}], ")"}]}],
206 | "\[Equal]", "0"}], ",", " ",
207 | RowBox[{
208 | RowBox[{"0.2",
209 | RowBox[{"(",
210 | RowBox[{
211 | RowBox[{"-", "x1"}], "-",
212 | RowBox[{"1.5", "x2"}], "+", "1.2"}], ")"}]}], "\[Equal]", "0"}]}],
213 | "}"}], ",",
214 | RowBox[{"{",
215 | RowBox[{"x1", ",", "x2"}], "}"}]}], "]"}]], "Input",
216 | CellChangeTimes->{{3.6210171506050463`*^9, 3.621017300976647*^9}}],
217 |
218 | Cell[BoxData[
219 | RowBox[{"{",
220 | RowBox[{
221 | RowBox[{"{",
222 | RowBox[{
223 | RowBox[{"x1", "\[Rule]", "0.06263595920972119`"}], ",",
224 | RowBox[{"x2", "\[Rule]", "0.758242693860186`"}]}], "}"}], ",",
225 | RowBox[{"{",
226 | RowBox[{
227 | RowBox[{"x1", "\[Rule]", "0.8844295888702942`"}], ",",
228 | RowBox[{"x2", "\[Rule]", "0.21038027408647064`"}]}], "}"}], ",",
229 | RowBox[{"{",
230 | RowBox[{
231 | RowBox[{"x1", "\[Rule]", "0.2853687241300338`"}], ",",
232 | RowBox[{"x2", "\[Rule]", "0.6097541839133109`"}]}], "}"}], ",",
233 | RowBox[{"{",
234 | RowBox[{
235 | RowBox[{"x1", "\[Rule]",
236 | RowBox[{"0.7353714926575128`", "\[InvisibleSpace]", "-",
237 | RowBox[{"0.25236586977566516`", " ", "\[ImaginaryI]"}]}]}], ",",
238 | RowBox[{"x2", "\[Rule]",
239 | RowBox[{"0.3097523382283249`", "\[InvisibleSpace]", "+",
240 | RowBox[{"0.16824391318377677`", " ", "\[ImaginaryI]"}]}]}]}], "}"}],
241 | ",",
242 | RowBox[{"{",
243 | RowBox[{
244 | RowBox[{"x1", "\[Rule]",
245 | RowBox[{"0.7353714926575128`", "\[InvisibleSpace]", "+",
246 | RowBox[{"0.25236586977566516`", " ", "\[ImaginaryI]"}]}]}], ",",
247 | RowBox[{"x2", "\[Rule]",
248 | RowBox[{"0.3097523382283249`", "\[InvisibleSpace]", "-",
249 | RowBox[{"0.16824391318377677`", " ", "\[ImaginaryI]"}]}]}]}], "}"}]}],
250 | "}"}]], "Output",
251 | CellChangeTimes->{{3.621017283053774*^9, 3.6210173032976923`*^9}}]
252 | }, Open ]]
253 | },
254 | WindowSize->{971, 798},
255 | WindowMargins->{{Automatic, 202}, {70, Automatic}},
256 | FrontEndVersion->"7.0 for Linux x86 (64-bit) (November 11, 2008)",
257 | StyleDefinitions->"Default.nb"
258 | ]
259 | (* End of Notebook Content *)
260 |
261 | (* Internal cache information *)
262 | (*CellTagsOutline
263 | CellTagsIndex->{}
264 | *)
265 | (*CellTagsIndex
266 | CellTagsIndex->{}
267 | *)
268 | (*NotebookFileOutline
269 | Notebook[{
270 | Cell[CellGroupData[{
271 | Cell[567, 22, 490, 14, 32, "Input"],
272 | Cell[1060, 38, 1872, 69, 121, "Output"]
273 | }, Open ]],
274 | Cell[CellGroupData[{
275 | Cell[2969, 112, 116, 2, 32, "Input"],
276 | Cell[3088, 116, 984, 27, 52, "Output"]
277 | }, Open ]],
278 | Cell[CellGroupData[{
279 | Cell[4109, 148, 834, 24, 32, "Input"],
280 | Cell[4946, 174, 213, 5, 31, "Output"]
281 | }, Open ]],
282 | Cell[CellGroupData[{
283 | Cell[5196, 184, 988, 31, 55, "Input"],
284 | Cell[6187, 217, 1362, 33, 52, "Output"]
285 | }, Open ]]
286 | }
287 | ]
288 | *)
289 |
290 | (* End of internal cache information *)
291 |
--------------------------------------------------------------------------------
/newton-sin.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "metadata": {
3 | "language": "Julia",
4 | "name": ""
5 | },
6 | "nbformat": 3,
7 | "nbformat_minor": 0,
8 | "worksheets": [
9 | {
10 | "cells": [
11 | {
12 | "cell_type": "code",
13 | "collapsed": false,
14 | "input": [
15 | "using NewtonMethod"
16 | ],
17 | "language": "python",
18 | "metadata": {},
19 | "outputs": [
20 | {
21 | "output_type": "stream",
22 | "stream": "stdout",
23 | "text": [
24 | "Syntax: newton(function, Interval(lo, hi), calls)\n"
25 | ]
26 | },
27 | {
28 | "output_type": "stream",
29 | "stream": "stderr",
30 | "text": [
31 | "Warning: requiring \"NewtonMethod\" did not define a corresponding module.\n"
32 | ]
33 | }
34 | ],
35 | "prompt_number": 1
36 | },
37 | {
38 | "cell_type": "code",
39 | "collapsed": false,
40 | "input": [
41 | "f(x) = sin(x)"
42 | ],
43 | "language": "python",
44 | "metadata": {},
45 | "outputs": [
46 | {
47 | "metadata": {},
48 | "output_type": "pyout",
49 | "prompt_number": 2,
50 | "text": [
51 | "f (generic function with 1 method)"
52 | ]
53 | }
54 | ],
55 | "prompt_number": 2
56 | },
57 | {
58 | "cell_type": "code",
59 | "collapsed": false,
60 | "input": [
61 | "newton(f, Interval(-20., 20.), 40)"
62 | ],
63 | "language": "python",
64 | "metadata": {},
65 | "outputs": [
66 | {
67 | "metadata": {},
68 | "output_type": "pyout",
69 | "prompt_number": 3,
70 | "text": [
71 | "7-element Array{Interval,1}:\n",
72 | " Interval(-18.849555921516185,-18.84955592151618) \n",
73 | " Interval(-15.707963267926392,-15.707963267926392)\n",
74 | " Interval(-9.424777960746805,-9.424777960746804) \n",
75 | " Interval(-6.283185307157011,-6.2831853071570105) \n",
76 | " Interval(-3.1415926535897936,-3.141592653589793) \n",
77 | " Interval(-0.0,5.0e-324) \n",
78 | " Interval(12.566370614381748,12.56637061438175) "
79 | ]
80 | }
81 | ],
82 | "prompt_number": 3
83 | },
84 | {
85 | "cell_type": "code",
86 | "collapsed": false,
87 | "input": [
88 | "newton(f, Interval(-21., 21.), 40)"
89 | ],
90 | "language": "python",
91 | "metadata": {},
92 | "outputs": [
93 | {
94 | "metadata": {},
95 | "output_type": "pyout",
96 | "prompt_number": 4,
97 | "text": [
98 | "8-element Array{Interval,1}:\n",
99 | " Interval(-15.707963267948967,-15.707963267948966)\n",
100 | " Interval(-12.566370614359174,-12.566370614359172)\n",
101 | " Interval(-9.424777960746805,-9.424777960746804) \n",
102 | " Interval(-6.283185307157011,-6.2831853071570105) \n",
103 | " Interval(-0.0,5.0e-324) \n",
104 | " Interval(12.566370614381748,12.56637061438175) \n",
105 | " Interval(15.707963267971541,15.707963267971541) \n",
106 | " Interval(18.849555921561333,18.849555921561336) "
107 | ]
108 | }
109 | ],
110 | "prompt_number": 4
111 | },
112 | {
113 | "cell_type": "code",
114 | "collapsed": false,
115 | "input": [
116 | "newton(f, Interval(-23., 23.), 40)"
117 | ],
118 | "language": "python",
119 | "metadata": {},
120 | "outputs": [
121 | {
122 | "metadata": {},
123 | "output_type": "pyout",
124 | "prompt_number": 5,
125 | "text": [
126 | "7-element Array{Interval,1}:\n",
127 | " Interval(-21.991148575105978,-21.991148575105974)\n",
128 | " Interval(-18.849555921516185,-18.84955592151618) \n",
129 | " Interval(-15.707963267926392,-15.70796326792639) \n",
130 | " Interval(-12.566370614336599,-12.566370614336597)\n",
131 | " Interval(-9.424777960746805,-9.424777960746804) \n",
132 | " Interval(-6.283185307157011,-6.2831853071570105) \n",
133 | " Interval(-0.0,5.0e-324) "
134 | ]
135 | }
136 | ],
137 | "prompt_number": 5
138 | },
139 | {
140 | "cell_type": "code",
141 | "collapsed": false,
142 | "input": [
143 | "newton(f, Interval(-21., 22.), 40)"
144 | ],
145 | "language": "python",
146 | "metadata": {},
147 | "outputs": [
148 | {
149 | "metadata": {},
150 | "output_type": "pyout",
151 | "prompt_number": 6,
152 | "text": [
153 | "8-element Array{Interval,1}:\n",
154 | " Interval(-15.707963267948967,-15.707963267948966)\n",
155 | " Interval(-12.566370614359174,-12.566370614359172)\n",
156 | " Interval(-9.424777960746805,-9.424777960746804) \n",
157 | " Interval(-6.283185307157011,-6.2831853071570105) \n",
158 | " Interval(-0.0,5.0e-324) \n",
159 | " Interval(12.566370614381748,12.56637061438175) \n",
160 | " Interval(15.707963267971541,15.707963267971543) \n",
161 | " Interval(21.991148575151126,21.99114857515113) "
162 | ]
163 | }
164 | ],
165 | "prompt_number": 6
166 | },
167 | {
168 | "cell_type": "code",
169 | "collapsed": false,
170 | "input": [
171 | "newton(f, Interval(-22., 21.), 40)"
172 | ],
173 | "language": "python",
174 | "metadata": {},
175 | "outputs": [
176 | {
177 | "metadata": {},
178 | "output_type": "pyout",
179 | "prompt_number": 7,
180 | "text": [
181 | "9-element Array{Interval,1}:\n",
182 | " Interval(-21.991148575128555,-21.991148575128552)\n",
183 | " Interval(-18.849555921516185,-18.849555921516185)\n",
184 | " Interval(-15.707963267948967,-15.707963267948966)\n",
185 | " Interval(-9.424777960746805,-9.424777960746804) \n",
186 | " Interval(-6.283185307179587,-6.283185307179586) \n",
187 | " Interval(-3.1415926535897936,-3.141592653589793) \n",
188 | " Interval(12.566370614381748,12.56637061438175) \n",
189 | " Interval(15.707963267971541,15.707963267971541) \n",
190 | " Interval(18.849555921561333,18.849555921561336) "
191 | ]
192 | }
193 | ],
194 | "prompt_number": 7
195 | },
196 | {
197 | "cell_type": "code",
198 | "collapsed": false,
199 | "input": [
200 | "newton(f, Interval(-20., 20.), 40)"
201 | ],
202 | "language": "python",
203 | "metadata": {},
204 | "outputs": [
205 | {
206 | "metadata": {},
207 | "output_type": "pyout",
208 | "prompt_number": 8,
209 | "text": [
210 | "7-element Array{Interval,1}:\n",
211 | " Interval(-18.849555921516185,-18.84955592151618) \n",
212 | " Interval(-15.707963267926392,-15.707963267926392)\n",
213 | " Interval(-9.424777960746805,-9.424777960746804) \n",
214 | " Interval(-6.283185307157011,-6.2831853071570105) \n",
215 | " Interval(-3.1415926535897936,-3.141592653589793) \n",
216 | " Interval(-0.0,5.0e-324) \n",
217 | " Interval(12.566370614381748,12.56637061438175) "
218 | ]
219 | }
220 | ],
221 | "prompt_number": 8
222 | },
223 | {
224 | "cell_type": "code",
225 | "collapsed": false,
226 | "input": [
227 | "newton(f, Interval(-20., 20.), 50)"
228 | ],
229 | "language": "python",
230 | "metadata": {},
231 | "outputs": [
232 | {
233 | "metadata": {},
234 | "output_type": "pyout",
235 | "prompt_number": 9,
236 | "text": [
237 | "7-element Array{Interval,1}:\n",
238 | " Interval(-18.849555921516185,-18.84955592151618) \n",
239 | " Interval(-15.707963267926392,-15.707963267926392)\n",
240 | " Interval(-9.424777960746805,-9.424777960746804) \n",
241 | " Interval(-6.283185307157011,-6.2831853071570105) \n",
242 | " Interval(-3.1415926535897936,-3.141592653589793) \n",
243 | " Interval(-0.0,5.0e-324) \n",
244 | " Interval(12.566370614381748,12.56637061438175) "
245 | ]
246 | }
247 | ],
248 | "prompt_number": 9
249 | },
250 | {
251 | "cell_type": "code",
252 | "collapsed": false,
253 | "input": [
254 | "newton(f, Interval(-20., 20.), 30)"
255 | ],
256 | "language": "python",
257 | "metadata": {},
258 | "outputs": [
259 | {
260 | "metadata": {},
261 | "output_type": "pyout",
262 | "prompt_number": 10,
263 | "text": [
264 | "7-element Array{Interval,1}:\n",
265 | " Interval(-18.849555921516185,-18.84955592151618) \n",
266 | " Interval(-15.707963267926392,-15.707963267926392)\n",
267 | " Interval(-9.424777960746805,-9.424777960746804) \n",
268 | " Interval(-6.283185307157011,-6.2831853071570105) \n",
269 | " Interval(-3.1415926535897936,-3.141592653589793) \n",
270 | " Interval(-0.0,2.2538265914667098e-260) \n",
271 | " Interval(12.566370614381748,12.56637061438175) "
272 | ]
273 | }
274 | ],
275 | "prompt_number": 10
276 | },
277 | {
278 | "cell_type": "code",
279 | "collapsed": false,
280 | "input": [
281 | "newton(f, Interval(-24., 22.), 40)"
282 | ],
283 | "language": "python",
284 | "metadata": {},
285 | "outputs": [
286 | {
287 | "metadata": {},
288 | "output_type": "pyout",
289 | "prompt_number": 11,
290 | "text": [
291 | "9-element Array{Interval,1}:\n",
292 | " Interval(-21.991148575128555,-21.991148575128552)\n",
293 | " Interval(-18.849555921538762,-18.84955592153876) \n",
294 | " Interval(-9.424777960746805,-9.424777960746804) \n",
295 | " Interval(-6.283185307179587,-6.283185307179586) \n",
296 | " Interval(-3.1415926535897936,-3.141592653589793) \n",
297 | " Interval(-0.0,0.0) \n",
298 | " Interval(6.283185307202162,6.283185307202162) \n",
299 | " Interval(18.849555921561333,18.849555921561336) \n",
300 | " Interval(21.991148575151126,21.99114857515113) "
301 | ]
302 | }
303 | ],
304 | "prompt_number": 11
305 | },
306 | {
307 | "cell_type": "markdown",
308 | "metadata": {},
309 | "source": [
310 | "The roots that are lost depend on the points of the interval. No other function (except sin and based on it cos) does this. Interestingly, changing the procedure of sin into an alternative one left the problem unchanged."
311 | ]
312 | },
313 | {
314 | "cell_type": "code",
315 | "collapsed": false,
316 | "input": [],
317 | "language": "python",
318 | "metadata": {},
319 | "outputs": []
320 | }
321 | ],
322 | "metadata": {}
323 | }
324 | ]
325 | }
--------------------------------------------------------------------------------
/.ipynb_checkpoints/newton-sin-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "metadata": {
3 | "language": "Julia",
4 | "name": ""
5 | },
6 | "nbformat": 3,
7 | "nbformat_minor": 0,
8 | "worksheets": [
9 | {
10 | "cells": [
11 | {
12 | "cell_type": "code",
13 | "collapsed": false,
14 | "input": [
15 | "using NewtonMethod"
16 | ],
17 | "language": "python",
18 | "metadata": {},
19 | "outputs": [
20 | {
21 | "output_type": "stream",
22 | "stream": "stdout",
23 | "text": [
24 | "Syntax: newton(function, Interval(lo, hi), calls)\n"
25 | ]
26 | },
27 | {
28 | "output_type": "stream",
29 | "stream": "stderr",
30 | "text": [
31 | "Warning: requiring \"NewtonMethod\" did not define a corresponding module.\n"
32 | ]
33 | }
34 | ],
35 | "prompt_number": 1
36 | },
37 | {
38 | "cell_type": "code",
39 | "collapsed": false,
40 | "input": [
41 | "f(x) = sin(x)"
42 | ],
43 | "language": "python",
44 | "metadata": {},
45 | "outputs": [
46 | {
47 | "metadata": {},
48 | "output_type": "pyout",
49 | "prompt_number": 2,
50 | "text": [
51 | "f (generic function with 1 method)"
52 | ]
53 | }
54 | ],
55 | "prompt_number": 2
56 | },
57 | {
58 | "cell_type": "code",
59 | "collapsed": false,
60 | "input": [
61 | "newton(f, Interval(-20., 20.), 40)"
62 | ],
63 | "language": "python",
64 | "metadata": {},
65 | "outputs": [
66 | {
67 | "metadata": {},
68 | "output_type": "pyout",
69 | "prompt_number": 3,
70 | "text": [
71 | "7-element Array{Interval,1}:\n",
72 | " Interval(-18.849555921516185,-18.84955592151618) \n",
73 | " Interval(-15.707963267926392,-15.707963267926392)\n",
74 | " Interval(-9.424777960746805,-9.424777960746804) \n",
75 | " Interval(-6.283185307157011,-6.2831853071570105) \n",
76 | " Interval(-3.1415926535897936,-3.141592653589793) \n",
77 | " Interval(-0.0,5.0e-324) \n",
78 | " Interval(12.566370614381748,12.56637061438175) "
79 | ]
80 | }
81 | ],
82 | "prompt_number": 3
83 | },
84 | {
85 | "cell_type": "code",
86 | "collapsed": false,
87 | "input": [
88 | "newton(f, Interval(-21., 21.), 40)"
89 | ],
90 | "language": "python",
91 | "metadata": {},
92 | "outputs": [
93 | {
94 | "metadata": {},
95 | "output_type": "pyout",
96 | "prompt_number": 4,
97 | "text": [
98 | "8-element Array{Interval,1}:\n",
99 | " Interval(-15.707963267948967,-15.707963267948966)\n",
100 | " Interval(-12.566370614359174,-12.566370614359172)\n",
101 | " Interval(-9.424777960746805,-9.424777960746804) \n",
102 | " Interval(-6.283185307157011,-6.2831853071570105) \n",
103 | " Interval(-0.0,5.0e-324) \n",
104 | " Interval(12.566370614381748,12.56637061438175) \n",
105 | " Interval(15.707963267971541,15.707963267971541) \n",
106 | " Interval(18.849555921561333,18.849555921561336) "
107 | ]
108 | }
109 | ],
110 | "prompt_number": 4
111 | },
112 | {
113 | "cell_type": "code",
114 | "collapsed": false,
115 | "input": [
116 | "newton(f, Interval(-23., 23.), 40)"
117 | ],
118 | "language": "python",
119 | "metadata": {},
120 | "outputs": [
121 | {
122 | "metadata": {},
123 | "output_type": "pyout",
124 | "prompt_number": 5,
125 | "text": [
126 | "7-element Array{Interval,1}:\n",
127 | " Interval(-21.991148575105978,-21.991148575105974)\n",
128 | " Interval(-18.849555921516185,-18.84955592151618) \n",
129 | " Interval(-15.707963267926392,-15.70796326792639) \n",
130 | " Interval(-12.566370614336599,-12.566370614336597)\n",
131 | " Interval(-9.424777960746805,-9.424777960746804) \n",
132 | " Interval(-6.283185307157011,-6.2831853071570105) \n",
133 | " Interval(-0.0,5.0e-324) "
134 | ]
135 | }
136 | ],
137 | "prompt_number": 5
138 | },
139 | {
140 | "cell_type": "code",
141 | "collapsed": false,
142 | "input": [
143 | "newton(f, Interval(-21., 22.), 40)"
144 | ],
145 | "language": "python",
146 | "metadata": {},
147 | "outputs": [
148 | {
149 | "metadata": {},
150 | "output_type": "pyout",
151 | "prompt_number": 6,
152 | "text": [
153 | "8-element Array{Interval,1}:\n",
154 | " Interval(-15.707963267948967,-15.707963267948966)\n",
155 | " Interval(-12.566370614359174,-12.566370614359172)\n",
156 | " Interval(-9.424777960746805,-9.424777960746804) \n",
157 | " Interval(-6.283185307157011,-6.2831853071570105) \n",
158 | " Interval(-0.0,5.0e-324) \n",
159 | " Interval(12.566370614381748,12.56637061438175) \n",
160 | " Interval(15.707963267971541,15.707963267971543) \n",
161 | " Interval(21.991148575151126,21.99114857515113) "
162 | ]
163 | }
164 | ],
165 | "prompt_number": 6
166 | },
167 | {
168 | "cell_type": "code",
169 | "collapsed": false,
170 | "input": [
171 | "newton(f, Interval(-22., 21.), 40)"
172 | ],
173 | "language": "python",
174 | "metadata": {},
175 | "outputs": [
176 | {
177 | "metadata": {},
178 | "output_type": "pyout",
179 | "prompt_number": 7,
180 | "text": [
181 | "9-element Array{Interval,1}:\n",
182 | " Interval(-21.991148575128555,-21.991148575128552)\n",
183 | " Interval(-18.849555921516185,-18.849555921516185)\n",
184 | " Interval(-15.707963267948967,-15.707963267948966)\n",
185 | " Interval(-9.424777960746805,-9.424777960746804) \n",
186 | " Interval(-6.283185307179587,-6.283185307179586) \n",
187 | " Interval(-3.1415926535897936,-3.141592653589793) \n",
188 | " Interval(12.566370614381748,12.56637061438175) \n",
189 | " Interval(15.707963267971541,15.707963267971541) \n",
190 | " Interval(18.849555921561333,18.849555921561336) "
191 | ]
192 | }
193 | ],
194 | "prompt_number": 7
195 | },
196 | {
197 | "cell_type": "code",
198 | "collapsed": false,
199 | "input": [
200 | "newton(f, Interval(-20., 20.), 40)"
201 | ],
202 | "language": "python",
203 | "metadata": {},
204 | "outputs": [
205 | {
206 | "metadata": {},
207 | "output_type": "pyout",
208 | "prompt_number": 8,
209 | "text": [
210 | "7-element Array{Interval,1}:\n",
211 | " Interval(-18.849555921516185,-18.84955592151618) \n",
212 | " Interval(-15.707963267926392,-15.707963267926392)\n",
213 | " Interval(-9.424777960746805,-9.424777960746804) \n",
214 | " Interval(-6.283185307157011,-6.2831853071570105) \n",
215 | " Interval(-3.1415926535897936,-3.141592653589793) \n",
216 | " Interval(-0.0,5.0e-324) \n",
217 | " Interval(12.566370614381748,12.56637061438175) "
218 | ]
219 | }
220 | ],
221 | "prompt_number": 8
222 | },
223 | {
224 | "cell_type": "code",
225 | "collapsed": false,
226 | "input": [
227 | "newton(f, Interval(-20., 20.), 50)"
228 | ],
229 | "language": "python",
230 | "metadata": {},
231 | "outputs": [
232 | {
233 | "metadata": {},
234 | "output_type": "pyout",
235 | "prompt_number": 9,
236 | "text": [
237 | "7-element Array{Interval,1}:\n",
238 | " Interval(-18.849555921516185,-18.84955592151618) \n",
239 | " Interval(-15.707963267926392,-15.707963267926392)\n",
240 | " Interval(-9.424777960746805,-9.424777960746804) \n",
241 | " Interval(-6.283185307157011,-6.2831853071570105) \n",
242 | " Interval(-3.1415926535897936,-3.141592653589793) \n",
243 | " Interval(-0.0,5.0e-324) \n",
244 | " Interval(12.566370614381748,12.56637061438175) "
245 | ]
246 | }
247 | ],
248 | "prompt_number": 9
249 | },
250 | {
251 | "cell_type": "code",
252 | "collapsed": false,
253 | "input": [
254 | "newton(f, Interval(-20., 20.), 30)"
255 | ],
256 | "language": "python",
257 | "metadata": {},
258 | "outputs": [
259 | {
260 | "metadata": {},
261 | "output_type": "pyout",
262 | "prompt_number": 10,
263 | "text": [
264 | "7-element Array{Interval,1}:\n",
265 | " Interval(-18.849555921516185,-18.84955592151618) \n",
266 | " Interval(-15.707963267926392,-15.707963267926392)\n",
267 | " Interval(-9.424777960746805,-9.424777960746804) \n",
268 | " Interval(-6.283185307157011,-6.2831853071570105) \n",
269 | " Interval(-3.1415926535897936,-3.141592653589793) \n",
270 | " Interval(-0.0,2.2538265914667098e-260) \n",
271 | " Interval(12.566370614381748,12.56637061438175) "
272 | ]
273 | }
274 | ],
275 | "prompt_number": 10
276 | },
277 | {
278 | "cell_type": "code",
279 | "collapsed": false,
280 | "input": [
281 | "newton(f, Interval(-24., 22.), 40)"
282 | ],
283 | "language": "python",
284 | "metadata": {},
285 | "outputs": [
286 | {
287 | "metadata": {},
288 | "output_type": "pyout",
289 | "prompt_number": 11,
290 | "text": [
291 | "9-element Array{Interval,1}:\n",
292 | " Interval(-21.991148575128555,-21.991148575128552)\n",
293 | " Interval(-18.849555921538762,-18.84955592153876) \n",
294 | " Interval(-9.424777960746805,-9.424777960746804) \n",
295 | " Interval(-6.283185307179587,-6.283185307179586) \n",
296 | " Interval(-3.1415926535897936,-3.141592653589793) \n",
297 | " Interval(-0.0,0.0) \n",
298 | " Interval(6.283185307202162,6.283185307202162) \n",
299 | " Interval(18.849555921561333,18.849555921561336) \n",
300 | " Interval(21.991148575151126,21.99114857515113) "
301 | ]
302 | }
303 | ],
304 | "prompt_number": 11
305 | },
306 | {
307 | "cell_type": "markdown",
308 | "metadata": {},
309 | "source": [
310 | "The roots that are lost depend on the points of the interval. No other function (except sin and based on it cos) does this. Interestingly, changing the procedure of sin into an alternative one left the problem unchanged."
311 | ]
312 | },
313 | {
314 | "cell_type": "code",
315 | "collapsed": false,
316 | "input": [],
317 | "language": "python",
318 | "metadata": {},
319 | "outputs": []
320 | }
321 | ],
322 | "metadata": {}
323 | }
324 | ]
325 | }
--------------------------------------------------------------------------------
/logistic-arbitrary.jl:
--------------------------------------------------------------------------------
1 | using NewtonMethod
2 |
3 | # Function composition
4 | compose(f::Function, g::Function) = x -> f(g(x))
5 |
6 | # Logistic function T(x) of the first order
7 | T1(x) = Interval(r)*(Interval(1/4)-(x-Interval(1/2))^2)
8 |
9 | # T^p (x) function - T(T(T(...T(x)))) p times
10 | function T(x, p)
11 | F = T1
12 | for i = 1:p-1
13 | F = compose(F, T1)
14 | end
15 | return F(x)
16 | end
17 |
18 | # Equation to solve for periodic points
19 |
20 | f(x, p) = T(x, p) - x
21 |
22 | r = 3.75
23 |
24 | f(x) = T(x, 8) - x
25 | newton(f, Interval(0.0000000001, 1), 512)
26 |
27 | #= Example output
28 | Function calls: 19
29 | 31-element Array{Interval,1}:
30 | Interval(2.70141733997309131900935211636288574483901429482501059532154506208297183996807957847829633116905071757806038469894488059344025411607098298341427286088463345e-01 with 512 bits of precision,2.70141733997309131900935211636288574483901429482501059532154506208297183996807957847829633116905071757806038469894488059344025411607098298341427286088463792e-01 with 512 bits of precision)
31 | Interval(2.74647636760931918840046974378059197911420565436949728776636765594938388294429628138380719979999854026710482365607036692728959040187437603028573367452714287e-01 with 512 bits of precision,2.74647636760931918840046974378059197911420565436949728776636765594938388294429628138380719979999854026710482365607036692728959040187437603028573367452714995e-01 with 512 bits of precision)
32 | Interval(3.0138171181726633936334181339465856447034349337873780523398986372086669732463733938459142325062332980240687180757639378136694887559077626546201191151561438e-01 with 512 bits of precision,3.01381711817266339363341813394658564470343493378737805233989863720866697324637339384591423250623329802406871807576393781366948875590776265462011911515615051e-01 with 512 bits of precision)
33 | Interval(3.08712576277511324461829601788358753550049139843400090231968259503551955534161812097844577167792000843709441476587235252683055900941920341118109072443522405e-01 with 512 bits of precision,3.08712576277511324461829601788358753550049139843400090231968259503551955534161812097844577167792000843709441476587235252683055900941920341118109072443523113e-01 with 512 bits of precision)
34 | Interval(3.66798186806905272073379444297018530917438548740483128515808130875022090521082841006090892219720057598088967935897122514296512155755215449527547847036711597e-01 with 512 bits of precision,3.66798186806905272073379444297018530917438548740483128515808130875022090521082841006090892219720057598088967935897122514296512155755215449527547847036712529e-01 with 512 bits of precision)
35 | Interval(3.78450775803430692686135645677894530453544376939824698561012796130981078865771575523406853340168442671144391465313379814252691099831785483761418991000291029e-01 with 512 bits of precision,3.78450775803430692686135645677894530453544376939824698561012796130981078865771575523406853340168442671144391465313379814252691099831785483761418991000291812e-01 with 512 bits of precision)
36 | Interval(4.10617758685194158020084074644597303577274924175521424154067697587735987938351697225502193609619674386681578126905119369812609634056998083116702622580651832e-01 with 512 bits of precision,4.10617758685194158020084074644597303577274924175521424154067697587735987938351697225502193609619674386681578126905119369812609634056998083116702622580652652e-01 with 512 bits of precision)
37 | Interval(4.2429101104593384973864956550002890959249659108940410455091507925280570816140225726198904774417796096204969838775219057848959796394078355287684139009193047e-01 with 512 bits of precision,4.24291011045933849738649565500028909592496591089404104550915079252805708161402257261989047744177960962049698387752190578489597963940783552876841390091931402e-01 with 512 bits of precision)
38 | Interval(5.7318379212630204408898661168704302350504723301380957392606699926998944631536054103660052370201266124561100075600772333537134467476609640409853155968299533e-01 with 512 bits of precision,5.73183792126302044088986611687043023505047233013809573926066999269989446315360541036600523702012661245611000756007723335371344674766096404098531559682996374e-01 with 512 bits of precision)
39 | Interval(5.92824367624351407929292833268682100619705230441170169638687726104889731985372093688432443846419608465710504370104633194043820729091546982633026028294981817e-01 with 512 bits of precision,5.92824367624351407929292833268682100619705230441170169638687726104889731985372093688432443846419608465710504370104633194043820729091546982633026028294982786e-01 with 512 bits of precision)
40 | Interval(6.17131705864440229122211127440407914709695646062694298168624551999972722541206527139384023687813497244366575775460548194871117747058392337549648803810393639e-01 with 512 bits of precision,6.17131705864440229122211127440407914709695646062694298168624551999972722541206527139384023687813497244366575775460548194871117747058392337549648803810394608e-01 with 512 bits of precision)
41 | Interval(6.37955377457103435004486384384682116483545332037301218881664118057901620563418872050203700796025592418384691816665978556041724706992728489161747287751938249e-01 with 512 bits of precision,6.37955377457103435004486384384682116483545332037301218881664118057901620563418872050203700796025592418384691816665978556041724706992728489161747287751939218e-01 with 512 bits of precision)
42 | Interval(6.85346050849424318856032513746113757716051637920528737020625551877192105901703809140235069074479417872458362294140322896647053262565609043898557787867166097e-01 with 512 bits of precision,6.85346050849424318856032513746113757716051637920528737020625551877192105901703809140235069074479417872458362294140322896647053262565609043898557787867167066e-01 with 512 bits of precision)
43 | Interval(7.04900116012334156176621269851610244955462747230100481462411647607712773260270648819212638188221137376596713557034120853859129627280751971519795473931089921e-01 with 512 bits of precision,7.04900116012334156176621269851610244955462747230100481462411647607712773260270648819212638188221137376596713557034120853859129627280751971519795473931090517e-01 with 512 bits of precision)
44 | Interval(7.19311930645055173976491685390702388906529225268829737848845774664565388772166593131585183054951655390981694560401685618093713472304695228549149382738651329e-01 with 512 bits of precision,7.19311930645055173976491685390702388906529225268829737848845774664565388772166593131585183054951655390981694560401685618093713472304695228549149382738652074e-01 with 512 bits of precision)
45 | Interval(7.34748010610079575596816976127320954907161803713527851458885941644562334217506631299734748010610079575596816976127320954907161803713527851458885941644562029e-01 with 512 bits of precision,7.34748010610079575596816976127320954907161803713527851458885941644562334217506631299734748010610079575596816976127320954907161803713527851458885941644562625e-01 with 512 bits of precision)
46 | Interval(7.43312719364390502084318158791807622280104302462812472248981692407736048176209257050948176267230584261223661807748755741792552548734499892986579584486721483e-01 with 512 bits of precision,7.43312719364390502084318158791807622280104302462812472248981692407736048176209257050948176267230584261223661807748755741792552548734499892986579584486722154e-01 with 512 bits of precision)
47 | Interval(7.5104549768227803081970631368228244762456586980133639156814468635103084995838555391967209341105529560318669953280033419090968945666029170278234873308438276e-01 with 512 bits of precision,7.5104549768227803081970631368228244762456586980133639156814468635103084995838555391967209341105529560318669953280033419090968945666029170278234873308438358e-01 with 512 bits of precision)
48 | Interval(7.61171584579304179915340358137628228608421111014895791246861220990877962339249435867362697679562840186647952273869267430436233586348096062296668790335239458e-01 with 512 bits of precision,7.61171584579304179915340358137628228608421111014895791246861220990877962339249435867362697679562840186647952273869267430436233586348096062296668790335240203e-01 with 512 bits of precision)
49 | Interval(7.84220103067157654843033781897425092460727931199554730113279865045357185986144239323802489621119072480368541527394187279839522116755503756071408934006958035e-01 with 512 bits of precision,7.84220103067157654843033781897425092460727931199554730113279865045357185986144239323802489621119072480368541527394187279839522116755503756071408934006958631e-01 with 512 bits of precision)
50 | Interval(7.93776424009589319853493368401011071936485127060845317825889083603345620789396876053449968867493328104043458354844221416456635412771784211577912853980185028e-01 with 512 bits of precision,7.93776424009589319853493368401011071936485127060845317825889083603345620789396876053449968867493328104043458354844221416456635412771784211577912853980185848e-01 with 512 bits of precision)
51 | Interval(8.04552388151561299148634786510741761220096592900707858241696023575283396912976239489208141454224715921253846782433428187669021737059581021323772518989637233e-01 with 512 bits of precision,8.04552388151561299148634786510741761220096592900707858241696023575283396912976239489208141454224715921253846782433428187669021737059581021323772518989637904e-01 with 512 bits of precision)
52 | Interval(8.12988592208150257534610957028715655742066381012222441901505883844702967193437423750979898452071608274906355087360433413277971761815499476183160699218476699e-01 with 512 bits of precision,8.12988592208150257534610957028715655742066381012222441901505883844702967193437423750979898452071608274906355087360433413277971761815499476183160699218477519e-01 with 512 bits of precision)
53 | Interval(8.70750543141618802533829389893130091823114804541495869218356161091015958734584878277488615636706326563347969541691136494586734588215821766796238021878908592e-01 with 512 bits of precision,8.70750543141618802533829389893130091823114804541495869218356161091015958734584878277488615636706326563347969541691136494586734588215821766796238021878909188e-01 with 512 bits of precision)
54 | Interval(8.75609934147011045211553765267387482681630049321819435887434300929107282839936909319388668379522958430347765968856231961243021526730775833671778687258206706e-01 with 512 bits of precision,8.75609934147011045211553765267387482681630049321819435887434300929107282839936909319388668379522958430347765968856231961243021526730775833671778687258207302e-01 with 512 bits of precision)
55 | Interval(8.86801213586489731717047378194784514639293819346647449980101262224456586916721793176858398649221477753258791558559299230840147096454686664779695067355145861e-01 with 512 bits of precision,8.86801213586489731717047378194784514639293819346647449980101262224456586916721793176858398649221477753258791558559299230840147096454686664779695067355146532e-01 with 512 bits of precision)
56 | Interval(8.907762163244491943089701201751873386534206694891951320407813813019362766965457330901057032391993843796882878715455859921959896022646389727939767144241214e-01 with 512 bits of precision,8.90776216324449194308970120175187338653420669489195132040781381301936276696545733090105703239199384379688287871545585992195989602264638972793976714424121996e-01 with 512 bits of precision)
57 | Interval(9.1001631064227501833186942863724909361476707601231319219434523224869473655128110812223870030608370751808905763650777553605756587484943294008014517567960139e-01 with 512 bits of precision,9.10016310642275018331869428637249093614767076012313192194345232248694736551281108122238700306083707518089057636507775536057565874849432940080145175679601837e-01 with 512 bits of precision)
58 | Interval(9.12380772314532644920514764099638296242933300313307492835808421346413940468740772156311160803982888374582174267039453718403687957934333648677822884590105313e-01 with 512 bits of precision,9.12380772314532644920514764099638296242933300313307492835808421346413940468740772156311160803982888374582174267039453718403687957934333648677822884590105984e-01 with 512 bits of precision)
59 | Interval(9.20890921698155147969462296192560975775690925359806528946589854389722444246393420707518885122706151221206601799887257757797093772863598413604419382369652742e-01 with 512 bits of precision,9.20890921698155147969462296192560975775690925359806528946589854389722444246393420707518885122706151221206601799887257757797093772863598413604419382369653189e-01 with 512 bits of precision)
60 | Interval(9.22308379788953575230534660463328165543626397524461957239433848283663754231803760000472109501536903221845725164535600873672161639508568015452506655300386598e-01 with 512 bits of precision,9.22308379788953575230534660463328165543626397524461957239433848283663754231803760000472109501536903221845725164535600873672161639508568015452506655300387045e-01 with 512 bits of precision)
61 | =#
62 |
63 |
64 |
--------------------------------------------------------------------------------
/modules/IntervalArithmetic.jl:
--------------------------------------------------------------------------------
1 | ## Interval arithmetic
2 |
3 | module IntervalArithmetic
4 | export Interval, rad, diam, mid, mig, mag, belong, hd, hull, isect, isectext, lo, hi, make_intervals, det2, inside
5 |
6 | typealias prec BigFloat
7 |
8 | type Interval
9 |
10 | lo
11 | hi
12 |
13 | function Interval(a, b)
14 | set_rounding(prec, RoundDown)
15 | lo = BigFloat("$a")
16 |
17 | set_rounding(prec, RoundUp)
18 | hi = BigFloat("$b")
19 |
20 | new(lo, hi)
21 | end
22 |
23 | end
24 |
25 | #import MPFR.BigFloat
26 | #BigFloat(x::Interval) = Interval(BigFloat(x.lo), BigFloat(x.hi))
27 |
28 | # Thin (degenerate) interval and functions zero() and one()
29 |
30 | Interval(x::Number) = Interval(x, x)
31 |
32 | # Prevent errors from embedded interval functions
33 | Interval(x::Interval) = x
34 |
35 | import Base.one
36 | one(x::Interval) = Interval(1.0)
37 |
38 | import Base.zero
39 | zero(x::Interval) = Interval(0.0)
40 | zero(Interval) = Interval(0)
41 |
42 | # The basic operations on intervals. Left end is rounded down, right end is rounded up.
43 |
44 | # Addition
45 |
46 | function +(x::Interval, y::Interval)
47 | z1 = with_rounding(prec, RoundDown) do
48 | x.lo + y.lo
49 | end
50 | z2 = with_rounding(prec, RoundUp) do
51 | x.hi + y.hi
52 | end
53 | Interval(z1, z2)
54 | end
55 |
56 | +(x::Interval, y::Real) = x + Interval(y)
57 | +(x::Real, y::Interval) = Interval(x) + y
58 |
59 | # Subtraction
60 |
61 | function -(x::Interval, y::Interval)
62 | z1 = with_rounding(prec, RoundDown) do
63 | x.lo - y.hi
64 | end
65 | z2 = with_rounding(prec, RoundUp) do
66 | x.hi - y.lo
67 | end
68 | Interval(z1, z2)
69 | end
70 |
71 | -(x::Interval) = Interval(-x.hi, -x.lo)
72 |
73 | -(x::Interval, y::Real) = x - Interval(y)
74 | -(x::Real, y::Interval) = Interval(x) - y
75 |
76 | # Multiplication
77 |
78 | function *(x::Interval, y::Interval)
79 | z1 = with_rounding(prec, RoundDown) do
80 | min(x.lo*y.lo, x.lo*y.hi, x.hi*y.lo, x.hi*y.hi)
81 | end
82 | z2 = with_rounding(prec, RoundUp) do
83 | max(x.lo*y.lo, x.lo*y.hi, x.hi*y.lo, x.hi*y.hi)
84 | end
85 | Interval(z1, z2)
86 | end
87 |
88 | *(x::Interval, y::Real) = x*Interval(y)
89 | *(x::Real, y::Interval) = Interval(x)*y
90 |
91 |
92 | # Division
93 |
94 | function /(x::Interval, y::Interval)
95 | z1 = with_rounding(prec, RoundDown) do
96 | 1/y.hi
97 | end
98 | z2 = with_rounding(prec, RoundUp) do
99 | 1/y.lo
100 | end
101 | x*Interval(z1, z2)
102 | end
103 |
104 | /(x::Interval, y::Real) = x/Interval(y)
105 | /(x::Real, y::Interval) = Interval(x)/y
106 |
107 | # Extended division
108 |
109 | function //(x::Interval, y::Interval)
110 | if belong(0., y) == false
111 | return x/y
112 | elseif belong(0., x) == true && belong(0, y) == true
113 | return Interval(-Inf, Inf)
114 | elseif x.hi < 0 && y.lo < y.hi == 0
115 | z1 = with_rounding(prec, RoundDown) do
116 | x.hi/y.lo
117 | end
118 | return Interval(z1, Inf)
119 | elseif x.hi < 0 && y.lo < 0 < y.hi
120 | z1 = with_rounding(prec, RoundDown) do
121 | x.hi/y.lo
122 | end
123 | z2 = with_rounding(prec, RoundUp) do
124 | x.hi/y.hi
125 | end
126 | return Interval(z1, z2)
127 | elseif x.hi < 0 && 0 == y.lo < y.hi
128 | z2 = with_rounding(prec, RoundUp) do
129 | x.hi/y.hi
130 | end
131 | return Interval(-Inf, z2)
132 | elseif 0 < x.lo && y.lo < y.hi == 0
133 | z2 = with_rounding(prec, RoundUp) do
134 | x.lo/y.lo
135 | end
136 | return Interval(-Inf, z2)
137 | elseif 0 < x.lo && y.lo < 0 < y.hi
138 | z1 = with_rounding(prec, RoundDown) do
139 | x.lo/y.hi
140 | end
141 | z2 = with_rounding(prec, RoundUp) do
142 | x.lo/y.lo
143 | end
144 | return Interval(z1, z2)
145 | elseif 0 < x.lo && 0 == y.lo < y.hi
146 | z1 = with_rounding(prec, RoundDown) do
147 | x.lo/y.hi
148 | end
149 | return Interval(z1, Inf)
150 | elseif belong(0, x) == false && y.lo == 0 && y.hi == 0
151 | return error("\nEmpty set: extended division by thin zero")
152 | end
153 | end
154 |
155 |
156 | ## Interval properties
157 |
158 | # Whether the point belongs to the interval: belong(point, interval)
159 |
160 | function belong(p::Real, x::Interval)
161 | if p >= x.lo && p <= x.hi
162 | return true
163 | else
164 | return false
165 | end
166 | end
167 |
168 | # Whether one interval is inside of the other
169 |
170 | function inside(x::Interval, y::Interval)
171 | if x.lo > y.lo && x.hi < y.hi
172 | return true
173 | else
174 | return false
175 | end
176 | end
177 |
178 | # Lower end, higher end, bottom, top, radius, diameter, midpoint, mignitude, magnitude, absolute value
179 |
180 | lo(x::Interval) = x.lo
181 | hi(x::Interval) = x.hi
182 | rad(x::Interval) = (x.hi - x.lo)/2
183 | diam(x::Interval) = x.hi - x.lo
184 | mid(x::Interval) = (x.hi + x.lo)/2
185 | mid(x::prec) = x
186 |
187 | function mig(x::Interval)
188 | if belong(0.0, x) == true
189 | return 0
190 | else return min(abs(x.lo), abs(x.hi))
191 | end
192 | end
193 |
194 | mag(x::Interval) = max(abs(x.lo), abs(x.hi))
195 |
196 | import Base.abs
197 | abs(x::Interval) = Interval(mig(x), mag(x))
198 |
199 |
200 | # Hausdorff distance
201 |
202 | hd(x::Interval, y::Interval) = max(abs(x.lo - y.lo), abs(x.hi - y.hi))
203 |
204 |
205 | # "Union" (hull) and intersection
206 |
207 | hull(x::Interval, y::Interval) = Interval(min(x.lo, y.lo), max(x.hi, y.hi))
208 |
209 | function isect(x::Interval, y::Interval)
210 | if x.hi < y.lo || y.hi < x.lo
211 | return false
212 | else
213 | z1 = with_rounding(prec, RoundDown) do
214 | max(x.lo, y.lo)
215 | end
216 | z2 = with_rounding(prec, RoundUp) do
217 | min(x.hi, y.hi)
218 | end
219 | return Interval(z1, z2)
220 | end
221 | end
222 |
223 | # Extended intersection (involving extended intervals [a, b] with a > b)
224 |
225 | function isectext(x::Interval, y::Interval)
226 | if x.hi < x.lo && y.hi >= y.lo # x is an extended interval and y is a normal one
227 | if y.lo <= x.hi && x.lo <= y.hi
228 | return [Interval(y.lo, x.hi), Interval(x.lo, y.hi)]
229 | elseif y.lo > x.hi && x.lo <= y.hi && y.lo <= x.lo
230 | return Interval(x.lo, y.hi)
231 | elseif y.lo <= x.hi && x.lo > y.hi && y.hi >= x.hi
232 | return Interval(y.lo, x.hi)
233 | elseif y.lo > x.hi && x.lo > y.hi
234 | return false
235 | elseif y.lo <= x.hi && x.lo > y.hi && y.hi < x.hi
236 | return y
237 | elseif y.lo > x.hi && x.lo <= y.hi && y.lo > x.lo
238 | return y
239 | end
240 | elseif x.hi < x.lo && y.hi < y.lo # both intervals are extended
241 | return Interval(max(x.lo, y.lo), min(x.hi, y.hi)) # Returns also an extended interval
242 | elseif x.hi >= x.lo && y.hi < y.lo # x normal, y extended
243 | return isectext(y, x)
244 | elseif x.hi >= x.lo && y.hi >= y.lo # both intervals are normal
245 | return isect(x, y)
246 | end
247 | end
248 |
249 |
250 | # Integer power
251 |
252 | function ^(x::Interval, n::Integer)
253 | if n > 0 && n % 2 == 1
254 | return Interval(x.lo^n, x.hi^n)
255 | elseif n > 0 && n % 2 == 0
256 | return Interval((mig(x))^n, (mag(x))^n)
257 | elseif n == 0
258 | return Interval(1, 1)
259 | elseif n < 0 && belong(0, x) == false
260 | return Interval(1/x.hi, 1/x.lo)^(-n)
261 | # elseif return println("Error")
262 | end
263 | end
264 |
265 |
266 | # Real power function - taken from https://github.com/dpsanders/ValidatedNumerics.jl
267 |
268 |
269 |
270 | macro round_down(expr)
271 | quote
272 | with_rounding(BigFloat, RoundDown) do
273 | $expr
274 | end
275 | end
276 | end
277 |
278 | macro round_up(expr)
279 | quote
280 | with_rounding(BigFloat, RoundUp) do
281 | $expr
282 | end
283 | end
284 | end
285 |
286 | macro round(expr1, expr2)
287 | quote
288 | Interval(@round_down($expr1), @round_up($expr2))
289 | end
290 | end
291 |
292 | function reciprocal(a::Interval)
293 | uno = one(BigFloat)
294 | z = zero(BigFloat)
295 | if belong(z, a)
296 | #if z in a
297 | warn("\nInterval in denominator contains 0.")
298 | return Interval(-inf(z),inf(z)) # inf(z) returns inf of type of z
299 | end
300 | @round(uno/a.hi, uno/a.lo)
301 | end
302 |
303 | function ^(a::Interval, x::Real)
304 | x == int(x) && return a^(int(x))
305 | x < zero(x) && return reciprocal( a^(-x) )
306 | x == 0.5*one(x) && return sqrt(a)
307 | #
308 | z = zero(BigFloat)
309 | z > a.hi && error("Undefined operation; Interval is strictly negative and power is not an integer")
310 | #
311 | xInterv = Interval( x )
312 | diam( xInterv ) >= eps(x) && return a^xInterv
313 | # xInterv is a thin interval
314 | domainPow = Interval(z, big(Inf))
315 | aRestricted = isect(a, domainPow)
316 | @round(aRestricted.lo^x, aRestricted.hi^x)
317 | end
318 |
319 |
320 |
321 |
322 |
323 | # Interval power - exercise 3.5 from Tucker "Validated Numerics"
324 |
325 | function ^(x::Interval, n::Interval)
326 | if x.lo > 0
327 | z1 = min(x.lo^n.lo, x.lo^n.hi, x.hi^n.lo, x.hi^n.hi)
328 | z2 = max(x.lo^n.lo, x.lo^n.hi, x.hi^n.lo, x.hi^n.hi)
329 | return Interval(z1, z2)
330 | end
331 | end
332 |
333 |
334 | # Trigonometry
335 |
336 | #= COMMENTED OUT: old Tucker definition of sin
337 | import Base.sin
338 | function sin(x::Interval)
339 |
340 | k = 0
341 | pcount = 0
342 | for k = -1000:1000
343 | p = pi/2 + 2pi*k
344 | if belong(p, x) == true
345 | pcount = pcount + 1
346 | end
347 | end
348 |
349 | k = 0
350 | qcount = 0
351 | for k = -1000:1000
352 | q = - pi/2 + 2pi*k
353 | if belong(q, x) == true
354 | qcount = qcount + 1
355 | end
356 | end
357 |
358 | if qcount != 0 && pcount != 0
359 | return Interval(-1., 1.)
360 | elseif qcount != 0 && pcount == 0
361 | return Interval(-1., max(sin(x.lo), sin(x.hi)))
362 | elseif qcount == 0 && pcount != 0
363 | return Interval(min(sin(x.lo), sin(x.hi)), 1.)
364 | elseif qcount == 0 && pcount == 0
365 | return Interval(min(sin(x.lo), sin(x.hi)), max(sin(x.lo), sin(x.hi)))
366 | end
367 | end
368 | =#
369 |
370 |
371 | # Taken from http://jenchienjackchang.com/sample-page/implicit-solid-modeling-using-interval-methods/interval-arithmetic/
372 |
373 | #= Deprecated in favour of the next
374 | import Base.sin
375 | function sin(x::Interval)
376 | if x.lo%2pi >= 0
377 | low = x.lo%2pi
378 | else low = x.lo%2pi + 2pi
379 | end
380 | x1 = Interval(low, low + diam(x))
381 | # If the interval has a diameter equal or greater than 2pi or it is an extended interval, return [-1, 1]
382 | if diam(x) >= 2pi || x.lo > x.hi
383 | return Interval(-1, 1)
384 | elseif 0 <= x1.lo <= x1.hi <= pi/2 || 3pi/2 <= x1.lo <= x1.hi <= 5pi/2 || 7pi/2 <= x1.lo <= x1.hi <= 4pi
385 | return Interval(sin(x1.lo), sin(x1.hi))
386 | elseif pi/2 <= x1.lo <= x1.hi <= 3pi/2 || 5pi/2 <= x1.lo <= x1.hi <= 7pi/2
387 | return Interval(sin(x1.hi), sin(x1.lo))
388 | elseif (0 <= x1.lo <= pi/2 && pi/2 <= x1.hi <= 3pi/2) || (3pi/2 <= x1.lo <= 5pi/2 && 5pi/2 <= x1.hi <= 7pi/2)
389 | return Interval(min(sin(x1.lo), sin(x1.hi)), 1)
390 | elseif (pi/2 <= x1.lo <= 3pi/2 && 3pi/2 <= x1.hi <= 5pi/2) || (5pi/2 <= x1.lo <= 7pi/2 && 7pi/2 <= x1.hi <= 4pi)
391 | return Interval(-1, max(sin(x1.lo), sin(x1.hi)))
392 | elseif (0 <= x1.lo <= pi/2 && 3pi/2 <= x1.hi <= 5pi/2) || (pi/2 <= x1.lo <= 3pi/2 && 5pi/2 <= x1.hi <= 7pi/2) || (3pi/2 <= x1.lo <= 5pi/2 && 7pi/2 <= x1.hi <= 4pi)
393 | return Interval(-1, 1)
394 | end
395 |
396 | end
397 | =#
398 |
399 | # Using Sanders/Benet sin() from https://github.com/dpsanders/ValidatedNumerics.jl
400 | import Base.sin
401 | function sin(a::Interval)
402 | piHalf = pi*BigFloat("0.5")
403 | twoPi = pi*BigFloat("2.0")
404 | domainSin = Interval( BigFloat(-1.0), BigFloat(1.0) )
405 |
406 | # Checking the specific case
407 | diam(a) >= twoPi && return domainSin
408 |
409 | # Limits within 1 full period of sin(x)
410 | # Abbreviations
411 | loMod2pi = mod(a.lo, twoPi)
412 | hiMod2pi = mod(a.hi, twoPi)
413 | loQuartile = floor( loMod2pi / piHalf )
414 | hiQuartile = floor( hiMod2pi / piHalf )
415 |
416 | # 20 different cases
417 | if loQuartile == hiQuartile # Interval limits in the same quartile
418 | loMod2pi > hiMod2pi && return domainSin
419 | set_rounding(BigFloat, RoundDown)
420 | lo = sin( a.lo )
421 | set_rounding(BigFloat, RoundUp)
422 | hi = sin( a.hi )
423 | set_rounding(BigFloat, RoundNearest)
424 | return Interval( lo, hi )
425 | elseif loQuartile == 3 && hiQuartile==0
426 | set_rounding(BigFloat, RoundDown)
427 | lo = sin( a.lo )
428 | set_rounding(BigFloat, RoundUp)
429 | hi = sin( a.hi )
430 | set_rounding(BigFloat, RoundNearest)
431 | return Interval( lo, hi )
432 | elseif loQuartile == 1 && hiQuartile==2
433 | set_rounding(BigFloat, RoundDown)
434 | lo = sin( a.hi )
435 | set_rounding(BigFloat, RoundUp)
436 | hi = sin( a.lo )
437 | set_rounding(BigFloat, RoundNearest)
438 | return Interval( lo, hi )
439 | elseif ( loQuartile == 0 || loQuartile==3 ) && ( hiQuartile==1 || hiQuartile==2 )
440 | set_rounding(BigFloat, RoundDown)
441 | slo = sin( a.lo )
442 | shi = sin( a.hi )
443 | set_rounding(BigFloat, RoundNearest)
444 | lo = min( slo, shi )
445 | return Interval( lo, BigFloat(1.0) )
446 | elseif ( loQuartile == 1 || loQuartile==2 ) && ( hiQuartile==3 || hiQuartile==0 )
447 | set_rounding(BigFloat, RoundUp)
448 | slo = sin( a.lo )
449 | shi = sin( a.hi )
450 | set_rounding(BigFloat, RoundNearest)
451 | hi = max( slo, shi )
452 | return Interval( BigFloat(-1.0), hi )
453 | elseif ( loQuartile == 0 && hiQuartile==3 ) || ( loQuartile == 2 && hiQuartile==1 )
454 | return domainSin
455 | else
456 | # This should be never reached!
457 | error(string("SOMETHING WENT WRONG in sin.\nThis should have never been reached") )
458 | end
459 | end
460 |
461 |
462 | import Base.cos
463 | cos(x::Interval) = sin(Interval(x.lo + pi/2, x.hi + pi/2))
464 |
465 | # Miscellaneous
466 |
467 | import Base.complex
468 | complex(x::Interval) = Interval(complex(x.lo), complex(x.hi))
469 |
470 | function *(x::Array{Interval, 1}, y::Interval)
471 | [x[1]*y, x[2]*y]
472 | end
473 |
474 |
475 | function /(x::Array{Any, 1}, y::Interval)
476 | [x[1]/y, x[2]/y]
477 | end
478 |
479 | # Equality of two intervals
480 | ==(a::Interval, b::Interval) = a.lo == b.lo && a.hi == b.hi
481 |
482 | # Monotonic functions
483 |
484 | import Base.exp
485 | exp(x::Interval) = Interval(exp(x.lo), exp(x.hi))
486 |
487 | import Base.sqrt
488 | sqrt(x::Interval) = Interval(sqrt(x.lo), sqrt(x.hi))
489 |
490 | import Base.log
491 | log(x::Interval) = Interval(log(x.lo), log(x.hi))
492 |
493 | import Base.asin
494 | asin(x::Interval) = Interval(asin(x.lo), asin(x.hi))
495 |
496 | import Base.acos
497 | acos(x::Interval) = Interval(acos(x.hi), acos(x.lo))
498 |
499 |
500 | #-------------------------------------------------------
501 |
502 | ## Interval arithmetic for 2D objects
503 |
504 | function lo(x::Array{Interval})
505 | y = prec[]
506 | for i = 1:length(x)
507 | push!(y, lo(x[i]))
508 | end
509 | y
510 | end
511 |
512 | function hi(x::Array{Interval})
513 | y = prec[]
514 | for i = 1:length(x)
515 | push!(y, hi(x[i]))
516 | end
517 | y
518 | end
519 |
520 | # Making mid() process 1-D and 2-D interval arrays into arrays of midpoints
521 | function mid(array::Array{Interval, 1})
522 | array1 = prec[]
523 | for i = 1:length(array)
524 | push!(array1, mid(array[i]))
525 | end
526 | array1
527 | end
528 |
529 | function mid(array::Array{Interval, 2})
530 | array1 = prec[]
531 | for i = 1:length(array)
532 | push!(array1, mid(array[i]))
533 | end
534 | reshape(array1, (2, 2))
535 | end
536 |
537 | function mid(array::Array{Array{Interval, 1}, 1})
538 | array1 = Array{prec, 1}[]
539 | for i = 1:length(array)
540 | push!(array1, mid(array[i]))
541 | end
542 | array1
543 | end
544 |
545 | function diam(x::Array{Interval, 1})
546 | y = prec[]
547 | for i = 1:length(x)
548 | push!(y, diam(x[i]))
549 | end
550 | y
551 | end
552 |
553 |
554 | # Function that makes numbers into thin intervals in arrays
555 | function make_intervals(x::Array{prec, 1})
556 | y = Interval[]
557 | for i = 1:length(x)
558 | push!(y, Interval(x[i]))
559 | end
560 | return y
561 | end
562 |
563 |
564 | function make_intervals(x::Array{prec, 2})
565 | y = Interval[]
566 | for i = 1:length(x)
567 | push!(y, Interval(x[i]))
568 | end
569 | return reshape(y, (2, 2))
570 | end
571 |
572 | # Intersection of 2-D vectors
573 | function isect(x::Array{Interval, 1}, y::Array{Interval, 1})
574 | z = Interval[]
575 | if length(x) == length(y)
576 | for i = 1:length(x)
577 | if isect(x[i], y[i]) == false
578 | return false
579 | end
580 | end
581 | for i = 1:length(x)
582 | push!(z, isect(x[i], y[i]))
583 | end
584 | else return false
585 | end
586 | return z
587 | end
588 |
589 |
590 | function isectext(x::Array{Interval, 1}, y::Array{Interval, 1})
591 | z = Interval[]
592 | if length(x) == length(y)
593 | for i = 1:length(x)
594 | if isectext(x[i], y[i]) == false
595 | return false
596 | end
597 | end
598 | for i = 1:length(x)
599 | push!(z, isectext(x[i], y[i]))
600 | end
601 | else return false
602 | end
603 | return z
604 | end
605 |
606 | # Determinant of a 2x2 interval matrix
607 |
608 | det2(x::Array{Interval, 2}) = x[1]*x[4] - x[3]*x[2]
609 |
610 | # Definitions for the inverse of an interval matrix
611 |
612 | import Base.one; one(::Type{Interval}) = Interval(1)
613 | import Base.real; real(x::Interval) = x
614 | import Base.inv; inv(x::Interval) = Interval(1)/x
615 | import Base.isless; isless(a::Interval, b::Interval) = a.hi < b.lo
616 |
617 |
618 | # End of module
619 | end
620 |
--------------------------------------------------------------------------------
/krawczyk2d-examples.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "metadata": {
3 | "language": "Julia",
4 | "name": ""
5 | },
6 | "nbformat": 3,
7 | "nbformat_minor": 0,
8 | "worksheets": [
9 | {
10 | "cells": [
11 | {
12 | "cell_type": "code",
13 | "collapsed": false,
14 | "input": [
15 | "# Krawczyk 2D actually works, but when the intervals are large, it stalls"
16 | ],
17 | "language": "python",
18 | "metadata": {},
19 | "outputs": [],
20 | "prompt_number": 1
21 | },
22 | {
23 | "cell_type": "code",
24 | "collapsed": false,
25 | "input": [
26 | "include(\"krawczyk2d.jl\")"
27 | ],
28 | "language": "python",
29 | "metadata": {},
30 | "outputs": [
31 | {
32 | "metadata": {},
33 | "output_type": "pyout",
34 | "prompt_number": 6,
35 | "text": [
36 | "krawczyk2d (generic function with 2 methods)"
37 | ]
38 | }
39 | ],
40 | "prompt_number": 6
41 | },
42 | {
43 | "cell_type": "code",
44 | "collapsed": false,
45 | "input": [
46 | "f(x) = [x[1]^2 + x[2]^2 - 1, x[1] - x[2]^2]"
47 | ],
48 | "language": "python",
49 | "metadata": {},
50 | "outputs": [
51 | {
52 | "metadata": {},
53 | "output_type": "pyout",
54 | "prompt_number": 3,
55 | "text": [
56 | "f (generic function with 1 method)"
57 | ]
58 | }
59 | ],
60 | "prompt_number": 3
61 | },
62 | {
63 | "cell_type": "code",
64 | "collapsed": false,
65 | "input": [
66 | "a = [Interval(0.5, 0.8), Interval(0.6, 0.9)]"
67 | ],
68 | "language": "python",
69 | "metadata": {},
70 | "outputs": [
71 | {
72 | "metadata": {},
73 | "output_type": "pyout",
74 | "prompt_number": 4,
75 | "text": [
76 | "2-element Array{Interval,1}:\n",
77 | " Interval(5e-01 with 256 bits of precision,8.000000000000000000000000000000000000000000000000000000000000000000000000000017e-01 with 256 bits of precision) \n",
78 | " Interval(5.999999999999999999999999999999999999999999999999999999999999999999999999999948e-01 with 256 bits of precision,9.000000000000000000000000000000000000000000000000000000000000000000000000000052e-01 with 256 bits of precision)"
79 | ]
80 | }
81 | ],
82 | "prompt_number": 4
83 | },
84 | {
85 | "cell_type": "code",
86 | "collapsed": false,
87 | "input": [
88 | "krawczyk2d(f, a)"
89 | ],
90 | "language": "python",
91 | "metadata": {},
92 | "outputs": [
93 | {
94 | "output_type": "stream",
95 | "stream": "stdout",
96 | "text": [
97 | "a => [Interval(5e-01 with 256 bits of precision,8.000000000000000000000000000000000000000000000000000000000000000000000000000017e-01 with 256 bits of precision),Interval(5.999999999999999999999999999999999999999999999999999999999999999999999999999948e-01 with 256 bits of precision,9.000000000000000000000000000000000000000000000000000000000000000000000000000052e-01 with 256 bits of precision)]"
98 | ]
99 | },
100 | {
101 | "output_type": "stream",
102 | "stream": "stdout",
103 | "text": [
104 | "\n",
105 | "diam(a) => BigFloat[3.00000000000000000011e-01,3.00000000000000000011e-01]\n",
106 | "a => [Interval(5.59782608695652173609e-01 with 64 bits of precision,6.77173913043478261232e-01 with 64 bits of precision),Interval(7.44275362318840579489e-01 with 64 bits of precision,8.30362318840579710351e-01 with 64 bits of precision)]\n",
107 | "diam(a) => BigFloat[1.17391304347826087623e-01,8.60869565217391308621e-02]\n",
108 | "k += 1 => 3\n",
109 | "a => [Interval(6.11640871255334431689e-01 with 64 bits of precision,6.2442728271432796749e-01 with 64 bits of precision),Interval(7.81842914150279365824e-01 with 64 bits of precision,7.90461684587798984547e-01 with 64 bits of precision)]\n",
110 | "diam(a) => BigFloat[1.27864114589935358012e-02,8.61877043751961872346e-03]\n",
111 | "k += 1 => 4\n",
112 | "a => [Interval(6.17961699100631085921e-01 with 64 bits of precision,6.18106278469247463888e-01 with 64 bits of precision),Interval(7.86096586748077572548e-01 with 64 bits of precision,7.86206171543394608436e-01 with 64 bits of precision)]\n",
113 | "diam(a) => BigFloat[1.44579368616377967102e-04,1.09584795317035888461e-04]\n",
114 | "k += 1 => 5\n",
115 | "a => [Interval(6.18033978705287749924e-01 with 64 bits of precision,6.18033998794501946436e-01 with 64 bits of precision),Interval(7.8615137096578607801e-01 with 64 bits of precision,7.86151384549060496562e-01 with 64 bits of precision)]\n",
116 | "diam(a) => BigFloat[2.00892141965125677061e-08,1.35832744185522893976e-08]\n",
117 | "Unique zero in [Interval(6.18033988749894675277e-01 with 64 bits of precision,6.18033988749895021029e-01 with 64 bits of precision),Interval(7.86151377757423169867e-01 with 64 bits of precision,7.86151377757423402211e-01 with 64 bits of precision)]"
118 | ]
119 | },
120 | {
121 | "output_type": "stream",
122 | "stream": "stdout",
123 | "text": [
124 | "\n"
125 | ]
126 | },
127 | {
128 | "metadata": {},
129 | "output_type": "pyout",
130 | "prompt_number": 6,
131 | "text": [
132 | "1-element Array{Array{Interval,1},1}:\n",
133 | " [Interval(6.18033988749894675277e-01 with 64 bits of precision,6.18033988749895021029e-01 with 64 bits of precision),Interval(7.86151377757423169867e-01 with 64 bits of precision,7.86151377757423402211e-01 with 64 bits of precision)]"
134 | ]
135 | }
136 | ],
137 | "prompt_number": 6
138 | },
139 | {
140 | "cell_type": "code",
141 | "collapsed": false,
142 | "input": [
143 | "# Works. Now let's increase starting intervals"
144 | ],
145 | "language": "python",
146 | "metadata": {},
147 | "outputs": [],
148 | "prompt_number": 7
149 | },
150 | {
151 | "cell_type": "code",
152 | "collapsed": false,
153 | "input": [
154 | "a = [Interval(0, 2), Interval(0, 2)]"
155 | ],
156 | "language": "python",
157 | "metadata": {},
158 | "outputs": [
159 | {
160 | "metadata": {},
161 | "output_type": "pyout",
162 | "prompt_number": 8,
163 | "text": [
164 | "2-element Array{Interval,1}:\n",
165 | " Interval(0e+00 with 64 bits of precision,2e+00 with 64 bits of precision)\n",
166 | " Interval(0e+00 with 64 bits of precision,2e+00 with 64 bits of precision)"
167 | ]
168 | }
169 | ],
170 | "prompt_number": 8
171 | },
172 | {
173 | "cell_type": "code",
174 | "collapsed": false,
175 | "input": [
176 | "# This will set the algorithm into an infinite loop."
177 | ],
178 | "language": "python",
179 | "metadata": {},
180 | "outputs": [],
181 | "prompt_number": 1
182 | },
183 | {
184 | "cell_type": "code",
185 | "collapsed": false,
186 | "input": [
187 | "# Let's see the next example: it actually does find the roots, but when the intervals are very small"
188 | ],
189 | "language": "python",
190 | "metadata": {},
191 | "outputs": [],
192 | "prompt_number": 2
193 | },
194 | {
195 | "cell_type": "code",
196 | "collapsed": false,
197 | "input": [
198 | "f(x) = [20 - 20x[1] - x[2], x[1] - x[2]/20 - 1e-9*exp(x[2]/0.052)]"
199 | ],
200 | "language": "python",
201 | "metadata": {},
202 | "outputs": [
203 | {
204 | "metadata": {},
205 | "output_type": "pyout",
206 | "prompt_number": 3,
207 | "text": [
208 | "f (generic function with 1 method)"
209 | ]
210 | }
211 | ],
212 | "prompt_number": 3
213 | },
214 | {
215 | "cell_type": "code",
216 | "collapsed": false,
217 | "input": [
218 | "# trueroots = [0.9464142468335176, 1.0717150633296477]"
219 | ],
220 | "language": "python",
221 | "metadata": {},
222 | "outputs": [],
223 | "prompt_number": 4
224 | },
225 | {
226 | "cell_type": "code",
227 | "collapsed": false,
228 | "input": [
229 | "a = [Interval(0.94, 0.95), Interval(1.05, 1.08)]"
230 | ],
231 | "language": "python",
232 | "metadata": {},
233 | "outputs": [
234 | {
235 | "metadata": {},
236 | "output_type": "pyout",
237 | "prompt_number": 7,
238 | "text": [
239 | "2-element Array{Interval,1}:\n",
240 | " Interval(9.399999999999999999999999999999999999999999999999999999999999999999999999999927e-01 with 256 bits of precision,9.500000000000000000000000000000000000000000000000000000000000000000000000000069e-01 with 256 bits of precision)\n",
241 | " Interval(1.049999999999999999999999999999999999999999999999999999999999999999999999999993e+00 with 256 bits of precision,1.08000000000000000000000000000000000000000000000000000000000000000000000000001e+00 with 256 bits of precision) "
242 | ]
243 | }
244 | ],
245 | "prompt_number": 7
246 | },
247 | {
248 | "cell_type": "code",
249 | "collapsed": false,
250 | "input": [
251 | "krawczyk2d(f, a)"
252 | ],
253 | "language": "python",
254 | "metadata": {},
255 | "outputs": [
256 | {
257 | "output_type": "stream",
258 | "stream": "stdout",
259 | "text": [
260 | "a => [Interval(9.399999999999999999999999999999999999999999999999999999999999999999999999999927e-01 with 256 bits of precision,9.500000000000000000000000000000000000000000000000000000000000000000000000000069e-01 with 256 bits of precision),Interval(1.049999999999999999999999999999999999999999999999999999999999999999999999999993e+00 with 256 bits of precision,1.08000000000000000000000000000000000000000000000000000000000000000000000000001e+00 with 256 bits of precision)]"
261 | ]
262 | },
263 | {
264 | "output_type": "stream",
265 | "stream": "stdout",
266 | "text": [
267 | "\n",
268 | "diam(a) => BigFloat[1.00000000000000000006e-02,3.00000000000000000011e-02]\n",
269 | "a => [Interval(9.46142624135044351362e-01 with 64 bits of precision,9.4664088171185997489e-01 with 64 bits of precision),Interval(1.06718236576280050654e+00 with 64 bits of precision,1.07714751729911297124e+00 with 64 bits of precision)]\n",
270 | "diam(a) => BigFloat[4.98257576815623528122e-04,9.96515153631246470775e-03]\n",
271 | "k += 1 => 3\n",
272 | "a => [Interval(9.46389241901565050083e-01 with 64 bits of precision,9.46439058833313800773e-01 with 64 bits of precision),Interval(1.07121882333372398627e+00 with 64 bits of precision,1.07221516196869899313e+00 with 64 bits of precision)]\n",
273 | "diam(a) => BigFloat[4.98169317487506899816e-05,9.96338634975006860739e-04]\n",
274 | "k += 1 => 4\n",
275 | "a => [Interval(9.46413799486205053785e-01 with 64 bits of precision,9.46414692531945470576e-01 with 64 bits of precision),Interval(1.07170614936109058989e+00 with 64 bits of precision,1.07172401027589892007e+00 with 64 bits of precision)]\n",
276 | "diam(a) => BigFloat[8.93045740416791109656e-07,1.78609148083301843418e-05]\n",
277 | "k += 1 => 5\n",
278 | "a => [Interval(9.46414246757269344147e-01 with 64 bits of precision,9.46414246909765635783e-01 with 64 bits of precision),Interval(1.07171506180468728607e+00 with 64 bits of precision,1.07171506485461311684e+00 with 64 bits of precision)]\n",
279 | "diam(a) => BigFloat[1.5249629163605060711e-10,3.04992583076944823173e-09]\n",
280 | "Unique zero in [Interval(9.46414246833517617413e-01 with 64 bits of precision,9.46414246833517622346e-01 with 64 bits of precision),Interval(1.07171506332964755785e+00 with 64 bits of precision,1.0717150633296476474e+00 with 64 bits of precision)]"
281 | ]
282 | },
283 | {
284 | "output_type": "stream",
285 | "stream": "stdout",
286 | "text": [
287 | "\n"
288 | ]
289 | },
290 | {
291 | "metadata": {},
292 | "output_type": "pyout",
293 | "prompt_number": 8,
294 | "text": [
295 | "1-element Array{Array{Interval,1},1}:\n",
296 | " [Interval(9.46414246833517617413e-01 with 64 bits of precision,9.46414246833517622346e-01 with 64 bits of precision),Interval(1.07171506332964755785e+00 with 64 bits of precision,1.0717150633296476474e+00 with 64 bits of precision)]"
297 | ]
298 | }
299 | ],
300 | "prompt_number": 8
301 | },
302 | {
303 | "cell_type": "code",
304 | "collapsed": false,
305 | "input": [
306 | "# In the next function it finds the root, but only when it is closely surrounded by a starting interval"
307 | ],
308 | "language": "python",
309 | "metadata": {},
310 | "outputs": [],
311 | "prompt_number": 9
312 | },
313 | {
314 | "cell_type": "code",
315 | "collapsed": false,
316 | "input": [
317 | "f(x) = [0.5*(-(17.76x[1] - 103.79x[1]^2 + 229.62x[1]^3 - 226.31x[1]^4 + 83.72x[1]^5) + x[2]), 0.2*(-x[1] - 1.5x[2] + 1.2)]"
318 | ],
319 | "language": "python",
320 | "metadata": {},
321 | "outputs": [
322 | {
323 | "metadata": {},
324 | "output_type": "pyout",
325 | "prompt_number": 10,
326 | "text": [
327 | "f (generic function with 1 method)"
328 | ]
329 | }
330 | ],
331 | "prompt_number": 10
332 | },
333 | {
334 | "cell_type": "code",
335 | "collapsed": false,
336 | "input": [
337 | "# trueroots = [0.06263595920972119, 0.758242693860186]\n",
338 | "# trueroots = [0.8844295888702942, 0.21038027408647064]\n",
339 | "# trueroots = [0.2853687241300338, 0.6097541839133109]"
340 | ],
341 | "language": "python",
342 | "metadata": {},
343 | "outputs": [],
344 | "prompt_number": 11
345 | },
346 | {
347 | "cell_type": "code",
348 | "collapsed": false,
349 | "input": [
350 | "a = [Interval(0.05, 0.1), Interval(-100, 100)]"
351 | ],
352 | "language": "python",
353 | "metadata": {},
354 | "outputs": [
355 | {
356 | "metadata": {},
357 | "output_type": "pyout",
358 | "prompt_number": 12,
359 | "text": [
360 | "2-element Array{Interval,1}:\n",
361 | " Interval(4.99999999999999999973e-02 with 64 bits of precision,1.00000000000000000001e-01 with 64 bits of precision)\n",
362 | " Interval(-1e+02 with 64 bits of precision,1e+02 with 64 bits of precision) "
363 | ]
364 | }
365 | ],
366 | "prompt_number": 12
367 | },
368 | {
369 | "cell_type": "code",
370 | "collapsed": false,
371 | "input": [
372 | "krawczyk2d(f, a)"
373 | ],
374 | "language": "python",
375 | "metadata": {},
376 | "outputs": [
377 | {
378 | "output_type": "stream",
379 | "stream": "stdout",
380 | "text": [
381 | "a => [Interval(4.99999999999999999973e-02 with 64 bits of precision,1.00000000000000000001e-01 with 64 bits of precision),Interval(-1e+02 with 64 bits of precision,1e+02 with 64 bits of precision)]"
382 | ]
383 | },
384 | {
385 | "output_type": "stream",
386 | "stream": "stdout",
387 | "text": [
388 | "\n",
389 | "diam(a) => BigFloat[5.00000000000000000041e-02,2e+02]\n",
390 | "a => [Interval(4.99999999999999999973e-02 with 64 bits of precision,9.4550344742341260653e-02 with 64 bits of precision),Interval(7.36966436838439141379e-01 with 64 bits of precision,7.81488500003341015883e-01 with 64 bits of precision)]\n",
391 | "diam(a) => BigFloat[4.45503447423412606557e-02,4.4522063164901874504e-02]\n",
392 | "k += 1 => 3\n",
393 | "a => [Interval(4.99999999999999999973e-02 with 64 bits of precision,8.65160934538207583382e-02 with 64 bits of precision),Interval(7.42322604364119464221e-01 with 64 bits of precision,7.75318412680682777062e-01 with 64 bits of precision)]\n",
394 | "diam(a) => BigFloat[3.65160934538207583409e-02,3.29958083165633128415e-02]\n",
395 | "k += 1 => 4\n",
396 | "a => [Interval(4.43949064835282951901e-02 with 64 bits of precision,7.94399873513205070338e-02 with 64 bits of precision),Interval(7.47040008432452965479e-01 with 64 bits of precision,7.70403395677647773621e-01 with 64 bits of precision)]\n",
397 | "diam(a) => BigFloat[3.50450808677922118438e-02,2.33633872451948081421e-02]\n",
398 | "k += 1 => 5\n",
399 | "a => "
400 | ]
401 | },
402 | {
403 | "output_type": "stream",
404 | "stream": "stdout",
405 | "text": [
406 | "[Interval(5.06163960096364962984e-02 with 64 bits of precision,7.46470082780863032913e-02 with 64 bits of precision),Interval(7.5023532781460910133e-01 with 64 bits of precision,7.66255735993575639675e-01 with 64 bits of precision)]\n",
407 | "diam(a) => BigFloat[2.40306122684498069929e-02,1.60204081789665383454e-02]\n",
408 | "k += 1 => 6\n",
409 | "a => [Interval(5.69532489844786834348e-02 with 64 bits of precision,6.83186691336819782751e-02 with 64 bits of precision),Interval(7.54454220577545318048e-01 with 64 bits of precision,7.62031167343680848375e-01 with 64 bits of precision)]\n",
410 | "diam(a) => BigFloat[1.13654201492032948403e-02,7.57694676613553032719e-03]\n",
411 | "k += 1 => 7\n",
412 | "a => [Interval(6.13793095773444506483e-02 with 64 bits of precision,6.3892608842076667713e-02 with 64 bits of precision),Interval(7.57404927438615525144e-01 with 64 bits of precision,7.59080460281770336714e-01 with 64 bits of precision)]\n",
413 | "diam(a) => BigFloat[2.51329926473221706469e-03,1.67553284315481157071e-03]\n",
414 | "k += 1 => 8\n",
415 | "a => [Interval(6.25749570475021556183e-02 with 64 bits of precision,6.26969613719402846155e-02 with 64 bits of precision),Interval(7.58202025752039780542e-01 with 64 bits of precision,7.58283361968331866775e-01 with 64 bits of precision)]\n",
416 | "diam(a) => BigFloat[1.22004324438128997207e-04,8.13362162920862330484e-05]\n",
417 | "k += 1 => 9\n",
418 | "a => "
419 | ]
420 | },
421 | {
422 | "output_type": "stream",
423 | "stream": "stdout",
424 | "text": [
425 | "[Interval(6.26358157579486172535e-02 with 64 bits of precision,6.26361026614938229531e-02 with 64 bits of precision),Interval(7.58242598225670755047e-01 with 64 bits of precision,7.58242789494700892487e-01 with 64 bits of precision)]\n",
426 | "diam(a) => BigFloat[2.8690354520569962514e-07,1.91269030137440274042e-07]\n",
427 | "Unique zero in [Interval(6.26359592089280223205e-02 with 64 bits of precision,6.26359592105144178929e-02 with 64 bits of precision),Interval(7.58242693859657025137e-01 with 64 bits of precision,7.58242693860714622343e-01 with 64 bits of precision)]\n"
428 | ]
429 | },
430 | {
431 | "metadata": {},
432 | "output_type": "pyout",
433 | "prompt_number": 13,
434 | "text": [
435 | "1-element Array{Array{Interval,1},1}:\n",
436 | " [Interval(6.26359592089280223205e-02 with 64 bits of precision,6.26359592105144178929e-02 with 64 bits of precision),Interval(7.58242693859657025137e-01 with 64 bits of precision,7.58242693860714622343e-01 with 64 bits of precision)]"
437 | ]
438 | }
439 | ],
440 | "prompt_number": 13
441 | },
442 | {
443 | "cell_type": "markdown",
444 | "metadata": {},
445 | "source": [
446 | "Increasing the first interval destroys the root finding capability, and the second one in this example doesn't seem to affect it."
447 | ]
448 | }
449 | ],
450 | "metadata": {}
451 | }
452 | ]
453 | }
--------------------------------------------------------------------------------
/.ipynb_checkpoints/krawczyk2d-examples-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "metadata": {
3 | "language": "Julia",
4 | "name": ""
5 | },
6 | "nbformat": 3,
7 | "nbformat_minor": 0,
8 | "worksheets": [
9 | {
10 | "cells": [
11 | {
12 | "cell_type": "code",
13 | "collapsed": false,
14 | "input": [
15 | "# Krawczyk 2D actually works, but when the intervals are large, it stalls"
16 | ],
17 | "language": "python",
18 | "metadata": {},
19 | "outputs": [],
20 | "prompt_number": 1
21 | },
22 | {
23 | "cell_type": "code",
24 | "collapsed": false,
25 | "input": [
26 | "include(\"krawczyk2d.jl\")"
27 | ],
28 | "language": "python",
29 | "metadata": {},
30 | "outputs": [
31 | {
32 | "metadata": {},
33 | "output_type": "pyout",
34 | "prompt_number": 6,
35 | "text": [
36 | "krawczyk2d (generic function with 2 methods)"
37 | ]
38 | }
39 | ],
40 | "prompt_number": 6
41 | },
42 | {
43 | "cell_type": "code",
44 | "collapsed": false,
45 | "input": [
46 | "f(x) = [x[1]^2 + x[2]^2 - 1, x[1] - x[2]^2]"
47 | ],
48 | "language": "python",
49 | "metadata": {},
50 | "outputs": [
51 | {
52 | "metadata": {},
53 | "output_type": "pyout",
54 | "prompt_number": 3,
55 | "text": [
56 | "f (generic function with 1 method)"
57 | ]
58 | }
59 | ],
60 | "prompt_number": 3
61 | },
62 | {
63 | "cell_type": "code",
64 | "collapsed": false,
65 | "input": [
66 | "a = [Interval(0.5, 0.8), Interval(0.6, 0.9)]"
67 | ],
68 | "language": "python",
69 | "metadata": {},
70 | "outputs": [
71 | {
72 | "metadata": {},
73 | "output_type": "pyout",
74 | "prompt_number": 4,
75 | "text": [
76 | "2-element Array{Interval,1}:\n",
77 | " Interval(5e-01 with 256 bits of precision,8.000000000000000000000000000000000000000000000000000000000000000000000000000017e-01 with 256 bits of precision) \n",
78 | " Interval(5.999999999999999999999999999999999999999999999999999999999999999999999999999948e-01 with 256 bits of precision,9.000000000000000000000000000000000000000000000000000000000000000000000000000052e-01 with 256 bits of precision)"
79 | ]
80 | }
81 | ],
82 | "prompt_number": 4
83 | },
84 | {
85 | "cell_type": "code",
86 | "collapsed": false,
87 | "input": [
88 | "krawczyk2d(f, a)"
89 | ],
90 | "language": "python",
91 | "metadata": {},
92 | "outputs": [
93 | {
94 | "output_type": "stream",
95 | "stream": "stdout",
96 | "text": [
97 | "a => [Interval(5e-01 with 256 bits of precision,8.000000000000000000000000000000000000000000000000000000000000000000000000000017e-01 with 256 bits of precision),Interval(5.999999999999999999999999999999999999999999999999999999999999999999999999999948e-01 with 256 bits of precision,9.000000000000000000000000000000000000000000000000000000000000000000000000000052e-01 with 256 bits of precision)]"
98 | ]
99 | },
100 | {
101 | "output_type": "stream",
102 | "stream": "stdout",
103 | "text": [
104 | "\n",
105 | "diam(a) => BigFloat[3.00000000000000000011e-01,3.00000000000000000011e-01]\n",
106 | "a => [Interval(5.59782608695652173609e-01 with 64 bits of precision,6.77173913043478261232e-01 with 64 bits of precision),Interval(7.44275362318840579489e-01 with 64 bits of precision,8.30362318840579710351e-01 with 64 bits of precision)]\n",
107 | "diam(a) => BigFloat[1.17391304347826087623e-01,8.60869565217391308621e-02]\n",
108 | "k += 1 => 3\n",
109 | "a => [Interval(6.11640871255334431689e-01 with 64 bits of precision,6.2442728271432796749e-01 with 64 bits of precision),Interval(7.81842914150279365824e-01 with 64 bits of precision,7.90461684587798984547e-01 with 64 bits of precision)]\n",
110 | "diam(a) => BigFloat[1.27864114589935358012e-02,8.61877043751961872346e-03]\n",
111 | "k += 1 => 4\n",
112 | "a => [Interval(6.17961699100631085921e-01 with 64 bits of precision,6.18106278469247463888e-01 with 64 bits of precision),Interval(7.86096586748077572548e-01 with 64 bits of precision,7.86206171543394608436e-01 with 64 bits of precision)]\n",
113 | "diam(a) => BigFloat[1.44579368616377967102e-04,1.09584795317035888461e-04]\n",
114 | "k += 1 => 5\n",
115 | "a => [Interval(6.18033978705287749924e-01 with 64 bits of precision,6.18033998794501946436e-01 with 64 bits of precision),Interval(7.8615137096578607801e-01 with 64 bits of precision,7.86151384549060496562e-01 with 64 bits of precision)]\n",
116 | "diam(a) => BigFloat[2.00892141965125677061e-08,1.35832744185522893976e-08]\n",
117 | "Unique zero in [Interval(6.18033988749894675277e-01 with 64 bits of precision,6.18033988749895021029e-01 with 64 bits of precision),Interval(7.86151377757423169867e-01 with 64 bits of precision,7.86151377757423402211e-01 with 64 bits of precision)]"
118 | ]
119 | },
120 | {
121 | "output_type": "stream",
122 | "stream": "stdout",
123 | "text": [
124 | "\n"
125 | ]
126 | },
127 | {
128 | "metadata": {},
129 | "output_type": "pyout",
130 | "prompt_number": 6,
131 | "text": [
132 | "1-element Array{Array{Interval,1},1}:\n",
133 | " [Interval(6.18033988749894675277e-01 with 64 bits of precision,6.18033988749895021029e-01 with 64 bits of precision),Interval(7.86151377757423169867e-01 with 64 bits of precision,7.86151377757423402211e-01 with 64 bits of precision)]"
134 | ]
135 | }
136 | ],
137 | "prompt_number": 6
138 | },
139 | {
140 | "cell_type": "code",
141 | "collapsed": false,
142 | "input": [
143 | "# Works. Now let's increase starting intervals"
144 | ],
145 | "language": "python",
146 | "metadata": {},
147 | "outputs": [],
148 | "prompt_number": 7
149 | },
150 | {
151 | "cell_type": "code",
152 | "collapsed": false,
153 | "input": [
154 | "a = [Interval(0, 2), Interval(0, 2)]"
155 | ],
156 | "language": "python",
157 | "metadata": {},
158 | "outputs": [
159 | {
160 | "metadata": {},
161 | "output_type": "pyout",
162 | "prompt_number": 8,
163 | "text": [
164 | "2-element Array{Interval,1}:\n",
165 | " Interval(0e+00 with 64 bits of precision,2e+00 with 64 bits of precision)\n",
166 | " Interval(0e+00 with 64 bits of precision,2e+00 with 64 bits of precision)"
167 | ]
168 | }
169 | ],
170 | "prompt_number": 8
171 | },
172 | {
173 | "cell_type": "code",
174 | "collapsed": false,
175 | "input": [
176 | "# This will set the algorithm into an infinite loop."
177 | ],
178 | "language": "python",
179 | "metadata": {},
180 | "outputs": [],
181 | "prompt_number": 1
182 | },
183 | {
184 | "cell_type": "code",
185 | "collapsed": false,
186 | "input": [
187 | "# Let's see the next example: it actually does find the roots, but when the intervals are very small"
188 | ],
189 | "language": "python",
190 | "metadata": {},
191 | "outputs": [],
192 | "prompt_number": 2
193 | },
194 | {
195 | "cell_type": "code",
196 | "collapsed": false,
197 | "input": [
198 | "f(x) = [20 - 20x[1] - x[2], x[1] - x[2]/20 - 1e-9*exp(x[2]/0.052)]"
199 | ],
200 | "language": "python",
201 | "metadata": {},
202 | "outputs": [
203 | {
204 | "metadata": {},
205 | "output_type": "pyout",
206 | "prompt_number": 3,
207 | "text": [
208 | "f (generic function with 1 method)"
209 | ]
210 | }
211 | ],
212 | "prompt_number": 3
213 | },
214 | {
215 | "cell_type": "code",
216 | "collapsed": false,
217 | "input": [
218 | "# trueroots = [0.9464142468335176, 1.0717150633296477]"
219 | ],
220 | "language": "python",
221 | "metadata": {},
222 | "outputs": [],
223 | "prompt_number": 4
224 | },
225 | {
226 | "cell_type": "code",
227 | "collapsed": false,
228 | "input": [
229 | "a = [Interval(0.94, 0.95), Interval(1.05, 1.08)]"
230 | ],
231 | "language": "python",
232 | "metadata": {},
233 | "outputs": [
234 | {
235 | "metadata": {},
236 | "output_type": "pyout",
237 | "prompt_number": 7,
238 | "text": [
239 | "2-element Array{Interval,1}:\n",
240 | " Interval(9.399999999999999999999999999999999999999999999999999999999999999999999999999927e-01 with 256 bits of precision,9.500000000000000000000000000000000000000000000000000000000000000000000000000069e-01 with 256 bits of precision)\n",
241 | " Interval(1.049999999999999999999999999999999999999999999999999999999999999999999999999993e+00 with 256 bits of precision,1.08000000000000000000000000000000000000000000000000000000000000000000000000001e+00 with 256 bits of precision) "
242 | ]
243 | }
244 | ],
245 | "prompt_number": 7
246 | },
247 | {
248 | "cell_type": "code",
249 | "collapsed": false,
250 | "input": [
251 | "krawczyk2d(f, a)"
252 | ],
253 | "language": "python",
254 | "metadata": {},
255 | "outputs": [
256 | {
257 | "output_type": "stream",
258 | "stream": "stdout",
259 | "text": [
260 | "a => [Interval(9.399999999999999999999999999999999999999999999999999999999999999999999999999927e-01 with 256 bits of precision,9.500000000000000000000000000000000000000000000000000000000000000000000000000069e-01 with 256 bits of precision),Interval(1.049999999999999999999999999999999999999999999999999999999999999999999999999993e+00 with 256 bits of precision,1.08000000000000000000000000000000000000000000000000000000000000000000000000001e+00 with 256 bits of precision)]"
261 | ]
262 | },
263 | {
264 | "output_type": "stream",
265 | "stream": "stdout",
266 | "text": [
267 | "\n",
268 | "diam(a) => BigFloat[1.00000000000000000006e-02,3.00000000000000000011e-02]\n",
269 | "a => [Interval(9.46142624135044351362e-01 with 64 bits of precision,9.4664088171185997489e-01 with 64 bits of precision),Interval(1.06718236576280050654e+00 with 64 bits of precision,1.07714751729911297124e+00 with 64 bits of precision)]\n",
270 | "diam(a) => BigFloat[4.98257576815623528122e-04,9.96515153631246470775e-03]\n",
271 | "k += 1 => 3\n",
272 | "a => [Interval(9.46389241901565050083e-01 with 64 bits of precision,9.46439058833313800773e-01 with 64 bits of precision),Interval(1.07121882333372398627e+00 with 64 bits of precision,1.07221516196869899313e+00 with 64 bits of precision)]\n",
273 | "diam(a) => BigFloat[4.98169317487506899816e-05,9.96338634975006860739e-04]\n",
274 | "k += 1 => 4\n",
275 | "a => [Interval(9.46413799486205053785e-01 with 64 bits of precision,9.46414692531945470576e-01 with 64 bits of precision),Interval(1.07170614936109058989e+00 with 64 bits of precision,1.07172401027589892007e+00 with 64 bits of precision)]\n",
276 | "diam(a) => BigFloat[8.93045740416791109656e-07,1.78609148083301843418e-05]\n",
277 | "k += 1 => 5\n",
278 | "a => [Interval(9.46414246757269344147e-01 with 64 bits of precision,9.46414246909765635783e-01 with 64 bits of precision),Interval(1.07171506180468728607e+00 with 64 bits of precision,1.07171506485461311684e+00 with 64 bits of precision)]\n",
279 | "diam(a) => BigFloat[1.5249629163605060711e-10,3.04992583076944823173e-09]\n",
280 | "Unique zero in [Interval(9.46414246833517617413e-01 with 64 bits of precision,9.46414246833517622346e-01 with 64 bits of precision),Interval(1.07171506332964755785e+00 with 64 bits of precision,1.0717150633296476474e+00 with 64 bits of precision)]"
281 | ]
282 | },
283 | {
284 | "output_type": "stream",
285 | "stream": "stdout",
286 | "text": [
287 | "\n"
288 | ]
289 | },
290 | {
291 | "metadata": {},
292 | "output_type": "pyout",
293 | "prompt_number": 8,
294 | "text": [
295 | "1-element Array{Array{Interval,1},1}:\n",
296 | " [Interval(9.46414246833517617413e-01 with 64 bits of precision,9.46414246833517622346e-01 with 64 bits of precision),Interval(1.07171506332964755785e+00 with 64 bits of precision,1.0717150633296476474e+00 with 64 bits of precision)]"
297 | ]
298 | }
299 | ],
300 | "prompt_number": 8
301 | },
302 | {
303 | "cell_type": "code",
304 | "collapsed": false,
305 | "input": [
306 | "# In the next function it finds the root, but only when it is closely surrounded by a starting interval"
307 | ],
308 | "language": "python",
309 | "metadata": {},
310 | "outputs": [],
311 | "prompt_number": 9
312 | },
313 | {
314 | "cell_type": "code",
315 | "collapsed": false,
316 | "input": [
317 | "f(x) = [0.5*(-(17.76x[1] - 103.79x[1]^2 + 229.62x[1]^3 - 226.31x[1]^4 + 83.72x[1]^5) + x[2]), 0.2*(-x[1] - 1.5x[2] + 1.2)]"
318 | ],
319 | "language": "python",
320 | "metadata": {},
321 | "outputs": [
322 | {
323 | "metadata": {},
324 | "output_type": "pyout",
325 | "prompt_number": 10,
326 | "text": [
327 | "f (generic function with 1 method)"
328 | ]
329 | }
330 | ],
331 | "prompt_number": 10
332 | },
333 | {
334 | "cell_type": "code",
335 | "collapsed": false,
336 | "input": [
337 | "# trueroots = [0.06263595920972119, 0.758242693860186]\n",
338 | "# trueroots = [0.8844295888702942, 0.21038027408647064]\n",
339 | "# trueroots = [0.2853687241300338, 0.6097541839133109]"
340 | ],
341 | "language": "python",
342 | "metadata": {},
343 | "outputs": [],
344 | "prompt_number": 11
345 | },
346 | {
347 | "cell_type": "code",
348 | "collapsed": false,
349 | "input": [
350 | "a = [Interval(0.05, 0.1), Interval(-100, 100)]"
351 | ],
352 | "language": "python",
353 | "metadata": {},
354 | "outputs": [
355 | {
356 | "metadata": {},
357 | "output_type": "pyout",
358 | "prompt_number": 12,
359 | "text": [
360 | "2-element Array{Interval,1}:\n",
361 | " Interval(4.99999999999999999973e-02 with 64 bits of precision,1.00000000000000000001e-01 with 64 bits of precision)\n",
362 | " Interval(-1e+02 with 64 bits of precision,1e+02 with 64 bits of precision) "
363 | ]
364 | }
365 | ],
366 | "prompt_number": 12
367 | },
368 | {
369 | "cell_type": "code",
370 | "collapsed": false,
371 | "input": [
372 | "krawczyk2d(f, a)"
373 | ],
374 | "language": "python",
375 | "metadata": {},
376 | "outputs": [
377 | {
378 | "output_type": "stream",
379 | "stream": "stdout",
380 | "text": [
381 | "a => [Interval(4.99999999999999999973e-02 with 64 bits of precision,1.00000000000000000001e-01 with 64 bits of precision),Interval(-1e+02 with 64 bits of precision,1e+02 with 64 bits of precision)]"
382 | ]
383 | },
384 | {
385 | "output_type": "stream",
386 | "stream": "stdout",
387 | "text": [
388 | "\n",
389 | "diam(a) => BigFloat[5.00000000000000000041e-02,2e+02]\n",
390 | "a => [Interval(4.99999999999999999973e-02 with 64 bits of precision,9.4550344742341260653e-02 with 64 bits of precision),Interval(7.36966436838439141379e-01 with 64 bits of precision,7.81488500003341015883e-01 with 64 bits of precision)]\n",
391 | "diam(a) => BigFloat[4.45503447423412606557e-02,4.4522063164901874504e-02]\n",
392 | "k += 1 => 3\n",
393 | "a => [Interval(4.99999999999999999973e-02 with 64 bits of precision,8.65160934538207583382e-02 with 64 bits of precision),Interval(7.42322604364119464221e-01 with 64 bits of precision,7.75318412680682777062e-01 with 64 bits of precision)]\n",
394 | "diam(a) => BigFloat[3.65160934538207583409e-02,3.29958083165633128415e-02]\n",
395 | "k += 1 => 4\n",
396 | "a => [Interval(4.43949064835282951901e-02 with 64 bits of precision,7.94399873513205070338e-02 with 64 bits of precision),Interval(7.47040008432452965479e-01 with 64 bits of precision,7.70403395677647773621e-01 with 64 bits of precision)]\n",
397 | "diam(a) => BigFloat[3.50450808677922118438e-02,2.33633872451948081421e-02]\n",
398 | "k += 1 => 5\n",
399 | "a => "
400 | ]
401 | },
402 | {
403 | "output_type": "stream",
404 | "stream": "stdout",
405 | "text": [
406 | "[Interval(5.06163960096364962984e-02 with 64 bits of precision,7.46470082780863032913e-02 with 64 bits of precision),Interval(7.5023532781460910133e-01 with 64 bits of precision,7.66255735993575639675e-01 with 64 bits of precision)]\n",
407 | "diam(a) => BigFloat[2.40306122684498069929e-02,1.60204081789665383454e-02]\n",
408 | "k += 1 => 6\n",
409 | "a => [Interval(5.69532489844786834348e-02 with 64 bits of precision,6.83186691336819782751e-02 with 64 bits of precision),Interval(7.54454220577545318048e-01 with 64 bits of precision,7.62031167343680848375e-01 with 64 bits of precision)]\n",
410 | "diam(a) => BigFloat[1.13654201492032948403e-02,7.57694676613553032719e-03]\n",
411 | "k += 1 => 7\n",
412 | "a => [Interval(6.13793095773444506483e-02 with 64 bits of precision,6.3892608842076667713e-02 with 64 bits of precision),Interval(7.57404927438615525144e-01 with 64 bits of precision,7.59080460281770336714e-01 with 64 bits of precision)]\n",
413 | "diam(a) => BigFloat[2.51329926473221706469e-03,1.67553284315481157071e-03]\n",
414 | "k += 1 => 8\n",
415 | "a => [Interval(6.25749570475021556183e-02 with 64 bits of precision,6.26969613719402846155e-02 with 64 bits of precision),Interval(7.58202025752039780542e-01 with 64 bits of precision,7.58283361968331866775e-01 with 64 bits of precision)]\n",
416 | "diam(a) => BigFloat[1.22004324438128997207e-04,8.13362162920862330484e-05]\n",
417 | "k += 1 => 9\n",
418 | "a => "
419 | ]
420 | },
421 | {
422 | "output_type": "stream",
423 | "stream": "stdout",
424 | "text": [
425 | "[Interval(6.26358157579486172535e-02 with 64 bits of precision,6.26361026614938229531e-02 with 64 bits of precision),Interval(7.58242598225670755047e-01 with 64 bits of precision,7.58242789494700892487e-01 with 64 bits of precision)]\n",
426 | "diam(a) => BigFloat[2.8690354520569962514e-07,1.91269030137440274042e-07]\n",
427 | "Unique zero in [Interval(6.26359592089280223205e-02 with 64 bits of precision,6.26359592105144178929e-02 with 64 bits of precision),Interval(7.58242693859657025137e-01 with 64 bits of precision,7.58242693860714622343e-01 with 64 bits of precision)]\n"
428 | ]
429 | },
430 | {
431 | "metadata": {},
432 | "output_type": "pyout",
433 | "prompt_number": 13,
434 | "text": [
435 | "1-element Array{Array{Interval,1},1}:\n",
436 | " [Interval(6.26359592089280223205e-02 with 64 bits of precision,6.26359592105144178929e-02 with 64 bits of precision),Interval(7.58242693859657025137e-01 with 64 bits of precision,7.58242693860714622343e-01 with 64 bits of precision)]"
437 | ]
438 | }
439 | ],
440 | "prompt_number": 13
441 | },
442 | {
443 | "cell_type": "markdown",
444 | "metadata": {},
445 | "source": [
446 | "Increasing the first interval destroys the root finding capability, and the second one in this example doesn't seem to affect it."
447 | ]
448 | }
449 | ],
450 | "metadata": {}
451 | }
452 | ]
453 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/newton2d-examples.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "metadata": {
3 | "language": "Julia",
4 | "name": "",
5 | "signature": "sha256:f5659f10e8db0fe182f61bd8e6d5925f7ae80cbdbf66d269a920e00eb03518df"
6 | },
7 | "nbformat": 3,
8 | "nbformat_minor": 0,
9 | "worksheets": [
10 | {
11 | "cells": [
12 | {
13 | "cell_type": "code",
14 | "collapsed": false,
15 | "input": [
16 | "include(\"newton2d.jl\")"
17 | ],
18 | "language": "python",
19 | "metadata": {},
20 | "outputs": [
21 | {
22 | "metadata": {},
23 | "output_type": "pyout",
24 | "prompt_number": 1,
25 | "text": [
26 | "newton2d (generic function with 2 methods)"
27 | ]
28 | }
29 | ],
30 | "prompt_number": 1
31 | },
32 | {
33 | "cell_type": "code",
34 | "collapsed": false,
35 | "input": [
36 | "f(x) = [x[1]^2 + x[2]^2 - 1, x[1] - x[2]^2]"
37 | ],
38 | "language": "python",
39 | "metadata": {},
40 | "outputs": [
41 | {
42 | "metadata": {},
43 | "output_type": "pyout",
44 | "prompt_number": 2,
45 | "text": [
46 | "f (generic function with 1 method)"
47 | ]
48 | }
49 | ],
50 | "prompt_number": 2
51 | },
52 | {
53 | "cell_type": "code",
54 | "collapsed": false,
55 | "input": [
56 | "a = [Interval(0.5, 0.8), Interval(0.6, 0.9)]"
57 | ],
58 | "language": "python",
59 | "metadata": {},
60 | "outputs": [
61 | {
62 | "metadata": {},
63 | "output_type": "pyout",
64 | "prompt_number": 3,
65 | "text": [
66 | "2-element Array{Interval,1}:\n",
67 | " Interval(5e-01 with 256 bits of precision,8.000000000000000000000000000000000000000000000000000000000000000000000000000017e-01 with 256 bits of precision) \n",
68 | " Interval(5.999999999999999999999999999999999999999999999999999999999999999999999999999948e-01 with 256 bits of precision,9.000000000000000000000000000000000000000000000000000000000000000000000000000052e-01 with 256 bits of precision)"
69 | ]
70 | }
71 | ],
72 | "prompt_number": 3
73 | },
74 | {
75 | "cell_type": "code",
76 | "collapsed": false,
77 | "input": [
78 | "roots = newton2d(f, a, 64)"
79 | ],
80 | "language": "python",
81 | "metadata": {},
82 | "outputs": [
83 | {
84 | "output_type": "stream",
85 | "stream": "stdout",
86 | "text": [
87 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(5.69951923076923076632e-01 with 64 bits of precision,6.43645833333333333595e-01 with 64 bits of precision),Interval(7.76909722222222222138e-01 with 64 bits of precision,8.02564102564102564328e-01 with 64 bits of precision)]]"
88 | ]
89 | },
90 | {
91 | "output_type": "stream",
92 | "stream": "stdout",
93 | "text": [
94 | "\n",
95 | "roots_array = roots_array_new => [[Interval(5.69951923076923076632e-01 with 64 bits of precision,6.43645833333333333595e-01 with 64 bits of precision),Interval(7.76909722222222222138e-01 with 64 bits of precision,8.02564102564102564328e-01 with 64 bits of precision)]]\n",
96 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(6.16649962609692997909e-01 with 64 bits of precision,6.19676057175074426167e-01 with 64 bits of precision),Interval(7.85711856788002042517e-01 with 64 bits of precision,7.86710356930029978083e-01 with 64 bits of precision)]]\n",
97 | "roots_array = roots_array_new => [[Interval(6.16649962609692997909e-01 with 64 bits of precision,6.19676057175074426167e-01 with 64 bits of precision),Interval(7.85711856788002042517e-01 with 64 bits of precision,7.86710356930029978083e-01 with 64 bits of precision)]]\n",
98 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(6.18033201420526032209e-01 with 64 bits of precision,6.18034789347726672202e-01 with 64 bits of precision),Interval(7.86151061673094964761e-01 with 64 bits of precision,7.86151706419289133176e-01 with 64 bits of precision)]]\n",
99 | "roots_array = roots_array_new => [[Interval(6.18033201420526032209e-01 with 64 bits of precision,6.18034789347726672202e-01 with 64 bits of precision),Interval(7.86151061673094964761e-01 with 64 bits of precision,7.86151706419289133176e-01 with 64 bits of precision)]]\n",
100 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(6.18033988749863042703e-01 with 64 bits of precision,6.18033988749926693068e-01 with 64 bits of precision),Interval(7.86151377757410522269e-01 with 64 bits of precision,7.86151377757436125161e-01 with 64 bits of precision)]]\n",
101 | "roots_array = roots_array_new => [[Interval(6.18033988749863042703e-01 with 64 bits of precision,6.18033988749926693068e-01 with 64 bits of precision),Interval(7.86151377757410522269e-01 with 64 bits of precision,7.86151377757436125161e-01 with 64 bits of precision)]]\n",
102 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(6.18033988749894848045e-01 with 64 bits of precision,6.18033988749894848424e-01 with 64 bits of precision),Interval(7.86151377757423285931e-01 with 64 bits of precision,7.8615137775742328631e-01 with 64 bits of precision)]]\n",
103 | "roots_array = roots_array_new => [[Interval(6.18033988749894848045e-01 with 64 bits of precision,6.18033988749894848424e-01 with 64 bits of precision),Interval(7.86151377757423285931e-01 with 64 bits of precision,7.8615137775742328631e-01 with 64 bits of precision)]]\n",
104 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(6.18033988749894848045e-01 with 64 bits of precision,6.18033988749894848424e-01 with 64 bits of precision),Interval(7.86151377757423285931e-01 with 64 bits of precision,7.8615137775742328631e-01 with 64 bits of precision)]]\n",
105 | "Function calls: 5\n"
106 | ]
107 | },
108 | {
109 | "metadata": {},
110 | "output_type": "pyout",
111 | "prompt_number": 5,
112 | "text": [
113 | "1-element Array{Array{Interval,1},1}:\n",
114 | " [Interval(6.18033988749894848045e-01 with 64 bits of precision,6.18033988749894848424e-01 with 64 bits of precision),Interval(7.86151377757423285931e-01 with 64 bits of precision,7.8615137775742328631e-01 with 64 bits of precision)]"
115 | ]
116 | }
117 | ],
118 | "prompt_number": 5
119 | },
120 | {
121 | "cell_type": "code",
122 | "collapsed": false,
123 | "input": [
124 | "f(roots[1])"
125 | ],
126 | "language": "python",
127 | "metadata": {},
128 | "outputs": [
129 | {
130 | "metadata": {},
131 | "output_type": "pyout",
132 | "prompt_number": 7,
133 | "text": [
134 | "2-element Array{Interval,1}:\n",
135 | " Interval(-5.42101086242752217051e-19 with 64 bits of precision,8.673617379884035473e-19 with 64 bits of precision) \n",
136 | " Interval(-5.96311194867027438704e-19 with 64 bits of precision,4.87890977618476995303e-19 with 64 bits of precision)"
137 | ]
138 | }
139 | ],
140 | "prompt_number": 7
141 | },
142 | {
143 | "cell_type": "code",
144 | "collapsed": false,
145 | "input": [
146 | "# Works."
147 | ],
148 | "language": "python",
149 | "metadata": {},
150 | "outputs": [],
151 | "prompt_number": 5
152 | },
153 | {
154 | "cell_type": "code",
155 | "collapsed": false,
156 | "input": [
157 | "# 2nd example from Moore book"
158 | ],
159 | "language": "python",
160 | "metadata": {},
161 | "outputs": [],
162 | "prompt_number": 6
163 | },
164 | {
165 | "cell_type": "code",
166 | "collapsed": false,
167 | "input": [
168 | "f(x) = [20 - 20x[1] - x[2], x[1] - x[2]/20 - 1e-9*exp(x[2]/0.052)]"
169 | ],
170 | "language": "python",
171 | "metadata": {},
172 | "outputs": [
173 | {
174 | "metadata": {},
175 | "output_type": "pyout",
176 | "prompt_number": 8,
177 | "text": [
178 | "f (generic function with 1 method)"
179 | ]
180 | }
181 | ],
182 | "prompt_number": 8
183 | },
184 | {
185 | "cell_type": "code",
186 | "collapsed": false,
187 | "input": [
188 | "a = [Interval(0.5, 1.2), Interval(0.6, 1.2)]"
189 | ],
190 | "language": "python",
191 | "metadata": {},
192 | "outputs": [
193 | {
194 | "metadata": {},
195 | "output_type": "pyout",
196 | "prompt_number": 9,
197 | "text": [
198 | "2-element Array{Interval,1}:\n",
199 | " Interval(5e-01 with 64 bits of precision,1.20000000000000000004e+00 with 64 bits of precision) \n",
200 | " Interval(5.99999999999999999967e-01 with 64 bits of precision,1.20000000000000000004e+00 with 64 bits of precision)"
201 | ]
202 | }
203 | ],
204 | "prompt_number": 9
205 | },
206 | {
207 | "cell_type": "code",
208 | "collapsed": false,
209 | "input": [
210 | "roots = newton2d(f, a, 64)"
211 | ],
212 | "language": "python",
213 | "metadata": {},
214 | "outputs": [
215 | {
216 | "output_type": "stream",
217 | "stream": "stdout",
218 | "text": [
219 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(5.24913596541994085176e-01 with 64 bits of precision,9.54783404920287672335e-01 with 64 bits of precision),Interval(9.04331901594246556598e-01 with 64 bits of precision,1.20000000000000000004e+00 with 64 bits of precision)]]"
220 | ]
221 | },
222 | {
223 | "output_type": "stream",
224 | "stream": "stdout",
225 | "text": [
226 | "\n",
227 | "roots_array = roots_array_new => [[Interval(5.24913596541994085176e-01 with 64 bits of precision,9.54783404920287672335e-01 with 64 bits of precision),Interval(9.04331901594246556598e-01 with 64 bits of precision,1.20000000000000000004e+00 with 64 bits of precision)]]\n",
228 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(9.29487402579674734042e-01 with 64 bits of precision,9.47322133828186144428e-01 with 64 bits of precision),Interval(1.05355732343627711643e+00 with 64 bits of precision,1.20000000000000000004e+00 with 64 bits of precision)]]\n",
229 | "roots_array = roots_array_new => [[Interval(9.29487402579674734042e-01 with 64 bits of precision,9.47322133828186144428e-01 with 64 bits of precision),Interval(1.05355732343627711643e+00 with 64 bits of precision,1.20000000000000000004e+00 with 64 bits of precision)]]\n",
230 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(9.4405739404211960064e-01 with 64 bits of precision,9.47322133828186144428e-01 with 64 bits of precision),Interval(1.05355732343627711643e+00 with 64 bits of precision,1.11885211915760798037e+00 with 64 bits of precision)]]\n",
231 | "roots_array = roots_array_new => [[Interval(9.4405739404211960064e-01 with 64 bits of precision,9.47322133828186144428e-01 with 64 bits of precision),Interval(1.05355732343627711643e+00 with 64 bits of precision,1.11885211915760798037e+00 with 64 bits of precision)]]\n",
232 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(9.46028161295262554455e-01 with 64 bits of precision,9.46870644360673580542e-01 with 64 bits of precision),Interval(1.06258711278652839491e+00 with 64 bits of precision,1.07943677409474890645e+00 with 64 bits of precision)]]\n",
233 | "roots_array = roots_array_new => [[Interval(9.46028161295262554455e-01 with 64 bits of precision,9.46870644360673580542e-01 with 64 bits of precision),Interval(1.06258711278652839491e+00 with 64 bits of precision,1.07943677409474890645e+00 with 64 bits of precision)]]\n",
234 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(9.46407827444742915182e-01 with 64 bits of precision,9.46419276900890626275e-01 with 64 bits of precision),Interval(1.07161446198218747721e+00 with 64 bits of precision,1.07184345110514169289e+00 with 64 bits of precision)]]\n",
235 | "roots_array = roots_array_new => [[Interval(9.46407827444742915182e-01 with 64 bits of precision,9.46419276900890626275e-01 with 64 bits of precision),Interval(1.07161446198218747721e+00 with 64 bits of precision,1.07184345110514169289e+00 with 64 bits of precision)]]\n",
236 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(9.46414245222457044325e-01 with 64 bits of precision,9.46414248263380555859e-01 with 64 bits of precision),Interval(1.07171503473238888629e+00 with 64 bits of precision,1.07171509555085910917e+00 with 64 bits of precision)]]\n",
237 | "roots_array = roots_array_new => [[Interval(9.46414245222457044325e-01 with 64 bits of precision,9.46414248263380555859e-01 with 64 bits of precision),Interval(1.07171503473238888629e+00 with 64 bits of precision,1.07171509555085910917e+00 with 64 bits of precision)]]\n",
238 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(9.46414246833517562878e-01 with 64 bits of precision,9.46414246833517668533e-01 with 64 bits of precision),Interval(1.07171506332964663205e+00 with 64 bits of precision,1.07171506332964873995e+00 with 64 bits of precision)]]\n",
239 | "roots_array = roots_array_new => [[Interval(9.46414246833517562878e-01 with 64 bits of precision,9.46414246833517668533e-01 with 64 bits of precision),Interval(1.07171506332964663205e+00 with 64 bits of precision,1.07171506332964873995e+00 with 64 bits of precision)]]\n",
240 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(9.46414246833517617088e-01 with 64 bits of precision,9.46414246833517617467e-01 with 64 bits of precision),Interval(1.07171506332964765413e+00 with 64 bits of precision,1.07171506332964765488e+00 with 64 bits of precision)]]\n",
241 | "roots_array = roots_array_new => [[Interval(9.46414246833517617088e-01 with 64 bits of precision,9.46414246833517617467e-01 with 64 bits of precision),Interval(1.07171506332964765413e+00 with 64 bits of precision,1.07171506332964765488e+00 with 64 bits of precision)]]\n",
242 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(9.46414246833517617142e-01 with 64 bits of precision,9.46414246833517617467e-01 with 64 bits of precision),Interval(1.07171506332964765413e+00 with 64 bits of precision,1.07171506332964765488e+00 with 64 bits of precision)]]\n",
243 | "roots_array = roots_array_new => [[Interval(9.46414246833517617142e-01 with 64 bits of precision,9.46414246833517617467e-01 with 64 bits of precision),Interval(1.07171506332964765413e+00 with 64 bits of precision,1.07171506332964765488e+00 with 64 bits of precision)]]\n",
244 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(9.46414246833517617142e-01 with 64 bits of precision,9.46414246833517617467e-01 with 64 bits of precision),Interval(1.07171506332964765413e+00 with 64 bits of precision,1.07171506332964765488e+00 with 64 bits of precision)]]\n",
245 | "Function calls: 9\n"
246 | ]
247 | },
248 | {
249 | "metadata": {},
250 | "output_type": "pyout",
251 | "prompt_number": 11,
252 | "text": [
253 | "1-element Array{Array{Interval,1},1}:\n",
254 | " [Interval(9.46414246833517617142e-01 with 64 bits of precision,9.46414246833517617467e-01 with 64 bits of precision),Interval(1.07171506332964765413e+00 with 64 bits of precision,1.07171506332964765488e+00 with 64 bits of precision)]"
255 | ]
256 | }
257 | ],
258 | "prompt_number": 11
259 | },
260 | {
261 | "cell_type": "code",
262 | "collapsed": false,
263 | "input": [
264 | "f(ans[1])"
265 | ],
266 | "language": "python",
267 | "metadata": {},
268 | "outputs": [
269 | {
270 | "metadata": {},
271 | "output_type": "pyout",
272 | "prompt_number": 12,
273 | "text": [
274 | "2-element Array{Interval,1}:\n",
275 | " Interval(-6.39679281766447616064e-18 with 64 bits of precision,4.87890977618476995303e-18 with 64 bits of precision)\n",
276 | " Interval(-8.83624770575686113716e-18 with 64 bits of precision,1.20888542232133744399e-17 with 64 bits of precision)"
277 | ]
278 | }
279 | ],
280 | "prompt_number": 12
281 | },
282 | {
283 | "cell_type": "code",
284 | "collapsed": false,
285 | "input": [
286 | "# Works. Krawczyk2d is not yet capable of doing this on such an interval (only on a tiny one)"
287 | ],
288 | "language": "python",
289 | "metadata": {},
290 | "outputs": [],
291 | "prompt_number": 10
292 | },
293 | {
294 | "cell_type": "code",
295 | "collapsed": false,
296 | "input": [
297 | "# 3rd example from Moore"
298 | ],
299 | "language": "python",
300 | "metadata": {},
301 | "outputs": [],
302 | "prompt_number": 11
303 | },
304 | {
305 | "cell_type": "heading",
306 | "level": 2,
307 | "metadata": {},
308 | "source": [
309 | "Complicated case with 3 zeros:"
310 | ]
311 | },
312 | {
313 | "cell_type": "code",
314 | "collapsed": false,
315 | "input": [
316 | "f(x) = [0.5*(-(17.76x[1] - 103.79x[1]^2 + 229.62x[1]^3 - 226.31x[1]^4 + 83.72x[1]^5) + x[2]), 0.2*(-x[1] - 1.5x[2] + 1.2)]"
317 | ],
318 | "language": "python",
319 | "metadata": {},
320 | "outputs": [
321 | {
322 | "metadata": {},
323 | "output_type": "pyout",
324 | "prompt_number": 61,
325 | "text": [
326 | "f (generic function with 1 method)"
327 | ]
328 | }
329 | ],
330 | "prompt_number": 61
331 | },
332 | {
333 | "cell_type": "heading",
334 | "level": 3,
335 | "metadata": {},
336 | "source": [
337 | "True zeros:"
338 | ]
339 | },
340 | {
341 | "cell_type": "markdown",
342 | "metadata": {},
343 | "source": [
344 | "There are three real roots: {x1 -> 0.062636, x2 -> 0.758243}, {x1 -> 0.88443, x2 -> 0.21038}, {x1 -> 0.285369, x2 -> 0.609754}"
345 | ]
346 | },
347 | {
348 | "cell_type": "code",
349 | "collapsed": false,
350 | "input": [
351 | "a = [Interval(0.01, 5), Interval(0.1, 5)]"
352 | ],
353 | "language": "python",
354 | "metadata": {},
355 | "outputs": [
356 | {
357 | "metadata": {},
358 | "output_type": "pyout",
359 | "prompt_number": 62,
360 | "text": [
361 | "2-element Array{Interval,1}:\n",
362 | " Interval(9.9999999999999999998e-03 with 64 bits of precision,5e+00 with 64 bits of precision) \n",
363 | " Interval(9.99999999999999999946e-02 with 64 bits of precision,5e+00 with 64 bits of precision)"
364 | ]
365 | }
366 | ],
367 | "prompt_number": 62
368 | },
369 | {
370 | "cell_type": "code",
371 | "collapsed": false,
372 | "input": [
373 | "newton2d(f, a, 64)"
374 | ],
375 | "language": "python",
376 | "metadata": {},
377 | "outputs": [
378 | {
379 | "output_type": "stream",
380 | "stream": "stdout",
381 | "text": [
382 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(9.9999999999999999998e-03 with 64 bits of precision,2.52558389946483697317e+00 with 64 bits of precision),Interval(9.99999999999999999946e-02 with 64 bits of precision,5e+00 with 64 bits of precision)]]"
383 | ]
384 | },
385 | {
386 | "output_type": "stream",
387 | "stream": "stdout",
388 | "text": [
389 | "\n",
390 | "roots_array = roots_array_new => [[Interval(9.9999999999999999998e-03 with 64 bits of precision,2.52558389946483697317e+00 with 64 bits of precision),Interval(9.99999999999999999946e-02 with 64 bits of precision,5e+00 with 64 bits of precision)]]\n",
391 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(9.9999999999999999998e-03 with 64 bits of precision,1.2686662376273644769e+00 with 64 bits of precision),Interval(9.99999999999999999946e-02 with 64 bits of precision,5e+00 with 64 bits of precision)]]\n",
392 | "roots_array = roots_array_new => [[Interval(9.9999999999999999998e-03 with 64 bits of precision,1.2686662376273644769e+00 with 64 bits of precision),Interval(9.99999999999999999946e-02 with 64 bits of precision,5e+00 with 64 bits of precision)]]\n",
393 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(9.9999999999999999998e-03 with 64 bits of precision,6.41495905915175664469e-01 with 64 bits of precision),Interval(3.72336062723216222939e-01 with 64 bits of precision,4.84710334659612871984e+00 with 64 bits of precision)]]\n",
394 | "roots_array = roots_array_new => [[Interval(9.9999999999999999998e-03 with 64 bits of precision,6.41495905915175664469e-01 with 64 bits of precision),Interval(3.72336062723216222939e-01 with 64 bits of precision,4.84710334659612871984e+00 with 64 bits of precision)]]\n",
395 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(9.9999999999999999998e-03 with 64 bits of precision,3.37257266081398510295e-01 with 64 bits of precision),Interval(5.75161822612400992316e-01 with 64 bits of precision,4.73470830452635709981e+00 with 64 bits of precision)]]\n",
396 | "roots_array = roots_array_new => [[Interval(9.9999999999999999998e-03 with 64 bits of precision,3.37257266081398510295e-01 with 64 bits of precision),Interval(5.75161822612400992316e-01 with 64 bits of precision,4.73470830452635709981e+00 with 64 bits of precision)]]\n",
397 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(9.9999999999999999998e-03 with 64 bits of precision,2.13368376853307920932e-01 with 64 bits of precision),Interval(6.57754415431128052253e-01 with 64 bits of precision,4.73470830452635709981e+00 with 64 bits of precision)]]\n",
398 | "roots_array = roots_array_new => [[Interval(9.9999999999999999998e-03 with 64 bits of precision,2.13368376853307920932e-01 with 64 bits of precision),Interval(6.57754415431128052253e-01 with 64 bits of precision,4.73470830452635709981e+00 with 64 bits of precision)]]\n",
399 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(9.9999999999999999998e-03 with 64 bits of precision,2.0409028710522643644e-01 with 64 bits of precision),Interval(6.63939808596515708319e-01 with 64 bits of precision,4.73470830452635709981e+00 with 64 bits of precision)]]\n",
400 | "roots_array = roots_array_new => [[Interval(9.9999999999999999998e-03 with 64 bits of precision,2.0409028710522643644e-01 with 64 bits of precision),Interval(6.63939808596515708319e-01 with 64 bits of precision,4.73470830452635709981e+00 with 64 bits of precision)]]\n",
401 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => "
402 | ]
403 | },
404 | {
405 | "output_type": "stream",
406 | "stream": "stdout",
407 | "text": [
408 | "[[Interval(9.9999999999999999998e-03 with 64 bits of precision,2.0409028710522643644e-01 with 64 bits of precision),Interval(6.63939808596515708319e-01 with 64 bits of precision,4.73470830452635709981e+00 with 64 bits of precision)]]\n",
409 | "Function calls: 6\n"
410 | ]
411 | },
412 | {
413 | "metadata": {},
414 | "output_type": "pyout",
415 | "prompt_number": 63,
416 | "text": [
417 | "1-element Array{Array{Interval,1},1}:\n",
418 | " [Interval(9.9999999999999999998e-03 with 64 bits of precision,2.0409028710522643644e-01 with 64 bits of precision),Interval(6.63939808596515708319e-01 with 64 bits of precision,4.73470830452635709981e+00 with 64 bits of precision)]"
419 | ]
420 | }
421 | ],
422 | "prompt_number": 63
423 | },
424 | {
425 | "cell_type": "code",
426 | "collapsed": false,
427 | "input": [
428 | "# Works. Another interval:"
429 | ],
430 | "language": "python",
431 | "metadata": {},
432 | "outputs": [],
433 | "prompt_number": 15
434 | },
435 | {
436 | "cell_type": "code",
437 | "collapsed": false,
438 | "input": [
439 | "a = [Interval(0.7, 0.9), Interval(0.1, 0.3)]"
440 | ],
441 | "language": "python",
442 | "metadata": {},
443 | "outputs": [
444 | {
445 | "metadata": {},
446 | "output_type": "pyout",
447 | "prompt_number": 20,
448 | "text": [
449 | "2-element Array{Interval,1}:\n",
450 | " Interval(6.99999999999999999989e-01 with 64 bits of precision,9.00000000000000000033e-01 with 64 bits of precision)\n",
451 | " Interval(9.99999999999999999946e-02 with 64 bits of precision,3.00000000000000000011e-01 with 64 bits of precision)"
452 | ]
453 | }
454 | ],
455 | "prompt_number": 20
456 | },
457 | {
458 | "cell_type": "code",
459 | "collapsed": false,
460 | "input": [
461 | "newton2d(f, a, 64)"
462 | ],
463 | "language": "python",
464 | "metadata": {},
465 | "outputs": [
466 | {
467 | "output_type": "stream",
468 | "stream": "stdout",
469 | "text": [
470 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(7.99533569108615181306e-01 with 64 bits of precision,9.00000000000000000087e-01 with 64 bits of precision),Interval(1.32402716810851698009e-01 with 64 bits of precision,2.66977620594256545897e-01 with 64 bits of precision)]]"
471 | ]
472 | },
473 | {
474 | "output_type": "stream",
475 | "stream": "stdout",
476 | "text": [
477 | "\n",
478 | "roots_array = roots_array_new => [[Interval(7.99533569108615181306e-01 with 64 bits of precision,9.00000000000000000087e-01 with 64 bits of precision),Interval(1.32402716810851698009e-01 with 64 bits of precision,2.66977620594256545897e-01 with 64 bits of precision)]]\n",
479 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(8.49310448278202196964e-01 with 64 bits of precision,9.00000000000000000141e-01 with 64 bits of precision),Interval(1.64941883459212836004e-01 with 64 bits of precision,2.33793034481198535481e-01 with 64 bits of precision)]]\n",
480 | "roots_array = roots_array_new => [[Interval(8.49310448278202196964e-01 with 64 bits of precision,9.00000000000000000141e-01 with 64 bits of precision),Interval(1.64941883459212836004e-01 with 64 bits of precision,2.33793034481198535481e-01 with 64 bits of precision)]]\n",
481 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(8.74368868193437198753e-01 with 64 bits of precision,9.00000000000000000195e-01 with 64 bits of precision),Interval(1.80847351067254425328e-01 with 64 bits of precision,2.17087421204375200919e-01 with 64 bits of precision)]]\n",
482 | "roots_array = roots_array_new => [[Interval(8.74368868193437198753e-01 with 64 bits of precision,9.00000000000000000195e-01 with 64 bits of precision),Interval(1.80847351067254425328e-01 with 64 bits of precision,2.17087421204375200919e-01 with 64 bits of precision)]]\n",
483 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(8.86713661126687165365e-01 with 64 bits of precision,9.00000000000000000195e-01 with 64 bits of precision),Interval(1.88028751271188605487e-01 with 64 bits of precision,2.08857559248875223218e-01 with 64 bits of precision)]]\n",
484 | "roots_array = roots_array_new => [[Interval(8.86713661126687165365e-01 with 64 bits of precision,9.00000000000000000195e-01 with 64 bits of precision),Interval(1.88028751271188605487e-01 with 64 bits of precision,2.08857559248875223218e-01 with 64 bits of precision)]]\n",
485 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(8.92042290862508345105e-01 with 64 bits of precision,9.00000000000000000195e-01 with 64 bits of precision),Interval(1.89953354713197845736e-01 with 64 bits of precision,2.05305139424994436743e-01 with 64 bits of precision)]]\n",
486 | "roots_array = roots_array_new => [[Interval(8.92042290862508345105e-01 with 64 bits of precision,9.00000000000000000195e-01 with 64 bits of precision),Interval(1.89953354713197845736e-01 with 64 bits of precision,2.05305139424994436743e-01 with 64 bits of precision)]]\n",
487 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(8.93576641696621274086e-01 with 64 bits of precision,9.00000000000000000195e-01 with 64 bits of precision),Interval(1.89953354713197845736e-01 with 64 bits of precision,2.04282238868919150697e-01 with 64 bits of precision)]]\n",
488 | "roots_array = roots_array_new => [[Interval(8.93576641696621274086e-01 with 64 bits of precision,9.00000000000000000195e-01 with 64 bits of precision),Interval(1.89953354713197845736e-01 with 64 bits of precision,2.04282238868919150697e-01 with 64 bits of precision)]]\n",
489 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(8.93683850490391404895e-01 with 64 bits of precision,9.00000000000000000195e-01 with 64 bits of precision),Interval(1.89953354713197845736e-01 with 64 bits of precision,2.04210766339739063622e-01 with 64 bits of precision)]]\n",
490 | "roots_array = roots_array_new => [[Interval(8.93683850490391404895e-01 with 64 bits of precision,9.00000000000000000195e-01 with 64 bits of precision),Interval(1.89953354713197845736e-01 with 64 bits of precision,2.04210766339739063622e-01 with 64 bits of precision)]]\n",
491 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(8.93683850490391404895e-01 with 64 bits of precision,9.00000000000000000195e-01 with 64 bits of precision),Interval(1.89953354713197845736e-01 with 64 bits of precision,2.04210766339739063622e-01 with 64 bits of precision)]]\n",
492 | "Function calls: 7\n"
493 | ]
494 | },
495 | {
496 | "metadata": {},
497 | "output_type": "pyout",
498 | "prompt_number": 21,
499 | "text": [
500 | "1-element Array{Array{Interval,1},1}:\n",
501 | " [Interval(8.93683850490391404895e-01 with 64 bits of precision,9.00000000000000000195e-01 with 64 bits of precision),Interval(1.89953354713197845736e-01 with 64 bits of precision,2.04210766339739063622e-01 with 64 bits of precision)]"
502 | ]
503 | }
504 | ],
505 | "prompt_number": 21
506 | },
507 | {
508 | "cell_type": "code",
509 | "collapsed": false,
510 | "input": [
511 | "# For some reason, the intervals are still relatively large"
512 | ],
513 | "language": "python",
514 | "metadata": {},
515 | "outputs": [],
516 | "prompt_number": 18
517 | },
518 | {
519 | "cell_type": "code",
520 | "collapsed": false,
521 | "input": [
522 | "a = [Interval(0.11, 0.3), Interval(0.5, 0.69)]"
523 | ],
524 | "language": "python",
525 | "metadata": {},
526 | "outputs": [
527 | {
528 | "metadata": {},
529 | "output_type": "pyout",
530 | "prompt_number": 13,
531 | "text": [
532 | "2-element Array{Interval,1}:\n",
533 | " Interval(1.09999999999999999999e-01 with 64 bits of precision,3.00000000000000000011e-01 with 64 bits of precision)\n",
534 | " Interval(5e-01 with 64 bits of precision,6.90000000000000000052e-01 with 64 bits of precision) "
535 | ]
536 | }
537 | ],
538 | "prompt_number": 13
539 | },
540 | {
541 | "cell_type": "code",
542 | "collapsed": false,
543 | "input": [
544 | "newton2d(f, a, 64)"
545 | ],
546 | "language": "python",
547 | "metadata": {},
548 | "outputs": [
549 | {
550 | "output_type": "stream",
551 | "stream": "stdout",
552 | "text": [
553 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(1.98959862448933060819e-01 with 64 bits of precision,3.00000000000000000038e-01 with 64 bits of precision),Interval(5.22511857040455090476e-01 with 64 bits of precision,6.67360091700711293024e-01 with 64 bits of precision)]]"
554 | ]
555 | },
556 | {
557 | "output_type": "stream",
558 | "stream": "stdout",
559 | "text": [
560 | "\n",
561 | "roots_array = roots_array_new => [[Interval(1.98959862448933060819e-01 with 64 bits of precision,3.00000000000000000038e-01 with 64 bits of precision),Interval(5.22511857040455090476e-01 with 64 bits of precision,6.67360091700711293024e-01 with 64 bits of precision)]]\n",
562 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(2.44405284093183400559e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.47605281726672503634e-01 with 64 bits of precision,6.37063143937877733179e-01 with 64 bits of precision)]]\n",
563 | "roots_array = roots_array_new => [[Interval(2.44405284093183400559e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.47605281726672503634e-01 with 64 bits of precision,6.37063143937877733179e-01 with 64 bits of precision)]]\n",
564 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(2.67881780072239415627e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.21412146618507056422e-01 with 64 bits of precision)]]\n",
565 | "roots_array = roots_array_new => [[Interval(2.67881780072239415627e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.21412146618507056422e-01 with 64 bits of precision)]]\n",
566 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(2.8018905070704416428e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.13207299528637223896e-01 with 64 bits of precision)]]\n",
567 | "roots_array = roots_array_new => [[Interval(2.8018905070704416428e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.13207299528637223896e-01 with 64 bits of precision)]]\n",
568 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(2.86802017717913006298e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.08798654854724662804e-01 with 64 bits of precision)]]\n",
569 | "roots_array = roots_array_new => [[Interval(2.86802017717913006298e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.08798654854724662804e-01 with 64 bits of precision)]]\n",
570 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => "
571 | ]
572 | },
573 | {
574 | "output_type": "stream",
575 | "stream": "stdout",
576 | "text": [
577 | "[[Interval(2.90699552997113188816e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.06200298001924541035e-01 with 64 bits of precision)]]\n",
578 | "roots_array = roots_array_new => [[Interval(2.90699552997113188816e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.06200298001924541035e-01 with 64 bits of precision)]]\n",
579 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(2.9119045375552936604e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.05873030829647089444e-01 with 64 bits of precision)]]\n",
580 | "roots_array = roots_array_new => [[Interval(2.9119045375552936604e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.05873030829647089444e-01 with 64 bits of precision)]]\n",
581 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(2.91199878305938713083e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.05866747796040858154e-01 with 64 bits of precision)]]\n",
582 | "roots_array = roots_array_new => [[Interval(2.91199878305938713083e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.05866747796040858154e-01 with 64 bits of precision)]]\n",
583 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(2.91199911011646166213e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.05866725992235889437e-01 with 64 bits of precision)]]\n",
584 | "roots_array = roots_array_new => [[Interval(2.91199911011646166213e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.05866725992235889437e-01 with 64 bits of precision)]]\n",
585 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(2.91199911115097032901e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.05866725923268644924e-01 with 64 bits of precision)]]\n",
586 | "roots_array = roots_array_new => [[Interval(2.91199911115097032901e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.05866725923268644924e-01 with 64 bits of precision)]]\n",
587 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => "
588 | ]
589 | },
590 | {
591 | "output_type": "stream",
592 | "stream": "stdout",
593 | "text": [
594 | "[[Interval(2.91199911115424146346e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.05866725923050569258e-01 with 64 bits of precision)]]\n",
595 | "roots_array = roots_array_new => [[Interval(2.91199911115424146346e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.05866725923050569258e-01 with 64 bits of precision)]]\n",
596 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(2.91199911115425180485e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.05866725923049879868e-01 with 64 bits of precision)]]\n",
597 | "roots_array = roots_array_new => [[Interval(2.91199911115425180485e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.05866725923049879868e-01 with 64 bits of precision)]]\n",
598 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(2.91199911115425183792e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.05866725923049877591e-01 with 64 bits of precision)]]\n",
599 | "roots_array = roots_array_new => [[Interval(2.91199911115425183792e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.05866725923049877591e-01 with 64 bits of precision)]]\n",
600 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(2.91199911115425183792e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.05866725923049877591e-01 with 64 bits of precision)]]\n",
601 | "Function calls: 13\n"
602 | ]
603 | },
604 | {
605 | "metadata": {},
606 | "output_type": "pyout",
607 | "prompt_number": 14,
608 | "text": [
609 | "1-element Array{Array{Interval,1},1}:\n",
610 | " [Interval(2.91199911115425183792e-01 with 64 bits of precision,3.00000000000000000065e-01 with 64 bits of precision),Interval(5.55929366475467126932e-01 with 64 bits of precision,6.05866725923049877591e-01 with 64 bits of precision)]"
611 | ]
612 | }
613 | ],
614 | "prompt_number": 14
615 | },
616 | {
617 | "cell_type": "markdown",
618 | "metadata": {},
619 | "source": []
620 | },
621 | {
622 | "cell_type": "code",
623 | "collapsed": false,
624 | "input": [
625 | "a = [Interval(0.01, 1), Interval(0.01, 1)]"
626 | ],
627 | "language": "python",
628 | "metadata": {},
629 | "outputs": [
630 | {
631 | "metadata": {},
632 | "output_type": "pyout",
633 | "prompt_number": 70,
634 | "text": [
635 | "2-element Array{Interval,1}:\n",
636 | " Interval(9.9999999999999999998e-03 with 64 bits of precision,1e+00 with 64 bits of precision)\n",
637 | " Interval(9.9999999999999999998e-03 with 64 bits of precision,1e+00 with 64 bits of precision)"
638 | ]
639 | }
640 | ],
641 | "prompt_number": 70
642 | },
643 | {
644 | "cell_type": "code",
645 | "collapsed": false,
646 | "input": [
647 | "newton2d(f, a, 64)"
648 | ],
649 | "language": "python",
650 | "metadata": {},
651 | "outputs": [
652 | {
653 | "output_type": "stream",
654 | "stream": "stdout",
655 | "text": [
656 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(3.77986706010765157344e-01 with 64 bits of precision,5.05395803514839542323e-01 with 64 bits of precision),Interval(4.63069464323440305111e-01 with 64 bits of precision,5.48008862659489895115e-01 with 64 bits of precision)]]"
657 | ]
658 | },
659 | {
660 | "output_type": "stream",
661 | "stream": "stdout",
662 | "text": [
663 | "\n",
664 | "roots_array = roots_array_new => [[Interval(3.77986706010765157344e-01 with 64 bits of precision,5.05395803514839542323e-01 with 64 bits of precision),Interval(4.63069464323440305111e-01 with 64 bits of precision,5.48008862659489895115e-01 with 64 bits of precision)]]\n",
665 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(4.38274314608033558981e-01 with 64 bits of precision,4.45181973145152710768e-01 with 64 bits of precision),Interval(5.03212017903231526256e-01 with 64 bits of precision,5.07817123594644293915e-01 with 64 bits of precision)]]\n",
666 | "roots_array = roots_array_new => [[Interval(4.38274314608033558981e-01 with 64 bits of precision,4.45181973145152710768e-01 with 64 bits of precision),Interval(5.03212017903231526256e-01 with 64 bits of precision,5.07817123594644293915e-01 with 64 bits of precision)]]\n",
667 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(4.38274314608033558954e-01 with 64 bits of precision,4.45181973145152710768e-01 with 64 bits of precision),Interval(5.03212017903231526256e-01 with 64 bits of precision,5.07817123594644293915e-01 with 64 bits of precision)]]\n",
668 | "roots_array = roots_array_new => [[Interval(4.38274314608033558954e-01 with 64 bits of precision,4.45181973145152710768e-01 with 64 bits of precision),Interval(5.03212017903231526256e-01 with 64 bits of precision,5.07817123594644293915e-01 with 64 bits of precision)]]\n",
669 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(4.38274314608033558954e-01 with 64 bits of precision,4.45181973145152710768e-01 with 64 bits of precision),Interval(5.03212017903231526256e-01 with 64 bits of precision,5.07817123594644293915e-01 with 64 bits of precision)]]\n",
670 | "Function calls: 3\n"
671 | ]
672 | },
673 | {
674 | "metadata": {},
675 | "output_type": "pyout",
676 | "prompt_number": 71,
677 | "text": [
678 | "1-element Array{Array{Interval,1},1}:\n",
679 | " [Interval(4.38274314608033558954e-01 with 64 bits of precision,4.45181973145152710768e-01 with 64 bits of precision),Interval(5.03212017903231526256e-01 with 64 bits of precision,5.07817123594644293915e-01 with 64 bits of precision)]"
680 | ]
681 | }
682 | ],
683 | "prompt_number": 71
684 | },
685 | {
686 | "cell_type": "code",
687 | "collapsed": false,
688 | "input": [
689 | "# This one looks like a false positive. Why?"
690 | ],
691 | "language": "python",
692 | "metadata": {},
693 | "outputs": [],
694 | "prompt_number": 17
695 | },
696 | {
697 | "cell_type": "code",
698 | "collapsed": false,
699 | "input": [
700 | "sol = newton2d(f, a, 64)"
701 | ],
702 | "language": "python",
703 | "metadata": {},
704 | "outputs": [
705 | {
706 | "output_type": "stream",
707 | "stream": "stdout",
708 | "text": [
709 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(3.77986706010765157344e-01 with 64 bits of precision,5.05395803514839542323e-01 with 64 bits of precision),Interval(4.63069464323440305111e-01 with 64 bits of precision,5.48008862659489895115e-01 with 64 bits of precision)]]"
710 | ]
711 | },
712 | {
713 | "output_type": "stream",
714 | "stream": "stdout",
715 | "text": [
716 | "\n",
717 | "roots_array = roots_array_new => [[Interval(3.77986706010765157344e-01 with 64 bits of precision,5.05395803514839542323e-01 with 64 bits of precision),Interval(4.63069464323440305111e-01 with 64 bits of precision,5.48008862659489895115e-01 with 64 bits of precision)]]\n",
718 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(4.38274314608033558981e-01 with 64 bits of precision,4.45181973145152710768e-01 with 64 bits of precision),Interval(5.03212017903231526256e-01 with 64 bits of precision,5.07817123594644293915e-01 with 64 bits of precision)]]\n",
719 | "roots_array = roots_array_new => [[Interval(4.38274314608033558981e-01 with 64 bits of precision,4.45181973145152710768e-01 with 64 bits of precision),Interval(5.03212017903231526256e-01 with 64 bits of precision,5.07817123594644293915e-01 with 64 bits of precision)]]\n",
720 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(4.38274314608033558954e-01 with 64 bits of precision,4.45181973145152710768e-01 with 64 bits of precision),Interval(5.03212017903231526256e-01 with 64 bits of precision,5.07817123594644293915e-01 with 64 bits of precision)]]\n",
721 | "roots_array = roots_array_new => [[Interval(4.38274314608033558954e-01 with 64 bits of precision,4.45181973145152710768e-01 with 64 bits of precision),Interval(5.03212017903231526256e-01 with 64 bits of precision,5.07817123594644293915e-01 with 64 bits of precision)]]\n",
722 | "roots_array_new = push!(roots_array_new,isectext(roots_array[i],N(roots_array[i]))) => [[Interval(4.38274314608033558954e-01 with 64 bits of precision,4.45181973145152710768e-01 with 64 bits of precision),Interval(5.03212017903231526256e-01 with 64 bits of precision,5.07817123594644293915e-01 with 64 bits of precision)]]\n",
723 | "Function calls: 3\n"
724 | ]
725 | },
726 | {
727 | "metadata": {},
728 | "output_type": "pyout",
729 | "prompt_number": 72,
730 | "text": [
731 | "1-element Array{Array{Interval,1},1}:\n",
732 | " [Interval(4.38274314608033558954e-01 with 64 bits of precision,4.45181973145152710768e-01 with 64 bits of precision),Interval(5.03212017903231526256e-01 with 64 bits of precision,5.07817123594644293915e-01 with 64 bits of precision)]"
733 | ]
734 | }
735 | ],
736 | "prompt_number": 72
737 | },
738 | {
739 | "cell_type": "code",
740 | "collapsed": false,
741 | "input": [
742 | "center(x) = make_intervals(mid(x))\n",
743 | "N(f, x) = center(x) - inv(jacobian(f, x))*f(center(x))"
744 | ],
745 | "language": "python",
746 | "metadata": {},
747 | "outputs": [
748 | {
749 | "metadata": {},
750 | "output_type": "pyout",
751 | "prompt_number": 73,
752 | "text": [
753 | "N (generic function with 1 method)"
754 | ]
755 | }
756 | ],
757 | "prompt_number": 73
758 | },
759 | {
760 | "cell_type": "code",
761 | "collapsed": false,
762 | "input": [
763 | "NNN = N(f, sol[1])"
764 | ],
765 | "language": "python",
766 | "metadata": {},
767 | "outputs": [
768 | {
769 | "metadata": {},
770 | "output_type": "pyout",
771 | "prompt_number": 74,
772 | "text": [
773 | "2-element Array{Interval,1}:\n",
774 | " Interval(3.87637464474657538128e-01 with 64 bits of precision,5.20025515047235507198e-01 with 64 bits of precision)\n",
775 | " Interval(4.5331632330184299542e-01 with 64 bits of precision,5.41575023683561641169e-01 with 64 bits of precision) "
776 | ]
777 | }
778 | ],
779 | "prompt_number": 74
780 | },
781 | {
782 | "cell_type": "code",
783 | "collapsed": false,
784 | "input": [
785 | "inside(sol[1][1], NNN[1])"
786 | ],
787 | "language": "python",
788 | "metadata": {},
789 | "outputs": [
790 | {
791 | "metadata": {},
792 | "output_type": "pyout",
793 | "prompt_number": 34,
794 | "text": [
795 | "true"
796 | ]
797 | }
798 | ],
799 | "prompt_number": 34
800 | },
801 | {
802 | "cell_type": "code",
803 | "collapsed": false,
804 | "input": [
805 | "inside(sol[1][2], NNN[2])"
806 | ],
807 | "language": "python",
808 | "metadata": {},
809 | "outputs": [
810 | {
811 | "metadata": {},
812 | "output_type": "pyout",
813 | "prompt_number": 35,
814 | "text": [
815 | "true"
816 | ]
817 | }
818 | ],
819 | "prompt_number": 35
820 | },
821 | {
822 | "cell_type": "code",
823 | "collapsed": false,
824 | "input": [
825 | "J = jacobian(f, sol[1])"
826 | ],
827 | "language": "python",
828 | "metadata": {},
829 | "outputs": [
830 | {
831 | "metadata": {},
832 | "output_type": "pyout",
833 | "prompt_number": 38,
834 | "text": [
835 | "2x2 Array{Interval,2}:\n",
836 | " Interval(-1.76984841281877910762e+00 with 64 bits of precision,3.37773217687788244361e+00 with 64 bits of precision) \u2026 Interval(5e-01 with 64 bits of precision,5e-01 with 64 bits of precision) \n",
837 | " Interval(-2.00000000000000000016e-01 with 64 bits of precision,-1.99999999999999999976e-01 with 64 bits of precision) Interval(-3.00000000000000000065e-01 with 64 bits of precision,-2.99999999999999999984e-01 with 64 bits of precision)"
838 | ]
839 | }
840 | ],
841 | "prompt_number": 38
842 | },
843 | {
844 | "cell_type": "code",
845 | "collapsed": false,
846 | "input": [
847 | "inv(J)"
848 | ],
849 | "language": "python",
850 | "metadata": {},
851 | "outputs": [
852 | {
853 | "metadata": {},
854 | "output_type": "pyout",
855 | "prompt_number": 39,
856 | "text": [
857 | "2x2 Array{Interval,2}:\n",
858 | " Interval(-4.75470083281939574619e-01 with 64 bits of precision,3.2847207327004322624e-01 with 64 bits of precision) \u2026 Interval(-1.30300529972210691028e+01 with 64 bits of precision,5.4745345545007204264e-01 with 64 bits of precision) \n",
859 | " Interval(-2.18981382180028817362e-01 with 64 bits of precision,3.16980055521293049565e-01 with 64 bits of precision) Interval(-3.69830230363338136068e+00 with 64 bits of precision,5.35336866481404606349e+00 with 64 bits of precision)"
860 | ]
861 | }
862 | ],
863 | "prompt_number": 39
864 | },
865 | {
866 | "cell_type": "code",
867 | "collapsed": false,
868 | "input": [
869 | "left(x::Interval) = Interval(x.lo, mid(x))\n",
870 | "right(x::Interval) = Interval(mid(x), x.hi)\n",
871 | "\n",
872 | "\n",
873 | "function bisect(xx::Vector{Interval})\n",
874 | " \n",
875 | " if length(xx) != 2\n",
876 | " error(\"Only works for 2 at the moment\")\n",
877 | " end\n",
878 | " \n",
879 | " x, y = xx\n",
880 | " \n",
881 | " @show x\n",
882 | " \n",
883 | " intervals = Vector{Interval}[]\n",
884 | " \n",
885 | " push!(intervals, [left(x), left(y)])\n",
886 | " push!(intervals, [left(x), right(y)])\n",
887 | " push!(intervals, [right(x), left(y)])\n",
888 | " push!(intervals, [right(x), right(y)])\n",
889 | " \n",
890 | " intervals\n",
891 | "end"
892 | ],
893 | "language": "python",
894 | "metadata": {},
895 | "outputs": [
896 | {
897 | "metadata": {},
898 | "output_type": "pyout",
899 | "prompt_number": 75,
900 | "text": [
901 | "bisect (generic function with 1 method)"
902 | ]
903 | }
904 | ],
905 | "prompt_number": 75
906 | },
907 | {
908 | "cell_type": "code",
909 | "collapsed": false,
910 | "input": [
911 | "x = sol[1]"
912 | ],
913 | "language": "python",
914 | "metadata": {},
915 | "outputs": [
916 | {
917 | "metadata": {},
918 | "output_type": "pyout",
919 | "prompt_number": 76,
920 | "text": [
921 | "2-element Array{Interval,1}:\n",
922 | " Interval(4.38274314608033558954e-01 with 64 bits of precision,4.45181973145152710768e-01 with 64 bits of precision)\n",
923 | " Interval(5.03212017903231526256e-01 with 64 bits of precision,5.07817123594644293915e-01 with 64 bits of precision)"
924 | ]
925 | }
926 | ],
927 | "prompt_number": 76
928 | },
929 | {
930 | "cell_type": "code",
931 | "collapsed": false,
932 | "input": [
933 | "y = bisect(x)"
934 | ],
935 | "language": "python",
936 | "metadata": {},
937 | "outputs": [
938 | {
939 | "output_type": "stream",
940 | "stream": "stdout",
941 | "text": [
942 | "x => Interval(4.38274314608033558954e-01 with 64 bits of precision,4.45181973145152710768e-01 with 64 bits of precision)"
943 | ]
944 | },
945 | {
946 | "output_type": "stream",
947 | "stream": "stdout",
948 | "text": [
949 | "\n"
950 | ]
951 | },
952 | {
953 | "metadata": {},
954 | "output_type": "pyout",
955 | "prompt_number": 78,
956 | "text": [
957 | "4-element Array{Array{Interval,1},1}:\n",
958 | " [Interval(4.38274314608033558954e-01 with 64 bits of precision,4.41728143876593134902e-01 with 64 bits of precision),Interval(5.03212017903231526256e-01 with 64 bits of precision,5.05514570748937910167e-01 with 64 bits of precision)]\n",
959 | " [Interval(4.38274314608033558954e-01 with 64 bits of precision,4.41728143876593134902e-01 with 64 bits of precision),Interval(5.05514570748937910113e-01 with 64 bits of precision,5.07817123594644293915e-01 with 64 bits of precision)]\n",
960 | " [Interval(4.41728143876593134875e-01 with 64 bits of precision,4.45181973145152710768e-01 with 64 bits of precision),Interval(5.03212017903231526256e-01 with 64 bits of precision,5.05514570748937910167e-01 with 64 bits of precision)]\n",
961 | " [Interval(4.41728143876593134875e-01 with 64 bits of precision,4.45181973145152710768e-01 with 64 bits of precision),Interval(5.05514570748937910113e-01 with 64 bits of precision,5.07817123594644293915e-01 with 64 bits of precision)]"
962 | ]
963 | }
964 | ],
965 | "prompt_number": 78
966 | },
967 | {
968 | "cell_type": "code",
969 | "collapsed": false,
970 | "input": [
971 | "import Base.show\n",
972 | "show(io::IO, x::Interval) = print(io, \"[$(round(float(x.lo), 5)), $(x.hi)]\")"
973 | ],
974 | "language": "python",
975 | "metadata": {},
976 | "outputs": [
977 | {
978 | "metadata": {},
979 | "output_type": "pyout",
980 | "prompt_number": 53,
981 | "text": [
982 | "show (generic function with 90 methods)"
983 | ]
984 | }
985 | ],
986 | "prompt_number": 53
987 | },
988 | {
989 | "cell_type": "code",
990 | "collapsed": false,
991 | "input": [
992 | "y = bisect(x)\n",
993 | "after_newton = [N(f,x) for x in y]"
994 | ],
995 | "language": "python",
996 | "metadata": {},
997 | "outputs": [
998 | {
999 | "output_type": "stream",
1000 | "stream": "stdout",
1001 | "text": [
1002 | "x => Interval(4.38274314608033558954e-01 with 64 bits of precision,4.45181973145152710768e-01 with 64 bits of precision)"
1003 | ]
1004 | },
1005 | {
1006 | "output_type": "stream",
1007 | "stream": "stdout",
1008 | "text": [
1009 | "\n"
1010 | ]
1011 | },
1012 | {
1013 | "metadata": {},
1014 | "output_type": "pyout",
1015 | "prompt_number": 79,
1016 | "text": [
1017 | "4-element Array{Any,1}:\n",
1018 | " [Interval(3.47097933805788840721e-01 with 64 bits of precision,6.56963251841997641835e-01 with 64 bits of precision),Interval(3.62024498772001572446e-01 with 64 bits of precision,5.68601377462807439783e-01 with 64 bits of precision)]\n",
1019 | " [Interval(3.47097933805788839555e-01 with 64 bits of precision,6.45856424941334515417e-01 with 64 bits of precision),Interval(3.69429050039110323301e-01 with 64 bits of precision,5.68601377462807440108e-01 with 64 bits of precision)]\n",
1020 | " [Interval(3.48964360037304871157e-01 with 64 bits of precision,6.41213649073018553885e-01 with 64 bits of precision),Interval(3.72524233951320964331e-01 with 64 bits of precision,5.67357093308463419131e-01 with 64 bits of precision)]\n",
1021 | " [Interval(3.36248746659157818085e-01 with 64 bits of precision,6.43246950176062365161e-01 with 64 bits of precision),Interval(3.71168699882625089759e-01 with 64 bits of precision,5.75834168893894787701e-01 with 64 bits of precision)]"
1022 | ]
1023 | }
1024 | ],
1025 | "prompt_number": 79
1026 | },
1027 | {
1028 | "cell_type": "code",
1029 | "collapsed": false,
1030 | "input": [
1031 | "display(y[1])\n",
1032 | "display(after_newton[1])"
1033 | ],
1034 | "language": "python",
1035 | "metadata": {},
1036 | "outputs": [
1037 | {
1038 | "metadata": {},
1039 | "output_type": "display_data",
1040 | "text": [
1041 | "2-element Array{Interval,1}:\n",
1042 | " Interval(4.38274314608033558954e-01 with 64 bits of precision,4.41728143876593134902e-01 with 64 bits of precision)\n",
1043 | " Interval(5.03212017903231526256e-01 with 64 bits of precision,5.05514570748937910167e-01 with 64 bits of precision)"
1044 | ]
1045 | },
1046 | {
1047 | "metadata": {},
1048 | "output_type": "display_data",
1049 | "text": [
1050 | "2-element Array{Interval,1}:\n",
1051 | " Interval(3.47097933805788840721e-01 with 64 bits of precision,6.56963251841997641835e-01 with 64 bits of precision)\n",
1052 | " Interval(3.62024498772001572446e-01 with 64 bits of precision,5.68601377462807439783e-01 with 64 bits of precision)"
1053 | ]
1054 | }
1055 | ],
1056 | "prompt_number": 82
1057 | },
1058 | {
1059 | "cell_type": "code",
1060 | "collapsed": false,
1061 | "input": [
1062 | "x"
1063 | ],
1064 | "language": "python",
1065 | "metadata": {},
1066 | "outputs": [
1067 | {
1068 | "metadata": {},
1069 | "output_type": "pyout",
1070 | "prompt_number": 55,
1071 | "text": [
1072 | "2-element Array{Interval,1}:\n",
1073 | " Interval(4.38274314608033558954e-01 with 64 bits of precision,4.45181973145152710768e-01 with 64 bits of precision)\n",
1074 | " Interval(5.03212017903231526256e-01 with 64 bits of precision,5.07817123594644293915e-01 with 64 bits of precision)"
1075 | ]
1076 | }
1077 | ],
1078 | "prompt_number": 55
1079 | },
1080 | {
1081 | "cell_type": "code",
1082 | "collapsed": false,
1083 | "input": [
1084 | "f(x)"
1085 | ],
1086 | "language": "python",
1087 | "metadata": {},
1088 | "outputs": [
1089 | {
1090 | "metadata": {},
1091 | "output_type": "pyout",
1092 | "prompt_number": 83,
1093 | "text": [
1094 | "2-element Array{Interval,1}:\n",
1095 | " Interval(-4.19940929233143423632e-01 with 64 bits of precision,7.49196193356633135163e-01 with 64 bits of precision)\n",
1096 | " Interval(-1.38153170742383035755e-03 with 64 bits of precision,1.38153170742383035755e-03 with 64 bits of precision)"
1097 | ]
1098 | }
1099 | ],
1100 | "prompt_number": 83
1101 | },
1102 | {
1103 | "cell_type": "code",
1104 | "collapsed": false,
1105 | "input": [
1106 | "using NewtonMethod"
1107 | ],
1108 | "language": "python",
1109 | "metadata": {},
1110 | "outputs": [
1111 | {
1112 | "output_type": "stream",
1113 | "stream": "stdout",
1114 | "text": [
1115 | "Syntax: newton(function, Interval(lo, hi), precision [default is 64])\n"
1116 | ]
1117 | }
1118 | ],
1119 | "prompt_number": 84
1120 | },
1121 | {
1122 | "cell_type": "code",
1123 | "collapsed": false,
1124 | "input": [
1125 | "using KrawczykMethod"
1126 | ],
1127 | "language": "python",
1128 | "metadata": {},
1129 | "outputs": [
1130 | {
1131 | "output_type": "stream",
1132 | "stream": "stdout",
1133 | "text": [
1134 | "Syntax: krawczyk(function, Interval(lo, hi), precision [default is 64])\n"
1135 | ]
1136 | }
1137 | ],
1138 | "prompt_number": 85
1139 | },
1140 | {
1141 | "cell_type": "code",
1142 | "collapsed": false,
1143 | "input": [
1144 | " x"
1145 | ],
1146 | "language": "python",
1147 | "metadata": {},
1148 | "outputs": [
1149 | {
1150 | "metadata": {},
1151 | "output_type": "pyout",
1152 | "prompt_number": 86,
1153 | "text": [
1154 | "2-element Array{Interval,1}:\n",
1155 | " Interval(4.38274314608033558954e-01 with 64 bits of precision,4.45181973145152710768e-01 with 64 bits of precision)\n",
1156 | " Interval(5.03212017903231526256e-01 with 64 bits of precision,5.07817123594644293915e-01 with 64 bits of precision)"
1157 | ]
1158 | }
1159 | ],
1160 | "prompt_number": 86
1161 | },
1162 | {
1163 | "cell_type": "code",
1164 | "collapsed": false,
1165 | "input": [],
1166 | "language": "python",
1167 | "metadata": {},
1168 | "outputs": []
1169 | }
1170 | ],
1171 | "metadata": {}
1172 | }
1173 | ]
1174 | }
--------------------------------------------------------------------------------