%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.

Antworten (1)

Star Strider
Star Strider am 8 Feb. 2018

0 Stimmen

Use the mldivide,\ (link) operator instead:
b = A\y;
b =
-19.1869e-003
21.2449e+000

2 Kommentare

Michelle Babak
Michelle Babak am 8 Feb. 2018
Thank you! Is it possible to use the least-squares formula though?
Star Strider
Star Strider am 8 Feb. 2018
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Linear Algebra finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 8 Feb. 2018

Kommentiert:

am 8 Feb. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by