MathGroup Archive 2011

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

Search the Archive

Re: Suming InterpolatingFunction Objects

  • To: mathgroup at smc.vnet.net
  • Subject: [mg120253] Re: Suming InterpolatingFunction Objects
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Thu, 14 Jul 2011 21:21:25 -0400 (EDT)
  • References: <201107140922.FAA15682@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

FunctionInterpolation appears unreliable, with NO options for controlling  
its accuracy!! I've used it in the past, and had no idea it could fail so  
badly.

But this works:

s = First@
    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}];
Clear[sum]
sum[t_] = x[t] + y[t] /. s;
Plot[sum[t], {t, 0, 20}]

and this also works:

s = First@
    NDSolve[{x'[t] == -y[t] - x[t]^2, y'[t] == 2 x[t] - y[t]^3,
      z[t] == x[t] + y[t], x[0] == y[0] == 1}, {x, y, z}, {t, 20}];
Plot[z[t] /. s, {t, 0, 20}]

Bobby

On Thu, 14 Jul 2011 04:22:34 -0500, Gabriel Landi <gtlandi at gmail.com>  
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


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: Numerical accuracy/precision - this is a bug or a feature?
  • Next by Date: Re: I think Omitting the multiplication sign is a big mistake
  • Previous by thread: Plotting a star map
  • Next by thread: Re: Suming InterpolatingFunction Objects