[SciPy-User] maping a float to a function value
Christopher Barker
Chris.Barker at noaa.gov
Wed Dec 9 18:02:05 EST 2009
> I need the (numerical) solution of the integral
> equation
>
> gamma(x) = c(x) + \int_0^\infty gamma(x-y) G(y) dy,
>
> for given functions c(x) and G(x). (There are some technical
> conditions on G and c such that I can prove that the integral equation
> has a solution.) Now I like to store the values gamma(x) as keys of
> x, as it feels natural. Moreover, I need gamma in a second integral
> equation. Sure I can store gamma as an array, but then I have to
> convert the index i to the key x, and I dislike this, as it is less
> elegant, and requires extra code.
However, I think it's a more correct solution -- as you've pointed out
real numbers to not map directly to floats, and, indeed, you are never
going to have gamma(x) pre-calculated for all x in your range. Indeed,
it's a bit absurd to try to have gamma(x) for all floats in your range,
either. So you are going to have to compute and store a subset. As they
are ordered, it sure makes sense to simply store them, and it's easy to
calculate an index -- you could put a different api on it if you really
want:
class gamma:
def__get_item(self, value):
# compute index form value here
return self._gamma[index]
but, as you are storing only a subset of your possible values, it seems
that interpolation really is the best and most natural way to go anyway.
In fact, the above is simply a nearest neighbor interpolator already, as
is your proposed dict with keys of rounded floats.
-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