How to display answer for partial pivoting for Gauss Elimination method
5 views (last 30 days)
Show older comments
So i am trying to write a code that uses gauss elimiination method through partial pivoting,I was able to get my answers but wasnt sure on how to display my Upper triangular matrix(partial pivoting).Here is my code
A=[8 7 1 0;5 2 -2 2;2 5 1 -2;0 5 -3 1];
b=[22 12 8 5];
n = size(A,1); % Calculating number of equations
A(:,n+1)=b % Creating the augmented matrix
A0 = A
% Elimination process starts
for i = 1:n-1
p = i
% Comparison to select the pivot
for j = i+1:n
if abs(A0(j,i)) > abs(A0(i,i))
U = A0(i,:)
A0(i,:) = A0(j,:)
A0(j,:) = U
end
end
% Cheking for nullity of the pivots
while (A0(p,i)== 0 && p <= n)
p = p+1
end
if p == n+1
disp('No unique solution');
break
else
if p ~= i
T = A0(i,:)
A0(i,:) = A0(p,:)
A0(p,:) = T
end
end
for j = i+1:n
m = A0(j,i)/A0(i,i)
for k = i+1:n+1
A0(j,k) = A0(j,k) - m*A0(i,k)
end
end
end
disp(A0)
x(n) = A0(n,n+1)/A0(n,n)
for i = n - 1:-1:1
sumax = 0
for j = i+1:n
sumax = sumax + A0(i,j)*x(j)
end
x(i) = (A0(i,n+1) - sumax)/A0(i,i)
end
0 Comments
Answers (1)
Sai Sumanth Korthiwada
on 20 Dec 2022
Hi Idris,
I understand that you are trying to display the upper triangular matrix using partial pivoting with Guass elimination method.
Please go through the following MATLAB Answer Accepted answer to know how 'Upper triangular matrix' is being displayed:
Hope this helps resolves your query.
0 Comments
See Also
Categories
Find more on Numerical Integration and Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!