MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: restricting interpolating functions to be positive

  • To: mathgroup at smc.vnet.net
  • Subject: [mg106477] Re: [mg106455] Re: restricting interpolating functions to be positive
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Thu, 14 Jan 2010 05:46:58 -0500 (EST)
  • References: <higdjs$kfi$1@smc.vnet.net> <201001131058.FAA06854@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

For some data, that works pretty well; for other samples it has HUGE  
peaks, reaching far above any of the data:

data = Sort at RandomReal[{0.1, 1}, {20, 2}];
{min, max} = data[[{1, -1}, 1]]
f = Interpolation@data;
logdata = data /. {x_, y_} -> {x, Log[y]};
interp = Exp[Interpolation[logdata]@#] &;
Show[Plot[Evaluate@Through[{f, interp}@x], {x, min, max},
   PlotRange -> All]]

(run it several times)

The same thing happens here, but not as dramatically:

data = Sort at RandomReal[{0.1, 1}, {20, 2}];
{min, max} = data[[{1, -1}, 1]]
f = Interpolation@data;
logdata = data /. {x_, y_} -> {x, Sqrt[y]};
interp = (Interpolation[logdata]@#)^2 &;
Show[Plot[Evaluate@Through[{f, interp}@x], {x, min, max},
   PlotRange -> All]]

Bobby

On Wed, 13 Jan 2010 04:58:01 -0600, Noqsi <jpd at noqsi.com> wrote:

> On Jan 11, 4:52 pm, dantimatter <goo... at dantimatter.com> wrote:
>> Hi All,
>>
>> I would like to construct an interpolation that can only take on
>> positive values.  The data that I'm trying to interpolate is all
>> positive, but for some reason the Interpolation[] function 'wants' to
>> connect the dots by dipping below zero.  Is there a way to force
>> positivity?  Or should I simply adjust the InterpolationOrder until it
>> works?
>
> One way is to transform the data. Choose a positive real function f,
> apply its inverse to the data. Tranform the interpolation back using
> f.
>
> Exp[] often is a good choice for f. Using Valeri's example data:
>
> data = {{0, 2}, {1, 1}, {2, .2}, {3, .01}, {4, 1}, {5, 0.9}, {6,
>    0.05}, {7, 0.1}, {8, 1}}
> logdata = data /. {x_, y_} -> {x, Log[y]}
> interp[x_] = Exp[Interpolation[logdata][x]]
>
> If you plot interp[x], you'll see that it avoids zero.
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: default options, OptionsPattern[], and FilterRules[]
  • Next by Date: New version of Quantum Mathematica Add-On for Dirac bra ket notation quantum algebra and quantum computing
  • Previous by thread: Re: restricting interpolating functions to be positive
  • Next by thread: Re: restricting interpolating functions to be positive