【发布时间】:2013-04-02 02:15:10
【问题描述】:
在 Jamie 对 post 的帮助之后,我知道我需要使用 scipy.optimize。但是,我不断收到以下错误:
Traceback (most recent call last):
File "./hw7problem5.py", line 19, in <module>
print(max_R)
NameError: name 'max_R' is not defined
#!/usr/bin/env python
# Plotting the energy for circular Hohmann transfer
import scipy
import matplotlib
import numpy as np
import pylab
def f(R):
return ((1 / np.sqrt(R)) - ((np.sqrt(2) * (1 - R)) / (np.sqrt(2)
* (1 + R))) - 1)
max_r = scipy.optimize.fmin(lambda r: 1 / f(r), 20)
x = np.arange(1, 25, 0.001)
pylab.plot(x, f(x), 'r')
pylab.show()
print(max_R)
【问题讨论】:
标签: optimization scipy ipython