comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Re: Constrained fit of a straight line: fixed intercept

Re: Constrained fit of a straight line: fixed intercept
type: item
description: On 8/27/10 12:36 AM, Joe Daal wrote: > Hi, > > I am not sure how easy this problem is, but it sure gave me hell > today. > I have the following vector arrays: X, Y,& Y_errors. There are 5 > elements in each and they do form a nice line describes by Y = A + BX. > I need to fit this line with B as a free parameter and constrain A to > pass by the the third point. > So the problem narrows down to one parameter as: Y = (Y0 - BX0) + BX, > whre Y0 and B0 and the third point values (i.e., X[2] and Y[2]). > I tried using MPFIT with the PARINFO keyword. It just didn't work. > Any ideas? Thanks.... > > -Joe How about: pivot = 2 dy = y - y[pivot] dx = x - x[pivot] w = where(dx ne 0, count) if count gt 0 then $ B = mean(dy[w]/dx[w]) $ else $ B = 0. TTFN, David
creator: David Grier
date: 2010-08-27T08:39:17-00:00

Re: Constrained fit of a straight line: fixed intercept
type: item
description: On 8/27/10 4:39 AM, David Grier wrote: > On 8/27/10 12:36 AM, Joe Daal wrote: >> Hi, >> >> I am not sure how easy this problem is, but it sure gave me hell >> today. >> I have the following vector arrays: X, Y,& Y_errors. There are 5 >> elements in each and they do form a nice line describes by Y = A + BX. >> I need to fit this line with B as a free parameter and constrain A to >> pass by the the third point. >> So the problem narrows down to one parameter as: Y = (Y0 - BX0) + BX, >> whre Y0 and B0 and the third point values (i.e., X[2] and Y[2]). >> I tried using MPFIT with the PARINFO keyword. It just didn't work. >> Any ideas? Thanks.... >> >> -Joe > > How about: > > pivot = 2 > dy = y - y[pivot] > dx = x - x[pivot] > w = where(dx ne 0, count) > if count gt 0 then $ > B = mean(dy[w]/dx[w]) $ > else $ > B = 0. ... and if you want to weight the results by the experimental errors: weights = abs(1./y_errors[w]) ; for instrumental errors B = mean(weights * dy[w] / dx[w]) / mean(weights) TTFN, David
creator: David Grier
date: 2010-08-27T10:45:18-00:00

Re: Constrained fit of a straight line: fixed intercept
type: item
description: On Aug 27, 5:45 am, David Grier <david.gr...@nyu.edu> wrote: > On 8/27/10 4:39 AM, David Grier wrote: > > > >> On 8/27/10 12:36 AM, Joe Daal wrote: >>> Hi, > >>> I am not sure how easy this problem is, but it sure gave me hell >>> today. >>> I have the following vector arrays: X, Y,& Y_errors. There are 5 >>> elements in each and they do form a nice line describes by Y = A + BX. >>> I need to fit this line with B as a free parameter and constrain A to >>> pass by the the third point. >>> So the problem narrows down to one parameter as: Y = (Y0 - BX0) + BX, >>> whre Y0 and B0 and the third point values (i.e., X[2] and Y[2]). >>> I tried using MPFIT with the PARINFO keyword. It just didn't work. >>> Any ideas? Thanks.... > >>> -Joe > >> How about: > >> pivot = 2 >> dy = y - y[pivot] >> dx = x - x[pivot] >> w = where(dx ne 0, count) >> if count gt 0 then $ >> B = mean(dy[w]/dx[w]) $ >> else $ >> B = 0. > > ... and if you want to weight the results by the experimental errors: > > weights = abs(1./y_errors[w]) ; for instrumental errors > B = mean(weights * dy[w] / dx[w]) / mean(weights) > > TTFN, > > David Great! Thank you. -Joe
creator: Joe Daal
date: 2010-08-27T20:57:57-00:00