How do I correct the error "Matrix dimensions must agree"?

1 Ansicht (letzte 30 Tage)
Ryan
Ryan am 8 Jun. 2021
Kommentiert: Ryan am 9 Jun. 2021
I am using the following code, however, I keep getting a matrix dimensions must agree error. How would I correct this?
A = [1 0 0 0;1 0 1 0; 0 1 1 0; 0 1 0 1; 0 0 0 1];
b = [1; 3; 5; 7; 4];
x = [1; 3; 5; 7; 4];
N = 64;
theta = 3:3:180;
xLS = A\b;
k = [50,100,200,400,800];
X = kaczmarz(A,b,k);
e = zeros(length(k),1)
for i=1:length(k), e(i) = norm(x-X(:,i),inf); end
e
figure(2), semilogy(k,e)
e =
0
0
0
0
0
Matrix dimensions must agree.
  2 Kommentare
David Hill
David Hill am 8 Jun. 2021
Need to know the output of kaczmar()
Ryan
Ryan am 8 Jun. 2021
>> X = kaczmarz(A,b,k)
X =
1.0000 1.0000 1.0000 1.0000 1.0000
3.0000 3.0000 3.0000 3.0000 3.0000
2.0000 2.0000 2.0000 2.0000 2.0000
4.0000 4.0000 4.0000 4.0000 4.0000

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

David Hill
David Hill am 8 Jun. 2021
Bearbeitet: David Hill am 8 Jun. 2021
Your problem is with the norm() function. You cannot subtract at 4x1 vector from a 5x1. Maybe you ment:
for i=1:length(k), e(i) = norm(x'-X(i,:),inf); end

Weitere Antworten (0)

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by