Re: FindFit and NormFunction (to find a best fit by medians)
- To: mathgroup at smc.vnet.net
- Subject: [mg91751] Re: FindFit and NormFunction (to find a best fit by medians)
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Sun, 7 Sep 2008 05:35:53 -0400 (EDT)
- References: <g9t6j5$j5d$1@smc.vnet.net>
Hi, thank you that you was so kind to post a complete working example, sampledata = Table[{t, 0.2*Random[] + (2 + 0.1*Random[])*t}, {t, 0, 10, 0.25}]; myNorm[lst : {__Real}] := Sqrt[Median[lst^2]] FindFit[sampledata, a + b*x, {a, b}, x, NormFunction -> myNorm] will avoid the rectn-error message. Regards Jens Stern wrote: > I'm trying to use FindFit to find a best linear fit using Medians rather > than Mean > > At one time, I believe the following code worked (I used it in several > places, and never noted it failing, but it hasn't been used in a while and I > don't actually remember): > > FindFit[sampledata,a+b*x,{a,b},x,NormFunction->(Sqrt[Median[#^2]]&)] > > Now, Mathematica seems to pass unevaluated expressions to the NormFunction, > causing Median o fail with a "rectn: Rectangular array of real numbers is > expected at position 1" error. > > I would appreciate any guidance. > > Michael > >