dimensions of array being concatenated are not consistent

1 次查看(过去 30 天)
R = 0.6:0.05:0.95; %Recycle ratio
l = length(R);
X(2,l) = 0;
for k = 1:l
A = [(2 - 1.5)*R(k) -0.5*R(k); k -k];
b = [779.3-780*R; 76];
% Gaussian elimination with partial pivoting
[n, m] = size(A);
Ab = [A, b];
% Forward elimination
for i = 1:n
[m, max_row] = max(abs(Ab(i:end, i)));
max_row = max_row + i - 1;
Ab([i, max_row], :) = Ab([max_row, i], :);
for j = i+1:n
factor = Ab(j, i) / Ab(i, i);
Ab(j, i:end) = Ab(j, i:end) - factor * Ab(i, i:end);
end
end
% Backward substitution
x = zeros(n, 1);
for i = n:-1:1
x(i) = (Ab(i, end) - Ab(i, i+1:end-1) * x(i+1:end)) / Ab(i, i);
end
% Store the solution in X
X(:,k) = x;
end

回答(1 个)

Torsten
Torsten 2023-10-7
编辑:Torsten 2023-10-7
b = [779.3-780*R(k); 76];
instead of
b = [779.3-780*R; 76];
But why do you use such a complicated code for 2x2 linear systems of equations ?

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by