Re: Re: Re: Combining

• To: mathgroup at smc.vnet.net
• Subject: [mg107198] Re: [mg107171] Re: [mg107129] Re: [mg107092] Combining
• From: DrMajorBob <btreat1 at austin.rr.com>
• Date: Fri, 5 Feb 2010 03:23:03 -0500 (EST)
• References: <201002020830.DAA08963@smc.vnet.net>

```You'd compute things just once with the code I already sent you.

Bobby

On Thu, 04 Feb 2010 06:00:05 -0600, Simon Pearce
<Simon.Pearce at nottingham.ac.uk> wrote:

> 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?
>
> Thanks,
> Simon
>
> -----Original Message-----
> From: DrMajorBob [mailto:btreat1 at austin.rr.com]
> Sent: 03 February 2010 11:12
> To: mathgroup at smc.vnet.net
> Subject: [mg107171] [mg107129] Re: [mg107092] Combining
> InterpolatingFunctions
>
> For instance:
>
> Clear[f]
> 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}]
>
> Bobby
>
> On Tue, 02 Feb 2010 02:30:36 -0600, Simon Pearce
> <Simon.Pearce at nottingham.ac.uk> 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
> choose
>> the correct one when I use a replacement rule. If I could tell it
> never
>> to extrapolate this would be perfect, though I don't seem to be able
> to.
>>
>>
>>
>> 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
> InterpolatingFunctions
>> without re-interpolating them? Or turning the extrapolation off!
>>
>>
>>
>> Thanks,
>>
>>
>>
>> Simon Pearce
>>
>>
>
>
> --
> DrMajorBob at yahoo.com
>
>
> 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.
>

--
DrMajorBob at yahoo.com

```

• Prev by Date: Re: Re: Re: Re: What does
• Next by Date: Re: Localize Pattern variables
• Previous by thread: Re: Re: Combining InterpolatingFunctions
• Next by thread: Re: Re: Re: Combining