这里用到的是scipy.optimize的fmin和fminbound import numpy as np from matplotlib import pyplot as plt from scipy.optimize import fmin,fminbound def f(x): return x**2+10*np.sin(x)+1 x=np.linspace(-10,10,num=500) min1=fmin(f,3)#求3附近的极小值 min2=fmin(f,0)#求0附近的极小值 min_global=fminbound(f,-10,10)#这个区域的最小值 print(mi