Sum of Least Squares
Ältere Kommentare anzeigen
I have a table, Check, where I would like to subtract column 6 from column 5 (to obtain a residual) and then square the residual. Then for all of the rows I would like to sum the squares of the residuals. Since MATLAB is supposed to be able to handle working with matrices and arrays much better than say visual basic, it seems I should be able to do this with one or two lines of codes. Maybe something like:
Check(:,7) = (Check(:,5) - Check(:,6))^2
SumofSquares = sum(Check(:,7)
1 Kommentar
Mathieu NOE
am 4 Okt. 2021
hi
you can do in one line .
SumofSquares = sum((Check(:,5) - Check(:,6)).^2);
Akzeptierte Antwort
Weitere Antworten (1)
John
am 31 Jul. 2023
0 Stimmen
xi = [1491214 17];
yi = [-3.97, 5.18, 20.43, 29.58, 35.68, 44.83];
n = length(xi);
A = [n sum(xi); sum(xi) sum(xi.^2)];
C = [sum(yi); sum(xi.*yi)];
Z = A\C;
a =Z(1);
b = Z(2);
fprintf ('y = %.5f + %.5f x \n',a,b)
Kategorien
Mehr zu Cast and Quantize Data finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!