BetaCodeShareBeta

by Code Solutions Project

Simple solutions for common problems

Description:Realiza reducción gaussiana recursivamente
Matlab
JoseluCross
function [Y] = gaussRecursivo( A )
%Gauss Recursivo
%   Genera una matriz expandida
%   triangular superior al aplicarse Gauss de manera recursiva
    dim = size(A);
    if dim(1) ~= 1
       for i =2:dim(1)
           if A(1,1) == 0
               disp('Se ha necesita pivotaje parcial');
               mayor=0;
               index=0;
               for j = 1:dim(1)
                   if A(1,j) > mayor
                       index=j;
                       mayor = A(1,j);
                   end
               end
               S = A(1,:);
               T = A(index,:);
               A(index,:) = S;
               A(1,:) = T;
           end
           mul = A(i,1)/A(1,1);
           A(i,:) = A(i,:) - mul*A(1,:);
       end
       B = A(2:dim(1),2:dim(2));
       B = gaussRecursivo(B);
       C = [zeros(dim(1)-1,1),B];
       Y = [A(1,:);C];
    else
       Y=A;
    end
end

Input example

[8 4 3; 4 8 6; 1 -2 4]

Output example

[8.0000 4.0000 3.0000 ; 0 6.0000 4.5000; 0 0 5.5000]
×Oh snap! Something wrong