Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

How to implement without function.?

Asked by Lalit Patil on 21 Jan 2013
 polyfit(x,y,1)

How to implement the same thing without function..?

0 Comments

Lalit Patil

Products

No products are associated with this question.

2 Answers

Answer by Jan Simon on 21 Jan 2013

I assume that this is a homework question. There are good reasons to look for a faster implementation than Matlab's polyfit, but you do not ask for speed.

At first you need to construct the Vandermonde matrix. There are a lot of different algorithms to get it, and Google or WikiPedia know more details.

At second the least squares problem must be solved. V \ y with the Vandermonde matrix V and the y values is sufficient. A QR decomposition is more stable, so I suggest to try it and ask again in case or problems.

Be sure to use properly scaled inputs for x: A mean of 0 and a standard deviation of 1 is a fair choice to support the numerical stability of the algorithm. It is easy to consider the scaling afterwards.

0 Comments

Jan Simon

Contact us