Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

NDSolve output without interpolating function

1,454 views
Skip to first unread message

william cuervo

unread,
Jan 13, 2012, 4:52:39 AM1/13/12
to
Hi!

Is there any way that NDSolve presents the output as a set of data instead
of as an interpolating function?


Thanks!

Bob Hanlon

unread,
Jan 14, 2012, 2:53:20 AM1/14/12
to
You could generate a Table of points using the interpolating function;
however, it would be difficult to sample the function at the best
values. If you let Mathematica Plot the function then you can leverage
its sampling algorithm.

Clear[nDSolve]

nDSolve[eqn_, depVar_Symbol, iter_List, opts_: {}] :=

Module[{sol, plt, pts},
sol = depVar /. NDSolve[eqn, depVar, iter,
FilterRules[opts, Options[NDSolve]]][[1]];
plt = Plot[sol[iter[[1]]], iter,
Evaluate[FilterRules[opts, Options[Plot]]]];
pts = Cases[plt, Line[pts_] :> pts, Infinity][[1]];
{sol, plt, pts}]

sol = nDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1},
y, {x, 0, 30}, PlotRange -> All];

The result includes the interpolating function

Plot[sol[[1]][x], {x, 0, 30}, PlotRange -> All]

the plot used to capture the points

Show[sol[[2]]]

and the list of points

ListLinePlot[sol[[3]], PlotRange -> All]


Bob Hanlon

Oleksandr Rasputinov

unread,
Jan 14, 2012, 2:57:27 AM1/14/12
to
On Fri, 13 Jan 2012 09:52:39 -0000, william cuervo <wfcu...@gmail.com>
wrote:
As far as I know, no. However, you can extract the values from the
InterpolatingFunction using the (undocumented) forms:

ifun["Grid"]

to find the locations at which the values are sampled, and

ifun["ValuesOnGrid"]

to extract the values themselves.

These (as well as some other properties) are officially accessible via the
DifferentialEquations`InterpolatingFunctionAnatomy` package, which just
provides functions for calling the undocumented forms above.

DrMajorBob

unread,
Jan 14, 2012, 2:57:57 AM1/14/12
to
Wolfram obviously does NOT want you to find this, but... search for
NDSolvePackages in Help and you may find the InterpolatingFunctionAnatomy
package.

NDSolve returns InterpolatingFunction objects, and the "anatomy" package
will let you access their internals.

Bobby

On Fri, 13 Jan 2012 03:51:29 -0600, william cuervo <wfcu...@gmail.com>
wrote:

> Hi!
>
> Is there any way that NDSolve presents the output as a set of data
> instead
> of as an interpolating function?
>
>
> Thanks!


--
DrMaj...@yahoo.com

Oliver Ruebenkoenig

unread,
Jan 14, 2012, 3:01:31 AM1/14/12
to


On Fri, 13 Jan 2012, william cuervo wrote:

> Hi!
>
> Is there any way that NDSolve presents the output as a set of data instead
> of as an interpolating function?
>
>
> Thanks!
>

Hi,

how about

s = y /. First@
NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30}]

s["ValuesOnGrid"]

s["Methods"]

Oliver

Szabolcs Horvát

unread,
Jan 14, 2012, 2:51:47 AM1/14/12
to
For anything NDSolve-related, I recommend looking at this part of the docs:

http://reference.wolfram.com/mathematica/tutorial/NDSolveOverview.html

(This is literally book length!)

For your query about the points, see here:

http://reference.wolfram.com/mathematica/tutorial/NDSolvePackages.html

First load the DifferentialEquations`InterpolatingFunctionAnatomy` package.

Then InterpolatingFunctionCoordinates[ifun] will give you the list of
coordinates. You can then map ifun (the interpolating function) to this
list to get the function values.

But note that an interpolating function has more than just this: it
also has the values of the derivatives, but just the function values itself.

Hope this helps.

--
Szabolcs Horvát
Mma QA site proposal: http://area51.stackexchange.com/proposals/37304

Kevin J. McCann

unread,
Jan 14, 2012, 2:52:18 AM1/14/12
to
Bring up the Documentation (help) window, and drop this into it:

tutorial/NDSolvePackages

Scroll down a bit and check out InterpolatingFunctionCoordinates. I
think it is what you want.

Kevin

Nasser M. Abbasi

unread,
Jan 14, 2012, 5:21:47 PM1/14/12
to
Wow, that is amazing. Never knew about these. Any idea where to
read more about these options? to understand more what they return
and such.

Sounds like they will be very useful to know about. nothing in documentation
center on them.

thanks
--Nasser

Oleksandr Rasputinov

unread,
Jan 15, 2012, 4:53:44 AM1/15/12
to
On Sat, 14 Jan 2012 22:21:47 -0000, Nasser M. Abbasi <n...@12000.org> wrote:

> On 1/14/2012 2:01 AM, Oliver Ruebenkoenig wrote:
> Wow, that is amazing. Never knew about these. Any idea where to
> read more about these options? to understand more what they return
> and such.
>
> Sounds like they will be very useful to know about. nothing in
> documentation
> center on them.
>
> thanks
> --Nasser
>

These have a rather unusual form of documentation that works as follows:

s["MethodInformation"["ValuesOnGrid"]]

prints:

System`InterpolatingFunction`ValuesOnGrid

InterpolatingFunction[domain, data]@ValuesOnGrid[] gives the function
values at each grid point. In some cases, this may be faster than
evaluating at each of the grid points.

Attributes[System`InterpolatingFunction`ValuesOnGrid] = {Protected}

Options[System`InterpolatingFunction`ValuesOnGrid] = {DropPeriodicEndpoint
-> False}

(of course, you can substitute "ValuesOnGrid" for whatever Method you are
interested in.)

Kevin J. McCann

unread,
Jan 16, 2012, 6:49:06 AM1/16/12
to
Oliver,

Wow! How did you find these? I always thought something like this should
be around, but resorted to rather tedious ways of getting at the data.

Thanks for putting this out. As far as I know, it is not in the
documentation.

Kevin

Oliver Ruebenkoenig

unread,
Jan 16, 2012, 6:58:46 AM1/16/12
to


On Sat, 14 Jan 2012, DrMajorBob wrote:

> Wolfram obviously does NOT want you to find this, but... search for
> NDSolvePackages in Help and you may find the InterpolatingFunctionAnatomy
> package.
>
> NDSolve returns InterpolatingFunction objects, and the "anatomy" package
> will let you access their internals.
>
> Bobby

Hi Bobby,

Yes, there should be a link from the InterpolatingFunction page to the
anatomy package. I filed this as a suggested improvement for the
Documentation.

Oliver


>
> On Fri, 13 Jan 2012 03:51:29 -0600, william cuervo <wfcu...@gmail.com>
> wrote:
>
>> Hi!
>>
>> Is there any way that NDSolve presents the output as a set of data
>> instead
>> of as an interpolating function?
>>
>>
>> Thanks!
>
>
> --
> DrMaj...@yahoo.com
>
>

Oliver Ruebenkoenig

unread,
Jan 16, 2012, 6:59:17 AM1/16/12
to


On Sun, 15 Jan 2012, Oleksandr Rasputinov wrote:

> On Sat, 14 Jan 2012 22:21:47 -0000, Nasser M. Abbasi <n...@12000.org> wrote:
>
>> On 1/14/2012 2:01 AM, Oliver Ruebenkoenig wrote:
>>> On Fri, 13 Jan 2012, william cuervo wrote:
>>>
>>>> Hi!
>>>>
>>>> Is there any way that NDSolve presents the output as a set of data
>>>> instead
>>>> of as an interpolating function?
>>>>
>>>>
>>>> Thanks!
>>>>
>>>
>>> Hi,
>>>
>>> how about
>>>
>>> s = y /. First@
>>> NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30}]
>>>
>>> s["ValuesOnGrid"]
>>>
>>> s["Methods"]
>>>
>>> Oliver
>>>
>>
>> Wow, that is amazing. Never knew about these. Any idea where to
>> read more about these options? to understand more what they return
>> and such.
>>
>> Sounds like they will be very useful to know about. nothing in
>> documentation
>> center on them.
>>
>> thanks
>> --Nasser
>>
>
> These have a rather unusual form of documentation that works as follows:
>
> s["MethodInformation"["ValuesOnGrid"]]
>
> prints:
>
> System`InterpolatingFunction`ValuesOnGrid
>
> InterpolatingFunction[domain, data]@ValuesOnGrid[] gives the function
> values at each grid point. In some cases, this may be faster than
> evaluating at each of the grid points.
>
> Attributes[System`InterpolatingFunction`ValuesOnGrid] = {Protected}
>
> Options[System`InterpolatingFunction`ValuesOnGrid] = {DropPeriodicEndpoint
> -> False}
>
> (of course, you can substitute "ValuesOnGrid" for whatever Method you are
> interested in.)
>
>


I filed a suggestion that the documentation on "MethodInformation" be
improved in the future.

In general, I usually, try "Properties" and "Methods" on objects. Some of
them offer additional functionality (while the one in this case can be
accessed via the anatomy package (tutorial/NDSolvePackages#120436095))


Thanks,
Oliver


Scot T. Martin

unread,
Jan 17, 2012, 3:37:18 AM1/17/12
to
Another "wow" from me. I hope the right person at Wolfram is listening. It would be really great to know about this additional functionality for NDSolve within its documentation, which is a great function that I have been using since 1994 (flattery to Wolfram!) and for which I am very keen to now learn about these additional possibilities (petition to Wolfram!). Please.


________________________________________
From: Oliver Ruebenkoenig [rueb...@wolfram.com]
Sent: Monday, January 16, 2012 17:09
Subject: Re: NDSolve output without interpolating function

DrMajorBob

unread,
Jan 17, 2012, 3:37:48 AM1/17/12
to
Documenting it would take ALL the fun out.

Bobby

On Mon, 16 Jan 2012 16:02:44 -0600, Kevin J. McCann <k...@kevinmccann.com>
wrote:

> Oliver,
>
> Wow! How did you find these? I always thought something like this should
> be around, but resorted to rather tedious ways of getting at the data.
>
> Thanks for putting this out. As far as I know, it is not in the
> documentation.
>
> Kevin
>
--
DrMaj...@yahoo.com

0 new messages