       Re: Approximating the function from its plot

• To: mathgroup at smc.vnet.net
• Subject: [mg56131] Re: Approximating the function from its plot
• From: Peter Pein <petsie at arcor.de>
• Date: Sat, 16 Apr 2005 03:52:20 -0400 (EDT)
• References: <d3o0dm\$bn5\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Siddharth Jain wrote:
> Hello
>
> I want find an approximate function for a ListPlot. Is it possible to
> do this using mathematica ?
>
> Thanks
> Siddharth
>
The method to use depends on whether the plot has been generated with
PlotJoined->True or False:

In:= (* a simple example *)
tb = Table[{x, Cos[x]}, {x, 0, Pi, Pi/5}];
pl = ListPlot[tb];

(*extract the coordinates of the points*)
data = Cases[pl[], Point[{x_, y_}] -> {x, y}];

In:= (* verify result *)
data == tb
Out= True

If PlotJoined->True has been used, we need the coordinates that are used
by Line[]:

In:= pl = ListPlot[tb, PlotJoined -> True, PlotStyle -> Red];
data = Cases[pl[], Line[lst_] -> lst, {0, Infinity}][];
In:= (* verification again: *)
data == tb
Out=  True

In:= (* now build an interpolating function:*)
f = Interpolation[data];
In:= (* and show the result *)
Show[Block[{\$DisplayFunction = #1 & },
Plot[f[x], {x, 0, Pi}]], pl];

--
Peter Pein
Berlin

```

• Prev by Date: Re: Maping and Complex Addition
• Next by Date: Re: Maping and Complex Addition
• Previous by thread: Re: Approximating the function from its plot
• Next by thread: Re: Approximating the function from its plot