Message Boards Message Boards

Exporting results from NDSolve?

Posted 2 years ago

Hi Guys

If I have "s" which pertains to the results from NDSolve, how can I export the results to excel? I require the numerical values of "x" and the values for "t"

s = NDSolveValue[sys, x, {t, 0, tf}]

Furthermore I am not sure how Mathematica deals with it's time steps, I would assume that the time steps are regular as produced by the ODE solvers in Matlab, however if the time steps are irregular, how can I get raw data with a regular time step?

Thus far I have figured out the that the raw data can be attained using the below

{s["Grid"], s["ValuesOnGrid"]}
POSTED BY: Mishal Mohanlal
2 Replies
Posted 2 years ago

Is your difficulty the export itself, or is it getting a table of values?

In your example, the value of s should be an InterpolatingFunction. That's just like any other function that can be applied to arguments. So, if you wanted a table of values for your range {0, tf}, then you could just evaluate s for values in that range spaced at whatever intervals you want. Like this (let's say tf is 10 and you want your spacing to be .5):

Table[{x, s[x]}, {x, 0, 10, .5}]

Or if you want to specify the number of samples (e.g. 35) instead of spacing:

Array[{#, s[#]} &, 35, {0, 10}]

If your difficulty is the export, then you need to decide the appropriate format. I assume you'll want CSV, so just use "CSV" as your format when you use Export (see http://reference.wolfram.com/language/ref/Export.html)

POSTED BY: Eric Rimbey

Thank you kindly.

POSTED BY: Mishal Mohanlal
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract