1
$\begingroup$

Consider that we have some plot in Mathematica notebook, like an ordinary plot = Plot[f[x],{x,xmin,xmax},PlotRange->All,PlotLegends->...]. Next, assume that f[x] has been forgotten by Mathematica (like, a part of the code has been deleted, or "Quit kernel" has been applied). Is it possible to extract f[x] from plot, i.e. is there some operation that allows obtaining f[x] by applying some operation with plot?

$\endgroup$
4
  • 7
    $\begingroup$ If you go plot//InputForm (or FullForm - and you can do it to the image stored in a notebook as well) you’ll get a giant output, but you’ll be able to see the actual code held by Mathematica. Generally, it’s full of line objects of GraphicsComplex which all have numerical data. If you had a hint on what the original function was, you might be able to fit it to the data stored there, but I don’t think you can recover the function perfectly. $\endgroup$
    – MassDefect
    Dec 10, 2020 at 9:04
  • 1
    $\begingroup$ @MassDefect, This way will not give you a function. The graphics of Plot stored in notebook is a postscript-like object, i.e. there are a lot of coordinates of points and curves but there is not an original function behind them $\endgroup$
    – Rom38
    Dec 10, 2020 at 10:02
  • 1
    $\begingroup$ You can recover the GraphicsComplex (or point data) from the graphics and then fit the data to a function using one of several of the built-in functions. The fitting process may yield the original function. For example, generate 100 points of sin(x), then use FindFormula and include Sine in the list of target functions. I suspect this will return sin(x). $\endgroup$
    – Dominic
    Dec 10, 2020 at 12:56
  • $\begingroup$ @Rom38 Right, that’s exactly what I meant. Sorry if I wasn’t clear. All that’s stored in there is raw data as lines and graphics complex objects. $\endgroup$
    – MassDefect
    Dec 10, 2020 at 19:03

1 Answer 1

1
$\begingroup$

For Example:

plot = Plot[{x^2 - 1/4 x^3, x Sin[x]}, {x, 0, 10}, PlotRange -> All, PlotLegends -> "Expressions"]
points = Cases[plot, Line[linedata_] -> linedata, Infinity];
FindFormula[#, x, 1] & /@ points

Out={1. x^2. - 0.25 x^3., x Sin[x]}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.