Plotting unknown functions

Ivan Cnop
icnop@vub.ac.be

Obtaining a formula from graphical input.

The classic approach in all standard textbooks is to plot known functions, i.e. functions with a prescribed expression.  
It is a hard problem to deduce the expression from a given graph, or from partial information about a graph. 
It takes a lot of mathematical experience to guess which kind of functions could eventually satisfy a set of constraints. 
We will see how a symbolic system may help.

Problem:

Find a function having a relative maximum with value approximately 2 close to x = 0, behaves like the diagonal x  near  x = 2, has a zero near  x = 4, and changes sign at this zero from positive to negative.

We cannot expect a symbolic system to answer this without making explicit what the constraints mean. 
However, we can draw a reasonable approximation and obtain some information about the kind of functions that can satisfy these constraints.

First: draw an empty plot

Plot[x, {x, -1, 5}, AspectRatio -> Automatic, 
      GridLines -> Automatic, 
      PlotRange -> {{-1, 5}, {-1, 5}}]

Next: draw some points and save these as "pts"

This is done by selecting the graphic, holding the appropriate key while clicking the mouse (or moving the mouse to make a sketch), and then copy - paste, before doing anything else.
Finally, assign the name "pts" to the pasted coordinates.

pts = {{-0.0072192, 2.01079}, {-0.0935508, 
            2.01079}, {-0.201465, 1.9892}, {-0.287797, 
            1.96762}, {-0.374128, 1.92446}, {-0.46046, 
            1.85971}, {-0.503626, 1.75179}, {-0.546792, 
            1.66546}, {-0.589957, 1.57913}, {-0.61154, 
            1.4928}, {-0.61154, 1.40647}, {-0.633123, 
            1.32013}, {0.0575296, 2.01079}, {0.143861, 1.94604}, {0.251776, 
            1.88129}, {0.338107, 1.85971}, {0.402856, 1.77338}, {0.489187, 
            1.68704}, {0.553936, 1.60071}, {0.618685, 1.51438}, {0.683434, 
            1.42805}, {1.54675, 1.55755}, {1.63308, 1.6223}, {1.69783, 
            1.70863}, {1.76258, 1.79496}, {1.84891, 1.83812}, {1.91366, 
            1.92446}, {1.99999, 1.9892}, {2.04316, 2.07554}, {2.1079, 
            2.16187}, {2.17265, 2.2482}, {2.25899, 2.31295}, {2.34532, 
            2.3777}, {2.41007, 2.46403}, {3.8777, 0.478402}, {3.8777, 
            0.39207}, {3.89929, 0.305738}, {3.92087, 0.219407}, {3.96403, 
            0.133075}, {4.0072, 
            0.0467438}, {4.02878, -0.0395879}, {4.07195, -0.125919}, {4.11511, -0.212251}, {4.15828, -0.298583}, {4.22303, -0.384914}, {4.24461, -0.471246}, {4.28778, -0.557577}, {4.30936, -0.643909}};

ListPlot[pts, AspectRatio -> Automatic, 
      GridLines -> Automatic, 
      PlotRange -> {{-1, 5}, {-1, 5}}]

Finally: approximate with a polynomial

Fit[pts, (x^Range)[0, 6], x]

Show[{Plot[%, {x, -1, 5}, AspectRatio -> Automatic, 
          GridLines -> Automatic, 
          PlotRange -> {{-1, 5}, {-1, 5}}], 
        ListPlot[pts]}]

Experiment: what degree polynomial?

Try the above while loweringthe degree

Fit[pts, (x^Range)[0, 5], x]

Show[{Plot[%, {x, -1, 5}, AspectRatio -> Automatic, 
          GridLines -> Automatic, 
          PlotRange -> {{-1, 5}, {-1, 5}}], 
        ListPlot[pts]}]

Fit[pts, (x^Range)[0, 4], x]

Show[{Plot[%, {x, -1, 5}, AspectRatio -> Automatic, 
          GridLines -> Automatic, 
          PlotRange -> {{-1, 5}, {-1, 5}}], 
        ListPlot[pts]}]

Fit[pts, (x^Range)[0, 3], x]

Show[{Plot[%, {x, -1, 5}, AspectRatio -> Automatic, 
          GridLines -> Automatic, 
          PlotRange -> {{-1, 5}, {-1, 5}}], 
        ListPlot[pts]}]

Fit[pts, (x^Range)[0, 2], x]

Show[{Plot[%, {x, -1, 5}, AspectRatio -> Automatic, 
          GridLines -> Automatic, 
          PlotRange -> {{-1, 5}, {-1, 5}}], 
        ListPlot[pts]}]

We see a rapid decrease in image faithfulness

Does it help to increase the degree substantially?

Fit[pts, (x^Range)[0, 12], x]

Show[{Plot[%, {x, -1, 5}, AspectRatio -> Automatic, 
          GridLines -> Automatic, 
          PlotRange -> {{-1, 5}, {-1, 5}}], 
        ListPlot[pts]}]

Remarks about the exact solution

The exact solution involves using derivatives at different points to describe the constraints.
This is one of the objectives of the Calculus as it has been developed over the centuries.
Modeling problems without knowing the nature of the result is among its achievements.

Lagrange interpolation can give an exact fit to some values, but the problem is more complex if the information is of a different nature. 
See the MathWorld encyclopedia for Lagrange interpolation:   http://mathworld.wolfram.com/LagrangeInterpolatingPolynomial.html