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
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Algebra에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!