Re: Combining InterpolatingFunctions

```Am 04.02.2010 13:00, schrieb Simon Pearce:
> 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] == =
> 1},
>    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
> piecewise.
>
> 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
> to!
>
> Any ideas?

If you need a replacement rule with something that acts like a function,
then you could construct it with something like this, which should
behave in almost every respect as one of the rules with interpolating
functions (to be on the save side, you might want to Block x on the RHS,
in case it has an OwnValue):

ftot = {y ->
Function @@ {{x},
Piecewise[{{y[x] /. f1, 0 <= x <= Pi}, {y[x] /. f2,
Pi < x <= 2 Pi}}]}}

hth,

albert

```

• Prev by Date: Re: Normality test
• Next by Date: Obtain smooth plot of free-hand contour
• Previous by thread: Re: Re: Combining InterpolatingFunctions
• Next by thread: Re: Re: Combining InterpolatingFunctions