MATLAB Answers

left side are not compatible with the size of the right side.

7 views (last 30 days)
Jia Hong Loh
Jia Hong Loh on 17 Oct 2020
Commented: Adam Danz on 17 Oct 2020
>> A=[-8,5,-2,0;-5,2,1,-2;10,-8,6,-3;3,-2,2,0];
>> b=[-29,-26,25,20];
>> cramer(4)
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Error in cramer (line 7)
B(:,i) = b;
This is my cramer function:
function cramer(n)
A=[];
b=[];
x=[];
for i=1:n
B=A;
B(:,i) = b;
xi=det(B)/det(A);
x=[x,xi];
end
disp(x)
end

Answers (1)

Adam Danz
Adam Danz on 17 Oct 2020
Your cramer function defines b as
b=[];
The loop within that function tries to store the empty value of b in B(:,i) which is of size [1x1] but b is of size [0,0] because it's empty.
B(:,i) = b;
That's why the error message reads,
Unable to perform assignment because the indices on the left side
are not compatible with the size of the right side.

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!