Information Technology Reference
In-Depth Information
Quiet[
Quiet[
Quiet[
Timing[
Timing[
Timing[
Tab le[NMinimize[
Tab le[NMinimize[ { ( x 2 + y 2
( x 2 + y 2
( x 2 + y 2
z 2 ) 2 ,
z 2 ) 2 ,
z 2 ) 2 ,
Tab le[NMinimize[
{
{
Element[
{
{
{
x , y , z
x , y , z
x , y , z
}
}
}
, Integers] , 5
, Integers] , 5
, Integers] , 5
x
25 , 5
25 , 5
25 , 5
y
25 , 5
25 , 5
25 , 5
z
25 , x
25 , x
25 , x
y
}
}
}
,
,
,
Element[
Element[
x
x
y
y
z
z
y
y
{
{
{
,
Method
x , y , z
x , y , z
x , y , z
}
}
}
,
,
Method
“DifferentialEvolution” , RandomSeed
“DifferentialEvolution” , RandomSeed
“DifferentialEvolution” , RandomSeed
RandomInteger[1000]] ,
RandomInteger[1000]] ,
RandomInteger[1000]] ,
Method
{
{
{
20
20
20
}
} ]]]
} ]]]
]]]
{
17 . 1771 ,
{{
0 .,
{
x
9 , y
12 , z
15
}}
,
{
0 .,
{
x
15 , y
20 , z
25
}}
,
{
0 .,
{
x
6 , y
8 , z
10
}}
,
{
0 .,
{
x
5 , y
12 , z
13
}}
,
{
0 .,
{
x
6 , y
8 , z
10
}}
,
{
0 .,
{
x
7 , y
24 , z
25
}}
,
{
0 .,
{
x
15 , y
20 , z
25
}}
,
{
0 .,
{
x
15 , y
20 , z
25
}}
,
{
0 .,
{
x
15 , y
20 , z
25
}}
,
{
0 .,
{
x
8 , y
15 , z
17
}}
,
{
0 .,
{
x
5 , y
12 , z
13
}}
,
{
0 .,
{
x
9 , y
12 , z
15
}}
,
{
0 .,
{
x
9 , y
12 , z
15
}}
,
{
0 .,
{
x
5 , y
12 , z
13
}}
,
{
0 .,
{
x
6 , y
8 , z
10
}}
,
{
0 .,
{
x
5 , y
12 , z
13
}}
,
{
0 .,
{
x
5 , y
12 , z
13
}}
,
{
0 .,
{
x
5 , y
12 , z
13
}}
,
{
0 .,
{
x
5 , y
12 , z
13
}}
,
{
0 .,
{
x
15 , y
20 , z
25
}}}}
We observe that each of these is a valid Pythagorean triple (of course, there are several
repeats). Recalling our objective function, any failure would appear as a false minimum,
that is to say, a square integer strictly larger than zero.
4.2.1.1 A Coin Problem
We start with a basic coin problem. We are given 143,267 coins in pennies, nickels,
dimes, and quarters, of total value $12563.29, and we are to determine how many coins
might be of each type. There are several ways one might set up such a problem in
NMinimize . We will try to minimize the sum of squares of differences between ac-
tual values and desired values of the two linear expressions implied by the information
above. For our search space we will impose obvious range constraints on the various
coin types. In order to obtain different results we will want to alter the seeding of the
random number generator; this changes the random initial parameters used to seed the
optimization code. That is why we specify the method with this option added. We will
do 10 runs of this.
Timing[Tab le[
Timing[Tab le[
{
{
{
min , sol
min , sol
min , sol
}
}
}
= NMinimize[
= NMinimize[
= NMinimize[
1256329) 2 +( p + n + d + q
143267) 2 ,
1256329) 2 +( p + n + d + q
1256329) 2 +( p + n + d + q
143267) 2 ,
143267) 2 ,
{
{
{
( p + 5 n + 10 d + 25 q
( p + 5 n + 10 d + 25 q
( p + 5 n + 10 d + 25 q
{
p , n , d , q
}∈
Integers , 0
1256329 , 0
1256329 / 5 ,
{
{
p , n , d , q
p , n , d , q
}∈
}∈
Integers , 0
Integers , 0
p
p
p
1256329 , 0
1256329 , 0
n
n
n
1256329 / 5 ,
1256329 / 5 ,
1256329 / 10 , 0
1256329 / 25
}
,
0
0
0
d
d
d
1256329 / 10 , 0
1256329 / 10 , 0
q
q
q
1256329 / 25
1256329 / 25
}
}
,
,
{
p , n , d , q
}
, MaxIterations
1000 ,
{
{
p , n , d , q
p , n , d , q
}
}
, MaxIterations
, MaxIterations
1000 ,
1000 ,
Method
→{
DifferentialEvolution , RandomSeed
Random[Integer , 1000]
}
] ,
Method
Method
→{
→{
DifferentialEvolution , RandomSeed
DifferentialEvolution , RandomSeed
Random[Integer , 1000]
Random[Integer , 1000]
}
}
] ,
] ,
{
10
}
]]
{
{
10
10
}
}
]]
]]
Search WWH ::




Custom Search