dimensions of array being concatenated are not consistent

2 visualizaciones (últimos 30 días)
Caleb
Caleb el 7 de Oct. de 2023
Editada: Torsten el 7 de Oct. de 2023
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

Respuestas (1)

Torsten
Torsten el 7 de Oct. de 2023
Editada: Torsten el 7 de Oct. de 2023
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 ?

Categorías

Más información sobre Tables en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by