Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Remove points from InterpolatingFunction

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109890] Re: Remove points from InterpolatingFunction
  • From: Frank Breitling <fbreitling at aip.de>
  • Date: Fri, 21 May 2010 06:46:09 -0400 (EDT)
  • References: <hsr87v$bc1$1@smc.vnet.net> <4BF22653.3050104@metrohm.com>

Hi Daniel,

Thank your very much for your fast answer.
You are right, I don't have the original points but obtain the
interpolating function from NDSolve.

Your solution for accessing points is what I was looking for.
It looks quite simple, but isn't obvious if you don't know it. I can
tell this from personal experience and answers received through the
German and international Mathematica lists where people come up with
complicated solutions
(http://www.mathematica.ch/dmug-archive/2010/msg00057.html) and refer to
complicated FullForm surgery
(http://forums.wolfram.com/mathgroup/archive/2010/May/msg00298.html).

As I learned from the German list
(http://www.mathematica.ch/dmug-archive/2010/msg00055.html), Mathematica
has the
DifferentialEquations`InterpolatingFunctionAnatomy` package to
compensate for this unexpected complication. It does the same thing and
in addition guaranties higher compatibility between different
Mathematica versions. Further details can be found at

http://reference.wolfram.com/mathematica/tutorial/NDSolvePackages.html .

However, since in Mathematica terminology points are referred to as
"coordinates" internet searches for point removal fail, too.
Therefore I will add a solution for point removal using Mathematica's
package below, to make others find it more easily.
The example below removes points from the function f[r] and reproduces
an interpolating function of the remaining points with the original
function values and slopes:

==

(*RemovePoints.nb*)

Needs["DifferentialEquations`InterpolatingFunctionAnatomy`"];

n = 6; y = RandomReal[{-1, 1}, n];
f[r_] = Interpolation[y][r];

points = Select[First[InterpolatingFunctionCoordinates[f[r][[0]]]],
   Not[.4 n < # < .7 n] &];
(*points = Select[f[r][[0]][[3, 1]], Not[.4 n < # < .7 n] &];*)

f2[r_] = Interpolation[
    Transpose[{Transpose[{points}], f[points], f'[points]}]][r];

Show[
 Plot[f[r], {r, 1, n}, PlotRange -> {{1, n}, {-1.5, 1.5}}],
 Plot[f2[r], {r, 1, n}, PlotStyle -> Hue[0.9]],
 ListPlot[y, PlotStyle -> PointSize[0.03]],
 ListPlot[Transpose[{points, f[points]}],
  PlotStyle -> {PointSize[0.02], Hue[0.9]}]]

==

Of course your expression is even shorter and doesn't require the
"InterpolatingFunctionAnatomy" package. It also works for me using
Mathematica 7 and so I added it as a comment for an alternative method.

Thanks again for your help!

Frank


PS: This mail got delayed by one day since the list didn't accept my
attached png illustration.


On 2010-05-18 07:32, dh wrote:
> Hi Frank,
> I assume you do not have the original points, otherwise you would simply
> delete some points and make a new function from the rest.
> Well, we may get the points from the function itself. E.g a one
> dimensional case:
> d = RandomReal[{-1, 1}, {5}];
> f = Interpolation[d]
> We may get the x and y values from:
> f[[3,1]]
> f[[4,3]]
> Having the points, delete the bad ones and use Interpolation to make a
> new one.
> Daniel
> 
> Am 17.05.2010 13:10, schrieb Frank Breitling:
>> Hello,
>>
>> I have an interpolating function with a small interval of low accuracy.
>> Therefore I would like to remove all points in this interval.
>> I already tried to overwrite the interval using Piecewise and Condition
>> (/;). However a so defined function causes problems in my later
>> calculations due to its higher complexity.
>> Therefore I would like to keep the original InterpolatingFuction and
>> only remove the problematic points.
>>
>> How can I do this?
>>
>> Kind regards
>>
>> Frank
>>
> 
> 




  • Prev by Date: Re: How to Enable Automatic Recalculation
  • Next by Date: Re: How to Enable Automatic Recalculation
  • Previous by thread: Re: Remove points from InterpolatingFunction
  • Next by thread: Multiple FindRoot