MathGroup Archive 1999

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

Search the Archive

Re: Using "Fit"

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16156] Re: Using "Fit"
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Tue, 2 Mar 1999 01:13:08 -0500
  • References: <7b89mg$4mb@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Philip M. Howe wrote in message <7b89mg$4mb at smc.vnet.net>...
>Hi,
>
>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.
>
>Thanks in advance for your help.
>
>Phil
>
>

Phil,
Some hints:
In[1]:=
data = Table[Random[],{10},{2}];
In[2]:=
takes = Table[Take[data,n],{n,2,Length[data]}];
In[3]:=
fits=Fit[#,{1,x,x^2,x^3},{x}]&/@takes
In[4]:=
Plot[Evaluate[fits],{x,0,1}, PlotStyle -> Table[Hue[t 0.7],{t,0,9}]]

Notes:
The crucial techniques are the use of the pure function at In[3] to get the
right pattern for the Fit input and the use of Map (/@) for using this
function on each list of data.
This applies to any list of data lists.

Many variations could be made - for example we might have the functions used
in Fit ( here 1, x, x^2,x^3) depend on the lists.

Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565





  • Prev by Date: How to draw the level curves ?
  • Next by Date: Printing error in MacOS
  • Previous by thread: Re: Using "Fit"
  • Next by thread: Re: Using "Fit"