Re:Need help with creating a List

*To*: mathgroup at yoda.ncsa.uiuc.edu (Mathematica Mailing List)*Subject*: Re:Need help with creating a List*From*: uunet!kinghorn.chem.WSU.EDU!don (Don Kinghorn)*Date*: Fri, 24 Aug 90 10:40:23 PDT

Begin recieved message: ************************************************************************************ . . . I am having some trouble with creating a list for plotting with ListPlot. As I understand it, what is needed is a list of lists, where each element of the main list is a list of two values, the x and y positions to be plotted. In my case, the x values are just a set of evenly spaced values, while the y values are the difference between some data I have and a functional form for the data. What I have is: func[x_] = "some long function" The data is in a list called "data" diff[x_] := data[[x]] - func[.05x] difftable = Table[ {.05i, diff[i]}, {i, Length[data]} ] My problem is the output of difftable. It looks like: {{.05, {value1}}, {.01, {value2}}, ....} What it needs to be for ListPlot to work (I think) is: {{.05, value1}, {.01, value2}, ....} I tried to make a test file with a simple func[x_] and just put in some datapoints, and there it did work. So I'm confused as to when and why mathematica is giving me {{xval1,yval1},{xval2,yval2}, ..} in one case and {{xval1,{yval1}}, {xval2,{yval2}}, ..} in the other case. Any ideas or suggestions? --Avi Feldblum ayf at pruxk.att.com or avi_feldblum at att.com *********************************************************************************** Look at your y data. I suspect that its in the form of a list of lists ( an nx1 matrix) and as a result your function diff is returning a vector. Try applying Flatten[] to your y data to put it in the form {y1,y2,y3, . . .}. This should give the result you want. Example: In[1]:= data=Transpose[{{1,2,3,4}}] Out[1]= {{1}, {2}, {3}, {4}} In[2]:= fcn[x_] := x-1/2 In[3]:= dif[x_] := data[[x]]-fcn[.05x] In[4]:= Table[{.05i,dif[i]},{i,Length[data]}] Out[4]= {{0.05, {1.45}}, {0.1, {2.4}}, {0.15, {3.35}}, {0.2, {4.3}}} In[5]:= data = Flatten[data] Out[5]= {1, 2, 3, 4} In[6]:= Table[{.05i,dif[i]},{i,Length[data]}] Out[6]= {{0.05, 1.45}, {0.1, 2.4}, {0.15, 3.35}, {0.2, 4.3}} I hope this helps. (this is only one of many possible solutions) Don Kinghorn