MathGroup Archive 2011

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

Search the Archive

Re: Suming InterpolatingFunction Objects


On Thu, 14 Jul 2011, DrMajorBob wrote:

> How did you discover the InterpolationPoints option, given that Help lists no 
> options (at all) for FunctionInterpolation?
>
> Bobby

Options[FunctionInterpolation]

;-)

Oliver


>
> On Thu, 14 Jul 2011 06:14:09 -0500, Oliver Ruebenkoenig 
> <ruebenko at wolfram.com> wrote:
>
>> On Thu, 14 Jul 2011, Gabriel Landi wrote:
>> 
>>> Hello everyone.
>>> 
>>> I encountered the following problem, which I am not sure is a bug or 
>>> simply
>>> a annoying detail.
>>> I will use as an example a piece of code from the mathematica tutorials.
>>> 
>>> Say I solve a system of ODEs
>>> 
>>> s = NDSolve[{x'[t] == -y[t] - x[t]^2, y'[t] == 2 x[t] - y[t]^3,
>>>  x[0] == y[0] == 1}, {x, y}, {t, 20}]
>>> 
>>> My quantity of interest could be x[t] + y[t]. I can plot it:
>>> 
>>> Plot[x[t] + y[t] /. s, {t, 0, 20}]
>>> 
>>> But say I wish to store it as a single object.
>>> So I do (this is the kinky part):
>>> 
>>> sum = FunctionInterpolation[x[t] + y[t] /. s, {t, 0, 20}]
>>> 
>>> Now, when I plot the result, it comes out completely different. It looks
>>> like something changed with the interpolation order or something.
>>> 
>>> Plot[sum[t], {t, 0, 20}]
>>> 
>>> What do you guys think?
>>> 
>>> Best regards,
>>> 
>>> Gabriel
>>> 
>> 
>> Gabriel,
>> 
>> here are two alternatives:
>> 
>> You could sample at more points via
>> 
>> sum = FunctionInterpolation[Evaluate[x[t] + y[t] /. s], {t, 0, 20},
>>   InterpolationPoints -> 100]
>> 
>> 
>> additionally specifying the derivatives may be a good idea:
>> 
>> sum = FunctionInterpolation[
>>   Evaluate[Table[
>>     D[Evaluate[x[t] + y[t] /. s], {{t}, k}], {k, 0, 2}]], {t, 0, 20},
>>   InterpolationPoints -> 30]
>> (* then you get away with less InterpolationPoints *)
>> 
>> or do it manually as follows:
>> 
>> The good thing here is that the NDSolve solutions are sampled at the same
>> points.
>> 
>> tutorial/NDSolvePackages#120436095
>> 
>> s = NDSolve[{x'[t] == -y[t] - x[t]^2, y'[t] == 2 x[t] - y[t]^3,
>>    x[0] == y[0] == 1}, {x, y}, {t, 20}]
>> 
>> Needs["DifferentialEquations`InterpolatingFunctionAnatomy`"]
>> 
>> domain = InterpolatingFunctionDomain[if1]
>> 
>> {coords1} = InterpolatingFunctionCoordinates[if1];
>> {coords2} = InterpolatingFunctionCoordinates[if2];
>> 
>> Norm[coords1 - coords2, 1]
>> 
>> vals1 = InterpolatingFunctionValuesOnGrid[if1];
>> vals2 = InterpolatingFunctionValuesOnGrid[if2];
>> 
>> if3 = Interpolation[Transpose[{coords1, vals1 + vals2}]]
>> 
>> Plot[if3[x], {x, 0, 20}]
>> 
>> Hope this helps.
>> 
>> Oliver
>> 
>
>
>


  • Prev by Date: Re: Suming InterpolatingFunction Objects
  • Next by Date: Re: Enterprise level Mathematica idea
  • Previous by thread: Re: Suming InterpolatingFunction Objects
  • Next by thread: Re: Suming InterpolatingFunction Objects