[SciPy-user] plot curve of a series of equations
Christopher Barker
Chris.Barker at noaa.gov
Fri Apr 24 17:55:54 EDT 2009
>> eqs = [
>> ['24 + 18.75*x + 4.79616e-013*x**2 + 31.25*x**3', 7.800, 7.600],
>> ['28 + 22.5*x + 5.68434e-013*x**2 + 0*x**3', 8.000, 7.800],
>> ]
>>
>> for i in eqs:
>> xr = np.linspace(i[2], i[1], 10)
>> x = xr - i[2]
>> y = eval(i[0])
eval makes me nervous. One of the nifty things about python is that
functions are objects too, so you can do something like:
(untested)
eqs = [
(lambda x: 24 + 18.75*x + 4.79616e-013*x**2 + 31.25*x**3,
7.800, 7.600),
(lambda x: 28 + 22.5*x + 5.68434e-013*x**2 + 0*x**3,
8.000, 7.800),
]
for f, x1, x2 in eqs:
xr = np.linspace(x1, x2, 10)
x = xr - x2
y = f(x)
If the function are more complicated, you can use def, rather than
lambda, and still put them in list or whatever.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the SciPy-User
mailing list