MathGroup Archive 1999

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

Search the Archive

Re: Using "Fit"

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16166] Re: [mg16128] Using "Fit"
  • From: BobHanlon at aol.com
  • Date: Tue, 2 Mar 1999 01:13:13 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated 2/27/99 5:35:04 AM, pmhowe at lanl.gov writes:

>I'm trying to analyze some datasets in a moderately efficient way, and
>am
>having trouble. Your suggestions will be appreciated.
>
>Suppose that I have a dataset, and I want to fit a function through a
>number of points, where I vary that number systematically, by taking just
>two {x,y} points, then three points, then four, etc. So, if "data" is my
>dataset, I can form new datasets by doing
>
>Take[data,2], Take[data,3], etc. I can then do a fit to each dataset.
>
>Fit[Take[data,2], {1,x},x];
>Fit[Take[data,3], {1,x},x];
>Fit[Take[data,4], {1,x},x]; etc.
>
>But this is slow for large datasets. I can form a table of datasets.
>
>Table[Take[data,n],{n,2,100}];
>
>Now I'd like to apply Fit to each of the lists in the table, and I can't
>figure out the syntax. Or, perhaps there is a better approach.
>

Phil,

allData = Sort[Table[Random[], {128}]];

You just need to Map the function Fit onto the table which you generated.

nbrDataElem = 16;
data = Take[allData, nbrDataElem];
dataSets = Table[Take[data, n], {n, nbrDataElem}];
Fit[#, {1, x}, x]& /@ dataSets // ColumnForm

For large data sets, instead of increasing the number of elements 
one at a time, you might want to consider doubling the number of 
elements at each step in the process.

nbrDataElem = Length[allData];
dataSets = Table[Take[allData, 2^n], 
		{n, 0, Round[Log[2, nbrDataElem]]}];
Fit[#, {1, x}, x]& /@ dataSets // ColumnForm

Bob Hanlon


  • Next by Date: Packages
  • Next by thread: Re: Using "Fit"