[SciPy-User] [SciPy-user] Accessing calculated function values of scipy.interpolated.quad
Pauli Virtanen
pav+sp@iki...
Mon Oct 26 12:01:22 CDT 2009
Mon, 26 Oct 2009 11:51:57 -0400, josef.pktd wrote:
> On Mon, Oct 26, 2009 at 10:40 AM, Richard Pfeifer
> <richard.w.pfeifer@googlemail.com> wrote:
>>
>> Hi Scipy-Users,
>>
>> I've got a question concerning scipy.integrate: I'm interessted in
>> (1) the Integral F = Int(f, a, b) of the function f(x) in the range
>> (a,b)
>> AND
>> (2) the values f(x_i) used for the integration (to plot f(x) in the
>> same
>> range).
>> scipy.integrate.quad can do the first job very well but I did not find
>> a way to get the values f(x_i). I could let scipy.integrate.quad do
>> it's job and then evaluate f(x) again for the plotting but this would
>> need twice the time...
>>
>> Is there any way to get the [x_i, f(x_i)] scipy.integrate.quad
>> calculated for the integration?
>
> I think the answer is no.
> Looking at the source of scipy.integrate.quad, the python function
> returns all the return values of the fortran routine. So the actual
> points of evaluation seem to be temp variables inside the fortran
> program.
There's no pre-made solution, but you can cook one yourself:
def func(x):
return ...long computation...
values = []
def wrapfunc(x):
y = func(x)
values.append((x, y))
return y
ig = integrate.quad(wrapfunc, 0, 1)
values = np.array(values)
values = values[np.argsort(values[:,0])]
--
Pauli Virtanen
More information about the SciPy-User
mailing list