Linear regression using least square method & VARARGIN
Afficher commentaires plus anciens
Hello,
As I specified, I have to solve a linear regression using least square method. I did it in the "classical" way using numbers given by me (for parameters). After my teacher evaluated it, he recommended me to make a function that will generate random parameters using varargin..To be honest, I don't know how varargin works and I don't know how to re-do the exercise in the way that my teacher wants..Any help will be very appreciated. Thank you!
%Linear regression using least square method
x=[1:10];
y=4.*x+5;
y=y+randn(size(y)); % Measurment of y with errors (random)
A=x-mean(x);
B=A.^2;
C=(x-mean(x)).*(y-mean(y));
a=sum(C)./sum(B);
b=-mean(x).*coef1+mean(y);
y1=a*x+b;
plot(x,y1,x,y,'o')
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Linear Regression dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!