MathGroup Archive 2010

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

Search the Archive

Re: Re: Combining InterpolatingFunctions

Thanks to those who have responded. In the responses everyone defines a
new function f[x_] using piecewise. However, I want to be able to use
the interpolatingfunctions as a replacement rule, as that is what the
rest of my code requires. In particular I use the f[x_]:=f[x] =... trick
so I don't have to compute the same pieces of code repeatedly.

Here are some example interpolatingfunctions from NDSolve,

f1 = NDSolve[{y''[x] + y[x] == 0, y[0] == 0, y'[0] == 1},
   y, {x, 0, Pi}][[1]];
f2 = NDSolve[{y''[x] + y[x] == 0, y[Pi] == -1, y'[0] == =
   y, {x, Pi, 2 Pi}][[1]];

And then I want to be able to combine the two replacement functions to
act on an expression involving y, say A. If I just had one function I'd
do A/.f1, which gives me a function that I can then plot, evaluate at
different points etc. But I want the correct function f1 or f2 for the
appropriate ranges of x in A, but I don't want to specify x in the

So I can write Piecewise[{{ff1, 0 <= x <= Pi}, {ff2, Pi < x <= 2 Pi}}],
but that doesn't work as it doesn't have a value of x when used as a
replacement. It does work if I specify x beforehand, but I don't want

Any ideas?


-----Original Message-----
From: DrMajorBob [mailto:btreat1 at]
Sent: 03 February 2010 11:12
To: mathgroup at
Subject: [mg107171] [mg107129] Re: [mg107092] Combining InterpolatingFunctions

For instance:

f1 = Interpolation@Table[{x, Sin@x}, {x, 0, Pi, 1/10}];
f2 = Interpolation@Table[{x, Cos@x}, {x, Pi, 2 Pi, 1/10}];
f[x_] = Piecewise[{{f1@x, 0 <= x <= Pi}, {f2@x, Pi < x <= 2 Pi}}];
Plot[f@x, {x, 0, 2 Pi}]


On Tue, 02 Feb 2010 02:30:36 -0600, Simon Pearce 
<Simon.Pearce at> wrote:

> Hi MathGroup,
> I have two sets of InterpolatingFunctions coming from two separate
> NDSolve's. One of them is defined over the region [0,rc] and the other
> over the region [rc,2]. I would like Mathematica to automatically
> the correct one when I use a replacement rule. If I could tell it
> to extrapolate this would be perfect, though I don't seem to be able
> I've tried using FunctionInterpolation, but in order to keep my error
> terms down I had to increase the InterpolationPoints to 1000, which
> increases the calculation time from approximately .5sec to 1.5sec.
> Can anyone suggest an efficient way of combining
> without re-interpolating them? Or turning the extrapolation off!
> Thanks,
> Simon Pearce

DrMajorBob at

This message has been checked for viruses but the contents of an attachment may still contain software viruses which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.

  • Prev by Date: Re: Is this a bug? FromAdjacencyMatrix[]
  • Next by Date: Re: What does & mean?
  • Previous by thread: Re: Combining InterpolatingFunctions
  • Next by thread: Re: Combining InterpolatingFunctions