left side are not compatible with the size of the right side.
1 次查看(过去 30 天)
显示 更早的评论
>> 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
2 个评论
回答(1 个)
Adam Danz
2020-10-17
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!