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

Matlab Program For Gauss Elimination Method With Partial Pivoting

The document presents the MATLAB code for solving systems of linear equations using Gauss elimination method with partial pivoting. It includes 5 problems - structural engineering equations, continuous beam equations, and portal frame equations. For each problem, it defines the coefficient matrix C and constant vector b, performs Gaussian elimination with partial pivoting on the augmented matrix [C b] to solve for the unknown variables.

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)
146 views6 pages

Matlab Program For Gauss Elimination Method With Partial Pivoting

The document presents the MATLAB code for solving systems of linear equations using Gauss elimination method with partial pivoting. It includes 5 problems - structural engineering equations, continuous beam equations, and portal frame equations. For each problem, it defines the coefficient matrix C and constant vector b, performs Gaussian elimination with partial pivoting on the augmented matrix [C b] to solve for the unknown variables.

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

(ii)Gauss Elimination Method with Partial pivoting MATLAB

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

clc
clear all
%Input matrix C
C = [0 4 -0.9;0 0.8 -0.9; 0.7 0.65 -1]
%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
%Partial pivoting
[big,k] =max(abs(A(i:n,i)));
kpr=k+i-1;
if kpr~=i
A([i,kpr],:)=A([kpr,i],:);
end
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:-
%MATLAB PROGRAM
%PROBLEM:-2 BY GAUSS ELEIMNINATION METHOD WITH PARTIAL PIVOTING
%Three equations of some structural engineering problem
%32F2 - 42.42F3 = 3000 .......eq(1)
%0.6F2 - 0.707F3 = 0 .......eq(2)
%0.8F1 - F2 + 0.707F3 = 100 .......eq(3)
%Let, x= matrix [F1; F2; F3]

clc
clear all
%Input matrix C
C = [0 32 -42.42;0 0.6 -0.707; 0.8 -1 0.707]
%Input matrix b as we know Cx = b
b= [3000 0 100]'
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
%Partial pivoting
[big,k] =max(abs(A(i:n,i)));
kpr=k+i-1;
if kpr~=i
A([i,kpr],:)=A([kpr,i],:);
end
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:-
%MATLAB PROGRAM
%PROBLEM:-3 BY GAUSS ELEIMNINATION METHOD WITH PARTIAL PIVOTING
%Two equations of continous 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
%Input matrix C
C = [72 180 ; 180 576 ]
%Input matrix b as we know Cx = b
b= [4765 12740]'
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
%Partial pivoting
[big,k] =max(abs(A(i:n,i)));
kpr=k+i-1;
if kpr~=i
A([i,kpr],:)=A([kpr,i],:);
end
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:-
%MATLAB PROGRAM
%PROBLEM:-4 BY GAUSS ELEIMNINATION METHOD WITH PARTIAL PIVOTING
%Two equations of continous 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
%Partial pivoting
[big,k] =max(abs(A(i:n,i)));
kpr=k+i-1;
if kpr~=i
A([i,kpr],:)=A([kpr,i],:);
end
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:-
%MATLAB PROGRAM
%PROBLEM:-5 BY GAUSS ELEIMNINATION METHOD WITH PARTIAL PIVOTING
%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
%Partial pivoting
[big,k] =max(abs(A(i:n,i)));
kpr=k+i-1;
if kpr~=i
A([i,kpr],:)=A([kpr,i],:);
end
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:-

You might also like