0% found this document useful (0 votes)
25 views1 page

Guasselimination

The document describes a Guass elimination program to solve systems of linear equations. It contains the code for the program which takes a coefficient matrix and constant matrix as input and outputs the solved matrix. It also shows an example run of the program and compares the output to using matrix inverse to solve.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views1 page

Guasselimination

The document describes a Guass elimination program to solve systems of linear equations. It contains the code for the program which takes a coefficient matrix and constant matrix as input and outputs the solved matrix. It also shows an example run of the program and compares the output to using matrix inverse to solve.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Name = Gaikwad Satish Balu

Roll no. = 146


Guass elimination Program

clc
clear all ;
%% creating a Matrix
A = input ( ' Enter the coefficient matrix ');
B = input ( ' Enter the constant matrix ');
N = length ( B ) ;
X = zeros ( N , 1 );

%% creating matrix with all lower diagonal elements as zero


Aug = [ A B ];
for j = 1: N -1
for i = j+1:N
m = Aug ( i , j ) / Aug ( j , j );
Aug ( i , : ) = Aug ( i , : ) - m * Aug ( j , : );
end
end
Aug
%% Back substitution
X (N) = Aug ( N , N+1 )/ Aug ( N , N );
for K = N-1 : -1 : 1
X ( K ) = (Aug ( K , N+1 ) - Aug( K , K+1: N )* X ( K+1 : N )) / Aug ( K ,
K );

end
--------------------------------------------------------------------

OUTPUT
Enter the coefficient matrix [1 3 5 ; 3 2 4 ; 2 1 1 ]
Enter the constant matrix [ 2 ; 7 ; 4 ]

Aug =

1.0000 3.0000 5.0000 2.0000


0 -7.0000 -11.0000 1.0000
0 0 -1.1429 -0.7143

X =

2.2500
-1.1250
0.6250

----------------------------------------------------------------------
SOLVER
>> A = [1 3 5 ; 3 2 4 ; 2 1 1 ];
>> B = [ 2 ; 7 ; 4 ] ;
>> X = inv ( A ) * ( B )

X =

2.2500
-1.1250
0.625

You might also like