import numpy as np
import matplotlib.pyplot as plt
import scipy.optimize as so
rosenbrockfunction = lambda x,y: (1-x)**2+100*(y-x**2)**2
X,Y = np.meshgrid(np.linspace(-.5,1.5,100), np.linspace(-1.5,3.,100))
Z = rosenbrockfunction(X,Y)
plt.figure(figsize=(4,3), dpi=72)
cs=plt.contour(X,Y,Z,np.logspace(-0.5,3.5,20,base=10),cmap='gray',linewidths=1.0)
rosen=lambda x: rosenbrockfunction(x[0],x[1])
solution, iterates = so.fmin_powell(rosen,x0=np.array([0,-0.7]),retall=True)
x,y=zip(*iterates)
plt.plot(x,y,'.',c="red") # plot black bullets
plt.plot(x,y,':',c="red",linewidth=1.5) # plot black dotted lines
plt.clabel(cs)
plt.savefig('ex203.png')
plt.show()

Discover more from Tips and Hints for Aerospace Engineers

Subscribe now to keep reading and get access to the full archive.

Continue reading