How should i Implement a function that fits a line using least squares to the 2-D data points. It should output the two parameters of a line without using a toolbox for fitting the line. And i have to do this by doing regression

 Respuesta aceptada

the function polyfit(x,y,n) does what you need.
The MATLAB starter help example with n=1
x = linspace(0,1,5);
y = 1./(1+x);
p = polyfit(x,y,1);
x1 = linspace(0,2);
y1 = 1./(1+x1);
f1 = polyval(p,x1);
figure
plot(x,y,'o')
hold on
plot(x1,y1)
plot(x1,f1,'r--')
legend('y','y1','f1')
If you find this answer of any help solving your question, please click on the thumbs-up vote link,
thanks in advance
John

Más respuestas (0)

Etiquetas

Preguntada:

max
el 1 de Abr. de 2016

Comentada:

max
el 2 de Abr. de 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by