Re: Combining InterpolatingFunctions
- To: mathgroup at smc.vnet.net
- Subject: [mg107187] Re: Combining InterpolatingFunctions
- From: Albert Retey <awnl at gmx-topmail.de>
- Date: Fri, 5 Feb 2010 03:21:03 -0500 (EST)
- References: <201002020830.DAA08963@smc.vnet.net> <201002031112.GAA19632@smc.vnet.net> <hkect6$1s0$1@smc.vnet.net>
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
- Follow-Ups:
- Re: Re: Combining InterpolatingFunctions
- From: Simon Pearce <Simon.Pearce@nottingham.ac.uk>
- Re: Re: Combining InterpolatingFunctions
- References:
- Combining InterpolatingFunctions
- From: Simon Pearce <Simon.Pearce@nottingham.ac.uk>
- Re: Combining InterpolatingFunctions
- From: DrMajorBob <btreat1@austin.rr.com>
- Combining InterpolatingFunctions