Exemplo n.º 1
0
import numpy as np

def func(x):
	return -abs(np.sin(x[0])*np.cos(x[1])*np.exp(abs(1-np.sqrt(x[0]**2+x[1]**2)/np.pi)))

def gfunc(x):
	return (func(x+0.001)-func(x))/0.001

if __name__ == "__main__":
        import sys
        sys.path.append('../')
        from tool.plot import plot3d
        plot3d(func, np.array([-5.0, 5.0]), np.array([5.12, 5.12]))
	#print func(np.array([8.05502, 9.66459]))
Exemplo n.º 2
0
import numpy as np


def func(x):
    return -(x[1]+47.0)*np.sin(np.sqrt(abs(0.5*x[0]+x[1]+47.0)))\
       -x[0]*np.sin(np.sqrt(abs(x[0]-(x[1]+47.0))))


def gfunc(x):
    return (func(x + 0.001) - func(x)) / 0.001


if __name__ == "__main__":
    import sys
    sys.path.append('../')
    from tool.plot import plot3d
    #print func(np.array([512.0,404.2319]))
    plot3d(func, np.array([-10, -10]), np.array([10, 10]))
Exemplo n.º 3
0
#!coding=utf-8
import numpy as np

A = 10.0


def func(x):
    sum = 0.0
    n = x.shape[0]
    for i in range(n):
        sum += (x[i]**2 - A * np.cos(2 * np.pi * x[i]))
    return A * n + sum


def gfunc(x):
    return 2 * x + A * 2 * np.pi * np.sin(x)


if __name__ == "__main__":
    import sys
    sys.path.append('../')
    from tool.plot import plot3d
    plot3d(func, np.array([9, 13]), np.array([17, 20]))
#print rastrigin(np.array([[1.0, 0.0], [3.0,0.0]]))
Exemplo n.º 4
0
import numpy as np


def func(x):
    sum = 0.0
    n = x.shape[0]
    for i in range(n - 1):
        sum += (100 * (x[i + 1] - x[i]**2)**2 + (1 - x[i])**2)

    return sum


def gfunc(x):
    return (func(x + 0.001) - func(x)) / 0.001


if __name__ == "__main__":
    import sys
    sys.path.append('../')
    from tool.plot import plot3d
    plot3d(func, np.array([-2, -2]), np.array([2, 3]))