Re: data fitting function
- To: mathgroup at smc.vnet.net
- Subject: [mg40865] Re: data fitting function
- From: Bill Rowe <listuser at earthlink.net>
- Date: Tue, 22 Apr 2003 06:47:50 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
On 4/21/03 at 6:51 AM, gongli at cutey.com (gong) wrote: >i would like to fit some data X = {{x1,y1},...,{xn,yn}} to a set of >functions, then have this assigned to a function i can call: >fittedfunc[x1] \approx y1 >moreover, i need fittedfunc to be as fast as possible in terms of >evaluation, since it will be used in a loop. i think it should be >ideally a compiled function. >i tried >f=Function[x,Fit[X,{functions},x] >bit im finding a major speed hit here, i think every time i call f[x] >it refits the data. Make this a two step operation. Step one, outside the loop would be to do the curve fit, i.e., f= Fit[X,{functions},x] Step two would be to evaluate f for specific values i.e., y = f/.x->#&/@xvalues Here, I am assuming xvalues is a list that contains all of the points where you want f evaluated. Using this approach, you wouldn't want to put the evaluation step inside a loop. If you need to evaluate f for each value one at a time inside the loop you will want a different method for evaluating f at each of the desired points. But the principle remains, to avoid repeatedly performing the Fit assign the results to a variable outside the loop and evaluate at the desired points in a separate step.