In [1]:
# Krawczyk 2D actually works, but when the intervals are large, it stalls

In [6]:
include("krawczyk2d.jl")


Out[6]:
krawczyk2d (generic function with 2 methods)

In [3]:
f(x) = [x[1]^2 + x[2]^2 - 1, x[1] - x[2]^2]


Out[3]:
f (generic function with 1 method)

In [4]:
a = [Interval(0.5, 0.8), Interval(0.6, 0.9)]


Out[4]:
2-element Array{Interval,1}:
 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)

In [6]:
krawczyk2d(f, a)


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)]
diam(a) => BigFloat[3.00000000000000000011e-01,3.00000000000000000011e-01]
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)]
diam(a) => BigFloat[1.17391304347826087623e-01,8.60869565217391308621e-02]
k += 1 => 3
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)]
diam(a) => BigFloat[1.27864114589935358012e-02,8.61877043751961872346e-03]
k += 1 => 4
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)]
diam(a) => BigFloat[1.44579368616377967102e-04,1.09584795317035888461e-04]
k += 1 => 5
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)]
diam(a) => BigFloat[2.00892141965125677061e-08,1.35832744185522893976e-08]
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)]
Out[6]:
1-element Array{Array{Interval,1},1}:
 [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)]

In [7]:
# Works. Now let's increase starting intervals

In [8]:
a = [Interval(0, 2), Interval(0, 2)]


Out[8]:
2-element Array{Interval,1}:
 Interval(0e+00 with 64 bits of precision,2e+00 with 64 bits of precision)
 Interval(0e+00 with 64 bits of precision,2e+00 with 64 bits of precision)

In [1]:
# This will set the algorithm into an infinite loop.

In [2]:
# Let's see the next example: it actually does find the roots, but when the intervals are very small

In [3]:
f(x) = [20 - 20x[1] - x[2], x[1] - x[2]/20 - 1e-9*exp(x[2]/0.052)]


Out[3]:
f (generic function with 1 method)

In [4]:
# trueroots = [0.9464142468335176, 1.0717150633296477]

In [7]:
a = [Interval(0.94, 0.95), Interval(1.05, 1.08)]


Out[7]:
2-element Array{Interval,1}:
 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) 

In [8]:
krawczyk2d(f, a)


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)]
diam(a) => BigFloat[1.00000000000000000006e-02,3.00000000000000000011e-02]
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)]
diam(a) => BigFloat[4.98257576815623528122e-04,9.96515153631246470775e-03]
k += 1 => 3
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)]
diam(a) => BigFloat[4.98169317487506899816e-05,9.96338634975006860739e-04]
k += 1 => 4
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)]
diam(a) => BigFloat[8.93045740416791109656e-07,1.78609148083301843418e-05]
k += 1 => 5
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)]
diam(a) => BigFloat[1.5249629163605060711e-10,3.04992583076944823173e-09]
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)]
Out[8]:
1-element Array{Array{Interval,1},1}:
 [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)]

In [9]:
# In the next function it finds the root, but only when it is closely surrounded by a starting interval

In [10]:
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)]


Out[10]:
f (generic function with 1 method)

In [11]:
# trueroots = [0.06263595920972119, 0.758242693860186]
# trueroots = [0.8844295888702942, 0.21038027408647064]
# trueroots = [0.2853687241300338, 0.6097541839133109]

In [12]:
a = [Interval(0.05, 0.1), Interval(-100, 100)]


Out[12]:
2-element Array{Interval,1}:
 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)                                         

In [13]:
krawczyk2d(f, a)


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)]
diam(a) => BigFloat[5.00000000000000000041e-02,2e+02]
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)]
diam(a) => BigFloat[4.45503447423412606557e-02,4.4522063164901874504e-02]
k += 1 => 3
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)]
diam(a) => BigFloat[3.65160934538207583409e-02,3.29958083165633128415e-02]
k += 1 => 4
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)]
diam(a) => BigFloat[3.50450808677922118438e-02,2.33633872451948081421e-02]
k += 1 => 5
a => [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)]
diam(a) => BigFloat[2.40306122684498069929e-02,1.60204081789665383454e-02]
k += 1 => 6
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)]
diam(a) => BigFloat[1.13654201492032948403e-02,7.57694676613553032719e-03]
k += 1 => 7
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)]
diam(a) => BigFloat[2.51329926473221706469e-03,1.67553284315481157071e-03]
k += 1 => 8
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)]
diam(a) => BigFloat[1.22004324438128997207e-04,8.13362162920862330484e-05]
k += 1 => 9
a => [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)]
diam(a) => BigFloat[2.8690354520569962514e-07,1.91269030137440274042e-07]
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)]
Out[13]:
1-element Array{Array{Interval,1},1}:
 [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)]

Increasing the first interval destroys the root finding capability, and the second one in this example doesn't seem to affect it.