NO IMAGE

檢視完整程式碼請點選http://www.daimapi.com/algorithm3_2/

程式碼利用Python3實現。

# -*- coding: utf-8 -*-
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
import math # 定義目標函式
def aimFunction(x):
y = x**3-60*x**2-4*x 6
return y
x = [i/10 for i in range(1000)]
y = [0 for i in range(1000)]
for i in range(1000):
y[i] = aimFunction(x[i])
plt.plot(x, y)
T = 1000 # 初始化溫度
Tmin = 10 # 溫度最小值
x = np.random.uniform(low=0, high=100) # 初始化x
k = 50 # 內迴圈次數
y = 0 # 初始化結果
t = 0 # 迭代次數