Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

Step by step output of Gauss Jordan in MatLab | Reduced Echelon form of Augmented matrix in MatLab

Solve the system of equations with Gauss Jordan elimination method in MATLAB. You do not need any MATLAB programing knowledge(or any programing language ) to program it, as I have provided the MATLAB code. 
How to use MATLAB to generate result is discussed in the tutorial in most easy manner. 
You can solve any size and type  (No. of array + No. of equations) of system of equation with the program, as it is made for general purpose.

%Code 


clear all;

clc;

format rat

disp('        Solving system of equations using')

disp('               Gauss Jorden Method')

disp('          In this method we convert the ')

disp('     Augmented matrix in reduced echenlon form')

disp('')

A=input('Enter the augmented matrix\n = ');

 

r=length(A(:,1));

c=length(A(1,:));

 

disp('Farward phase')

 

for i=1:r

       

    f=0;

    l=i;

    if A(i,i) ~= 1

        for m=i+1:r

            if A(m,i) == 1

                 B=A(i,:);

                 A(i,:)=A(m,:);

                 fprintf ('Swaping R%.f with R%.f.\n',m,i)

                 A(m,:)=B;

                 disp(A)

                 break;

            end

        end

    end

   

    if A(i,i)== 0

   

        for k=i+1:r

            if A(k,i)~= 0

                B=A(i,:);

                A(i,:)=A(k,:);

                fprintf ('Swaping R%.f with R%.f.\n',k,i)

                 A(k,:)= B;

                 diso(A);

                d=A(i,i);

                f=1;

            break;

            end

        end

       

        if f == 0

            for l=i+1:c-1

                if A(i,l) ~= 0

                    d=A(i,l);

                    f=1;

                break;

                end

            end

        end

       

    else

        d=A(i,i);

        f=1;

    end

   

   if f ~= 0

        if d~=1

            fprintf('R%.f / (%s) \n',i,rats(d))

            A(i,:)=A(i,:)/d ;

            disp(A);

        end

        for j=i+1:r

            if A(j,l)== 0

                continue;

            end

            fprintf('R%.f-  (%s)*R%.f \n',j,rats(A(j,l)),i)

            A(j,:)=A(j,:) - A(j,l)*A(i,:);

            disp(A)

        end

   end

  

end

disp('')

disp('Reverse phase')

fg=0;

for i=r:-1:1

    f=0;

     l=i;

     if A(i,i)== 0

        for l=i+1:c-1

            if A(i,l) ~= 0

                d=A(i,l);

                  f=1;

                break;

            end

        end

               

    else

        d=A(i,i);

        f=1;

    end

   

   if f ~= 0

        for j=i-1:-1:1

            if A(j,i)== 0

                continue;

            end

            fprintf('R%.f-  (%s)*R%.f \n',j,rats(A(j,i)),i)

            A(j,:)=A(j,:) - A(j,l)*A(i,:) ;

            disp(A);

            fg=1;

        end

   end

   if ( (f==0 && A(i,c)) == 1 || fg==0 && i==1)

       disp('No solution')   

       break;

   end

 

end

 

 




Join us on Telegram: https://t.me/matlabcastor

No comments

Popular Posts

Followers