MathGroup Archive 2011

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

Search the Archive

Re: Suming InterpolatingFunction Objects


On Thu, 14 Jul 2011, DrMajorBob wrote:

>> 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 *)
>
> I have two questions about that:
>
> (1) The second Evaluate has no effect -- correct? -- since 
> FunctionInterpolation holds ENTIRE arguments, not parts of them.

Yes.

>
> (2) Help gives an example something like this, but among the basic function 
> forms at the top of the page, there are no templates involving a Table as the 
> first argument. What is Help trying NOT to explain?
>
> Bobby
>

Bobby, unfortunately I do not understand the question. I just copied stuff 
from the help page.

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: Numerical accuracy/precision - this is a bug or a feature?
  • Previous by thread: Re: Suming InterpolatingFunction Objects
  • Next by thread: Plotting a star map