MATLAB: Error in linear regression with predefined error in y

errorfitlinear regression

I'm fitting y=ax+b with polyfit. x has no errors, but every component y_i has an error equal to error_i = C_i*y_i. (So this is correlated right?) How do I determine the error in the slope a?
I've been thinking about not using polyfit and minimazing S = sum(w_i * ( y_i – fit_i)^2) myself. With w_i = 1/error_i^2. But I have no idea how this minimizing can be done.

Best Answer

Take a look at the lscov function and see if it does what you need.