Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica: find mean value of an increasing list

  1. Oct 9, 2009 #1
    I have a list L={a_{1}, ..., a_{n}}. I would like to find the mean of
    L_{i} := {a_{1}, ... , a_{i}} for each 1<i<n, and then plot the means.
    How do to do that in a smart way?
     
    Last edited: Oct 9, 2009
  2. jcsd
  3. Oct 9, 2009 #2

    Hepth

    User Avatar
    Gold Member

    I'm not suite sure what you're asking but there are build in mean funcitons.

    So couldn't you do something like :

    MeanList= List[Mean[L],{i,0,n}]
    ListPlot[MeanList]
     
  4. Oct 9, 2009 #3
    The L_{i} can be constucted by the Take function. But it seems hard to plot the means afterwards. Thats the real problem, how to get something that can be plotted
     
  5. Oct 9, 2009 #4

    Hepth

    User Avatar
    Gold Member

    Well, your means will be scalars, one for each list, yes? well, make a list out of them and listplot.
     
  6. Oct 9, 2009 #5

    Hepth

    User Avatar
    Gold Member

    L = {11, 12, 13, 14, 15, 16}
    MeanList = Table[Mean[Take[L, i]], {i, 1, 6}]
    ListPlot[MeanList]
     
  7. Oct 9, 2009 #6
    Thank you very much.
    I did generate the means by:
    Code (Text):
    For[i = 1, i < 1000, i++, Print[Mean[Take[R, i]]]]
    and from there I was not able to make a list will all the means. Anyhow, your way was way better.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Mathematica: find mean value of an increasing list
  1. Lists in mathematica (Replies: 4)

Loading...