From: Frank Breitling on
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

From: Ingolf Dahl on
Hi Frank,
To me it is not completely clear what you are trying to achieve.
Either you could remove some of the control points for the definition of the
interpolation function. Mathematica can give you an interpolation function
in this case also, in the one-dimensional case. This function can of course
become very imprecise in the empty interval.
Or you might want to redefine the function in the unsure interval, and
replace it by something else. Then you maybe could add some extra control
points in the small interval? It depends on your problem what is suitable
and allowed.
With an already defined InterpolationFunction, you might check the structure
by looking at the FullForm of it, and make some surgery on that, bur that
sounds not as the easiest way.

Best regards

Ingolf Dahl
ingolf.dahl(a)telia.com

-----Original Message-----
From: Frank Breitling [mailto:fbreitling(a)aip.de]
Sent: den 17 maj 2010 13:11
Subject: Remove points from InterpolatingFunction

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


From: dh on
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
>


--

Daniel Huber
Metrohm Ltd.
Oberdorfstr. 68
CH-9100 Herisau
Tel. +41 71 353 8585, Fax +41 71 353 8907
E-Mail:<mailto:dh(a)metrohm.com>
Internet:<http://www.metrohm.com>


From: Frank Breitling on
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
>>
>
>



From: Frank Breitling on
Dear Ingo,

Thank you very much for your answer.
Meanwhile I found the solution for your suggested FullForm surgery.
I describe it in my reply to Daniel via this list.

Thanks again for your help.

Frank


On 2010-05-18 07:06, Ingolf Dahl wrote:
> Hi Frank,
> To me it is not completely clear what you are trying to achieve.
> Either you could remove some of the control points for the definition of the
> interpolation function. Mathematica can give you an interpolation function
> in this case also, in the one-dimensional case. This function can of course
> become very imprecise in the empty interval.
> Or you might want to redefine the function in the unsure interval, and
> replace it by something else. Then you maybe could add some extra control
> points in the small interval? It depends on your problem what is suitable
> and allowed.
> With an already defined InterpolationFunction, you might check the structure
> by looking at the FullForm of it, and make some surgery on that, bur that
> sounds not as the easiest way.
>
> Best regards
>
> Ingolf Dahl
> ingolf.dahl(a)telia.com
>
> -----Original Message-----
> From: Frank Breitling [mailto:fbreitling(a)aip.de]
> Sent: den 17 maj 2010 13:11
> To: mathgroup(a)smc.vnet.net
> Subject: Remove points from InterpolatingFunction
>
> 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
>