Least squares matrix?
古いコメントを表示
%Constants NumRocks=[1608 1277 1025 851 726 438 102 53 9 5 1]; %Number of rockfalls vector Vol=[0.01 0.02 0.03 0.04 0.05 0.1 0.5 1 5 10 100]; %Volume in meters cubed
%Least Squares Method A=[NumRocks',ones(11,1)]; y=Vol'; b=[inv(A.*A').*A'.*y]
Getting error: Matrix dimensions must agree.
回答 (1 件)
Star Strider
2018 年 2 月 8 日
b = A\y;
b =
-19.1869e-003
21.2449e+000
2 件のコメント
Michelle Babak
2018 年 2 月 8 日
Star Strider
2018 年 2 月 8 日
My pleasure!
The mldivide function solves the equation in the least-squares sense.
You have the correct idea, however the derivation requires matrix operations, not element-wise operations. (You also have the order of the matrix and its transpose reversed.)
This works:
b = (A'*A)\A'*y
giving the same result as posted earlier.
It is more efficient and accurate to use this version than to use:
b = inv(A'*A)*A'*y
that again gives the same result.
カテゴリ
ヘルプ センター および File Exchange で Linear Algebra についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!