fix(Griewank): don't pass 0 in sqrt
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
leo 2023-02-09 22:03:18 +01:00
parent 4af5b9ca1c
commit 2b56f6e6c6
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ

@ -70,7 +70,8 @@ func Griewank(x []float64) float64 {
for i := range x { for i := range x {
sum += math.Pow(x[i], 2) / 4000 sum += math.Pow(x[i], 2) / 4000
prod -= math.Cos(x[i] / math.Sqrt(float64(i))) // use i+1 in sqrt so that we don't get Nan.
prod *= math.Cos(x[i] / math.Sqrt(float64(i+1)))
} }
return sum - prod + 1 return sum - prod + 1