Re: Fitting data to line with a specific slope
- To: mathgroup at smc.vnet.net
- Subject: [mg30669] Re: [mg30618] Fitting data to line with a specific slope
- From: Ken Levasseur <Kenneth_Levasseur at uml.edu>
- Date: Mon, 3 Sep 2001 20:32:45 -0400 (EDT)
- References: <200108310809.EAA05457@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Catherine: You can transform your data first: In[9]:= data = {{-1, 5.}, {0, 0.1}, {1, -3}, {2, -6}, {4, -14.3}} Out[9]= {{-1, 5.}, {0, 0.1}, {1, -3}, {2, -6}, {4, -14.3}} m = -3.2; best = m x + Fit[data /. {{a_, b_} -> {a, b - m a}}, {1}, x] Out[19]= 0.2 - 3.2*x The linearity of least squares fitting lets you do this Ken Levasseur Math Sciences UMass Lowell Catherine Neish wrote: >Hi there. > >I am attempting to fit my data to a line of the form > > y = -3.2 x + intercept, > >but I cannot figure out how to do this with Mathematica. > >The function "Fit" takes only basis functions, so I cannot specify that I >would like the slope to be -3.2. I also tried "NonlinearFit," but the >following code > > NonlinearFit[data, intercept - 3.2 x, x, intercept] > >yielded the following error message: > >Tranpose::nmtx : The first two levels of the one-dimensional list {} cannot >be transposed >Tranpose::nmtx : The first two levels of the one-dimensional list {-3.2} >cannot be transposed >NonlinearFit::lnnosvd : NonlinearFit was unable to obtain the singular value >decomposition for the design matrix of the linear model. >NonlinearFit::fitfail : The fitting algorithm failed. > > >It is possible that my data does not fit a line with slope -3.2 very well. >Could this be the source of the errors? > >Any advice regarding these problems would be greatly appreciated. > >Sincerely, > >Catherine Neish > > >