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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!