0% found this document useful (0 votes)
350 views6 pages

Matlab Program For Gauss Elimination Method

The document presents the code for solving systems of linear equations using Gauss elimination method in MATLAB. It provides 5 examples of using the Gauss elimination method to solve different systems of 2-3 equations with 2-3 unknowns arising in structural engineering problems. The code takes the augmented matrix as input, performs Gauss elimination to put the matrix in upper triangular form and then back substitution to calculate the values of the unknowns.

Uploaded by

Dinesh Jangra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
350 views6 pages

Matlab Program For Gauss Elimination Method

The document presents the code for solving systems of linear equations using Gauss elimination method in MATLAB. It provides 5 examples of using the Gauss elimination method to solve different systems of 2-3 equations with 2-3 unknowns arising in structural engineering problems. The code takes the augmented matrix as input, performs Gauss elimination to put the matrix in upper triangular form and then back substitution to calculate the values of the unknowns.

Uploaded by

Dinesh Jangra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

(i)Gauss Elimination Method MATLAB Program

%PROBLEM:-1 BY GAUSS ELEIMNINATION METHOD MATLAB PROGRAM


%Two equations of continuous beam where it is need to find Rb and Rc
%72Rb + 180Rc = 4765 .......eq(1)
%180Rb + 576Rc = 12740 .......eq(2)
%Let, x= matrix [Rb; Rc]

clc
clear all
C = [72 180 ; 180 576 ] %Input matrix C
b= [4765 12740]' %Input matrix b as we know Cx = b
A = [C b]; %Augmented Matrix
n= size(A,1); %number of equations/variables
[m, n] = size(C);
if m~=n,
error('Matrix C must be square');
end
x = zeros(n,1); %variable matrix [x1 x2 ... xn] coulmn
for i=1:n-1
for j=i+1:n
m = A(j,i)/A(i,i)
A(j,:) = A(j,:) - m*A(i,:)
end
end
x(n) = A(n,n+1)/A(n,n)
for i=n-1:-1:1
summ = 0
for j=i+1:n
summ = summ + A(i,j)*x(j,:)
x(i,:) = (A(i,n+1) - summ)/A(i,i)
end
end

OUTPUT:-
%PROBLEM:-2 BY GAUSS ELEIMNINATION METHOD MATLAB PROGRAM
%Two equations of continuous beam where it is need to find Rb and Rc
%333.33Rb + 833.33Rc = 40000 .......eq(1)
%833.33Rb + 2666.67Rc = -117500 .......eq(2)
%Let, x= matrix [Rb; Rc]

clc
clear all
%Input matrix C
C = [333.33 833.33 ; 833.33 2666.67 ]
%Input matrix b as we know Cx = b
b= [40000 -117500]'
A = [C b]; %Augmented Matrix
n= size(A,1); %number of equations/variables
[row, col] = size(C);
if row~=col,
error('Matrix C must be square');
end
x = zeros(n,1); %variable matrix [x1 x2 ... xn] coulmn
for i=1:n-1
for j=i+1:n
m = A(j,i)/A(i,i)
A(j,:) = A(j,:) - m*A(i,:)
end
end
x(n) = A(n,n+1)/A(n,n)
for i=n-1:-1:1
summ = 0
for j=i+1:n
summ = summ + A(i,j)*x(j,:)
x(i,:) = (A(i,n+1) - summ)/A(i,i)
end
end

OUTPUT:-
%PROBLEM:-3 BY GAUSS ELEIMNINATION METHOD MATLAB PROGRAM
%Three equations of portal where it is need to find Rd,Hd and Md
%101.33Rd + 34Hd - 28Md = -233.33 .......eq(1)
%34Rd + 56.67Hd - 19Md = -55 .......eq(2)
%-28Rd - 19Hd + 12Md = 60 .......eq(3)
%Let, x= matrix [Rd; Hd; Md]

clc
clear all
%Input matrix C
C = [101.33 34 -28; 34 56.67 -19; -28 -19 12]
%Input matrix b as we know Cx = b
b= [-233.33 -55 60]'
A = [C b]; %Augmented Matrix
n= size(A,1); %number of equations/variables
[row, col] = size(C);
if row~=col,
error('Matrix C must be square');
end
x = zeros(n,1); %variable matrix [x1 x2 ... xn] coulmn
for i=1:n-1
for j=i+1:n
m = A(j,i)/A(i,i)
A(j,:) = A(j,:) - m*A(i,:)
end
end
x(n) = A(n,n+1)/A(n,n)
for i=n-1:-1:1
summ = 0
for j=i+1:n
summ = summ + A(i,j)*x(j,:)
x(i,:) = (A(i,n+1) - summ)/A(i,i)
end
end

OUTPUT:-
%PROBLEM:-4 BY GAUSS ELEIMNINATION METHOD MATLAB PROGRAM
%Three equations of some structural engineering problem
%0.8F1 + 0.707F2 - F3 = 100 .......eq(1)
%0.6F1 - 0.707F2 = 0 .......eq(2)
%32F1 - 42.42F2 = 3000 .......eq(3)
%Let, x= matrix [F1; F2; F3]

clc
clear all
%Input matrix C
C = [0.8 0.707 -1; 0.6 -0.707 0; 32 -42.42 0]
%Input matrix b as we know Cx = b
b= [100 0 3000]'
A = [C b]; %Augmented Matrix
n= size(A,1); %number of equations/variables
[row, col] = size(C);
if row~=col,
error('Matrix C must be square');
end
x = zeros(n,1); %variable matrix [x1 x2 ... xn] coulmn
for i=1:n-1
for j=i+1:n
m = A(j,i)/A(i,i)
A(j,:) = A(j,:) - m*A(i,:)
end
end
x(n) = A(n,n+1)/A(n,n)
for i=n-1:-1:1
summ = 0
for j=i+1:n
summ = summ + A(i,j)*x(j,:)
x(i,:) = (A(i,n+1) - summ)/A(i,i)
end
end

OUTPUT:-
%PROBLEM:-5 BY GAUSS ELEIMNINATION METHOD MATLAB PROGRAM
%Three equations of some structural engineering problem
%0.7F1 + 0.65F2 - F3 = 20 .......eq(1)
%0.8F1 - 0.9F2 = 0 .......eq(2)
%4F1 - 0.9F2 = 110 .......eq(3)
%Let, x= matrix [F1; F2; F3]

clc
clear all
%Input matrix C
C = [0.7 0.65 -1; 0.8 -0.9 0; 4 -0.9 0]
%Input matrix b as we know Cx = b
b= [20 0 110]'
A = [C b]; %Augmented Matrix
n= size(A,1); %number of equations/variables
[row, col] = size(C);
if row~=col,
error('Matrix C must be square');
end
x = zeros(n,1); %variable matrix [x1 x2 ... xn] coulmn
for i=1:n-1
for j=i+1:n
m = A(j,i)/A(i,i)
A(j,:) = A(j,:) - m*A(i,:)
end
end
x(n) = A(n,n+1)/A(n,n)
for i=n-1:-1:1
summ = 0
for j=i+1:n
summ = summ + A(i,j)*x(j,:)
x(i,:) = (A(i,n+1) - summ)/A(i,i)
end
end

OUPUT:-

You might also like