MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Creating a new table using values from a column in another table,


Wonko the Sane wrote:
> Hi all,
> 
> I have a question that I have not been able to work out myself, and so 
> put it to the group to help. I have a set of data points in a table (2 
> columns {{x1,y1},{x2,y2},....,{xn,yn}}) I have performed a fit to the 
> data and have a function f[x] which I would now like to evaluate at each 
> data point (column 1 of the first table) to get a new table 
> {{x1,f[x1]},{x2,f[x2]},....,{xn,f[xn]}}. Is there a way to do this? I 
> hope my request is clear
> 
> Best Regards
> Michael
> 
Hi Michael,

This (In[4]) should do what you want:

In[1]:=
data = Table[{n, Random[] + Sin[n]}, {n, 0, 4*Pi, 4*(Pi/100.)}];

In[2]:=
ListPlot[data, PlotStyle -> PointSize[0.02]];

In[3]:=
func[x_] = Fit[data, {1, Sin[x]}, x]

Out[3]=
0.40600651483282013 + 1.0079803137250567*Sin[x]

In[4]:=
({#1, func[#1]} & ) /@ data[[All,1]];

In[5]:=
ListPlot[%, PlotStyle -> PointSize[0.02]];

Best regards,
Jean-Marc


  • Prev by Date: Re: Mathematica Question
  • Next by Date: Re: Rules
  • Previous by thread: Re: Creating a new table using values from a column in another table,
  • Next by thread: RE: Creating a new table using values from a column in another table,