Curve Fitting using normal equations formulation of least squares
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MATLABhelp
am 23 Jan. 2019
Kommentiert: Dr. Bhavya
am 18 Sep. 2024
I am given an data table with values of x and y and supposed to approximate the relationship between x and y with a straight line y = a0 + a1*x. I must find the parameters using normal equations formulation of least squares. I have begun, but am unsure how to plot the curve?
My code is the following:
x = [20 40 60 80 100 120 140 160];
y = [13 22 30 36 40 43 45 46];
% Normal equations formulation of least squares
A = [ones(size(x)) x];
b = inv(A'*A)*(A'*y);
1 Kommentar
Akzeptierte Antwort
Matt J
am 23 Jan. 2019
x = [20 40 60 80 100 120 140 160].';
y = [13 22 30 36 40 43 45 46].';
% Normal equations formulation of least squares
A = [ones(size(x)) x];
yfit = A*((A'*A)\(A'*y));
plot(x,y,'*',x,yfit,'-')
0 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!