To solve the minimization problem using the simulated annealing method, you need to iterate through different temperatures and update the current guess based on the acceptance probability. Here's a Python code snippet that implements the simulated annealing algorithm for your function:
import random
import math
def E(x):
return x**4 - 3*x**3 - 15*x - 4
def acceptance_probability(delta_E, temperature):
if delta_E < 0:
return 1.0
return math.exp(-delta_E / temperature)
def minimize_simulated_annealing():
temperature = 100
current_guess = random.uniform(0, 10)
current_energy = E(current_guess)
print("Initial guess:", current_guess)
print("Initial energy:", current_energy)
for temp in range(100, 0, -10):
print("\nTemperature:", temp)
temperature = temp
for iteration in range(1, 6):
new_guess = random.uniform(0, 10)
new_energy = E(new_guess)
delta_energy = new_energy - current_energy
acceptance_prob = acceptance_probability(delta_energy, temperature)
print("Iteration:", iteration)
print("Current guess:", current_guess)
print("Current energy:", current_energy)
print("New guess:", new_guess)
print("New energy:", new_energy)
print("Delta energy:", delta_energy)
print("Acceptance probability:", acceptance_prob)
if acceptance_prob > random.uniform(0, 1):
current_guess = new_guess
current_energy = new_energy
print("Accepted new guess!")
else:
print("Rejected new guess!")
print("Optimum value of x:", current_guess)
minimize_simulated_annealing()
This code performs five iterations for each temperature value from 100 to 10, reducing the temperature by 10 after each iteration. The outputs for the first five iterations at each temperature are printed. You can run this code to see the computed results and adjust it according to your needs.