RE: assigning Fit functionally
- To: mathgroup at smc.vnet.net
- Subject: [mg41354] RE: [mg41324] assigning Fit functionally
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Fri, 16 May 2003 06:40:06 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
>-----Original Message----- >From: gong li [mailto:gongli at cutey.com] To: mathgroup at smc.vnet.net >Sent: Wednesday, May 14, 2003 2:19 PM >To: mathgroup at smc.vnet.net >Subject: [mg41354] [mg41324] assigning Fit functionally > > >hi > >i would like to do the following: > >processdata[fitdata_,fitfns_,fitvars_,rundata_]:=Module[{f}, >f=Fit[fitdata,fitfns,fitvars] >Map[f,rundata]] > >this is the basic idea of what i want. fitdata has 1 more column than >rundatam so fit will process the fitting correctly. however, Fit's >result is an expression with the symbols in fitvars hardcoded into it >so its not working properly. > >thanks for any help >-gong li > > Here is a simple example. I just suppose that the "variables" are undefined symbols: In[1]:= fdata=Flatten[Table[{x,y,3+2x+.5 y^2+ .1 x y}, {x,0.,1.,.25},{y,-.5,.5,.25}], 1] In[2]:= vars={x,y}; In[3]:= funs={1,x,y,x^2,y^2,x y}; In[4]:= ff=Fit[fdata,{1,x,y,x^2,y^2,x y},vars] In[5]:= pts = Flatten[Table[{x, y}, {x, 0., 1., .25}, {y, -.5, .5, .25}], 1]; Out[4]= 3.0000000000000004 + 1.9999999999999996*x - 6.70687463899533*^-16*x^2 - 2.5478751053409354*^-18* y + 0.10000000000000132*x*y + 0.4999999999999985*y^2 Now define: In[17]:= processdata[fitdata_, fitfns_, fitvars_, rundata_]:= Module[{ff}, ff = Fit[fitdata, fitfns, fitvars]; (Function @@ {fitvars, ff}) @@@ rundata] In[18]:= processdata[fdata, funs, vars, pts]; In[19]:= %-fdata[[All,3]] Out[19]= {0., 4.440892098500626*^-16, 4.440892098500626*^-16, 4.440892098500626*^-16, 0., 0., 4.440892098500626*^-16, 4.440892098500626*^-16, 4.440892098500626*^-16, 0., 0., 0., 0., 0., 0., -8.881784197001252*^-16, 0., 0., 0., 8.881784197001252*^-16, -1.7763568394002505*^-15, -8.881784197001252*^-16, -8.881784197001252*^-16, -8.881784197001252*^-16, 0.} -- Hartmut Wolf