1

I solved a function using NDSolve and got a result. I also have a plot of the function.

Could someone point me in the right direction how I can print the explicit data points and/or generate a fit such that I get a solution on function form?

Thank you all in advance

  • 1
    Hello, could you please post your code in the post so we can copy and paste? Many thanks! – bmf Mar 17 '22 at 17:30
  • Welcome to the Mathematica Stack Exchange. Please include enough Mathematica code in copy-paste-able form (not an image) to your post so that respondents can replicate the task on their computers. You can copy directly from your input cell and use the { } icon in the Edit window to format your code. – Syed Mar 17 '22 at 17:34
  • First example from the docs: s = NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30}]; Plot[Evaluate[y[x] /. s], {x, 0, 30}, PlotRange -> All]. Second example shows how to do a parametric plot. Check out NDSolveValue, too, for a different form that is sometimes more convenient. – Michael E2 Mar 17 '22 at 18:32

1 Answers1

2

So most parts of the answer can be found here: Export NDSolve data

Here is their example

Needs["DifferentialEquations`InterpolatingFunctionAnatomy`"];
soln = NDSolve[{x''[t] == -5 (1 + 1000 Exp[-100 t^2]) x[t], x[-5] == 0, x'[-5] 
== 1}, x, {t, -5, 5}]
xsoln = x /. First[First[soln]]
tvals = First[InterpolatingFunctionCoordinates[xsoln]];
xvals = InterpolatingFunctionValuesOnGrid[xsoln];
ListPlot[Transpose[{tvals, xvals}], PlotRange -> All]

Once the data is collected in a table. There is an inbuild funcion called "FindFunction". See here: https://reference.wolfram.com/language/ref/FindFormula.html

  • See also https://mathematica.stackexchange.com/questions/134222/easy-way-to-plot-ode-solutions-from-ndsolve and perhaps https://mathematica.stackexchange.com/questions/59944/extracting-the-function-from-interpolatingfunction-object – Michael E2 Mar 17 '22 at 18:36