[SciPy-user] plot curve of a series of equations
Gary Ruben
gruben at bigpond.net.au
Thu Apr 23 05:40:13 EDT 2009
Like this? This basically just what you said, so I'm not sure what your
exact question is. Is it just the use of eval that you weren't clear on?
import numpy as np
import matplotlib.pyplot as plt
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])
plt.plot(xr,y)
plt.show()
Gary R.
Bevan Jenkins wrote:
> Hello,
>
> I have a series of equations that describe a curve. Each equation is only
> valid for a range of x values. For example:
>
> Equation Upperlimit Lowerlimit
> 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
>
> There is a lower limit for eqn1, after that the upper limit of the previous
> eqn is lower of the next.
>
> From (X) scale linear, To (Y) scale linear
> y = A0 + A1(x) + A2(x)2 + A3(x)3
> where: x= value – LL
>
> LL = the lower limit of the applicable equation
>
> I would like to generate a sequence of values (linspace(min(lowerlimit),max
> (upperlimit)), work out x (x=value-approriate lower limit) and then using the
> appropriate equation generate the y values.
> Below is the answer I am looking for
>
> Value x y
> 7.600 0 24.000
> 7.650 0.05 24.941
> 7.700 0.1 25.906
> 7.750 0.15 26.918
> 7.800 0.2 28.000
> 7.850 0.050 29.125
> 7.900 0.100 30.25
> 7.950 0.150 31.375
> 8.000 0.200 32.5
>
> Thanks for any help,
>
> Bevan Jenkins
More information about the SciPy-User
mailing list