首先确定方程组有解。由一式得 ,代回带二式,解得 ,方程组有解。不过这样解只用了数学,不符题意,下面使用 Python 来迭代求解。求解该方程组,可等价于求下述二元函数的最小值。 ( 写成 以方便观看。) 这样就可以用一些最优化算法求解了,这里使用粒子群算法。import numpy as np
from math import pi, sin, cos
from Algorithms.PSO import ParticleSwarm
def cost(v : np.ndarray) -> float:
a, b = v
return (a * sin(b) - 25) ** 2 + (a * (139 * cos(b) - 25 * sin(b)) + 50000) ** 2
search_space = np.array([
[-500, -2 * pi],
[500, 2 * pi]
])
solver = ParticleSwarm(cost, 30, search_space)
solution = solver.iteration(1000)
print(solution.best_fitness)
print(solution.best_position)