From help-octave-request at bevo dot che dot wisc dot edu Tue Dec 15 13:28:48 1998 Subject: Re: fit data - trendline through zero From: heberf To: help-octave at bevo dot che dot wisc dot edu Date: Tue, 15 Dec 1998 13:29:34 -0600 (CST) Polyfit just does a regression of Y on a constant, X, X^2, X^3 and so on up to the order of the polynomial you are interested in. To set the intercept to zero you need to create some new variables. y = Y - mean(Y); x = X - mean(X); x2 = X.^2 - mean(X.^2); etc Put the x, x2, x3 etc into a matrix Z. The values of the line you want will be f = Z*inv(Z'*Z)*Z'y; Now a simple plot(x,f) will give the plot you want. This is a true least squares fit. In fact the slope coefficient on xn will be the same as the slope coefficient on X^n in the original data. The only thing that has changed is that the intercept is zero. Heber Farnsworth. > I use polyfit to find the trendline in my data. How can I force it to go > through zero ? > > Thanks > > Marcel > > > --------------------------------------------------------------------------- > > Marcel Meissel > > Polymer Processing Laboratory > Department of Mechanical Engineering > University of Maryland > College Park, MD 20742 > > (301)-405-2119 > --------------------------------------------------------------------------- > > Visit "www.MEISSEL.com" and tell me about the design. I need Feedback > ! > _ _ > / / (_)__ __ ____ __ > / /__/ / _ \/ // /\ \/ / ... The choice of a > /____/_/_//_/\_,_/ /_/\_\ GNU generation > ------------- End Forwarded Message -------------