From: Karan on 31 Oct 2007 22:27 How to force y intercept to be zero using function PolyFit (x, y, 1)
From: Daniel Sutoyo on 1 Nov 2007 03:11 Check this post http://www.mathworks.com/support/solutions/data/1-12BBUC.html?product=OP&solution=1-12BBUC Daniel Sutoyo "Karan " <ksumbaly(a)hotmail.com> wrote in message <fgbdie$5mp$1(a)fred.mathworks.com>... > How to force y intercept to be zero using function PolyFit > (x, y, 1)
From: John D'Errico on 1 Nov 2007 03:32 "Daniel Sutoyo" <dsutoyo(a)gmail.com> wrote in message <fgbu6e$bve $1(a)fred.mathworks.com>... > Check this post > > http://www.mathworks.com/support/solutions/data/1-12BBUC.html? product=OP&solution=1-12BBUC > > Daniel Sutoyo > > "Karan " <ksumbaly(a)hotmail.com> wrote in message > <fgbdie$5mp$1(a)fred.mathworks.com>... > > How to force y intercept to be zero using function PolyFit > > (x, y, 1) EXCEPT! The link posted suggests the user must use fmincon from the optimization toolbox! This is the Matlab equivalent of using a Mack truck to carry a pea to Boston. No toolboxes are even remotely necessary to solve this problem. In the simple case of fitting a straight line with a zero intercept, the constant term will be zero in the model. So we can solve for the slope of the fitted line by simply slope = x\y; where x and y are column vectors. If you wish it to be a polynomial as polyfit would return, just do this: P = [slope,0]; Even in the far more general case, where the asker might have wanted to fit a higher order polynomial through some general point, the use of fmincon is still not necessary. There I would have suggested using lsqlin from the optimization toolbox, or even one of my own tools from the file exchange. The use of fmincon is wild overkill for this problem. John
|
Pages: 1 Prev: run compiled exe file on another machine Next: varflowFailedException exception |