Gauss Elimination with Partial Pivoting | Numerical Methods Lab
Numerical Methods - Gauss Elimination Method

Lab 3: Gauss Elimination Method with Partial Pivoting

Lab 3: Solution of System of Linear Equations using Gauss Elimination with Partial Pivoting

Experiment Information

Experiment: Solution of System of Linear Equations using Gauss Elimination with Partial Pivoting

Course Code: Numerical Methods (SH202)

Description: Complete lab report covering theory, algorithm, Python implementation and analysis of Gauss elimination method with partial pivoting

Complete Lab Report PDF

1. Theory of Gauss Elimination Method

1.1 Basic elimination process

1.2 Need for partial pivoting

1.3 Computational complexity analysis

2. Algorithm with Partial Pivoting

2.1 Forward elimination phase

2.2 Back substitution phase

2.3 Pivot selection strategy

3. Implementation

3.1 Python code with numpy

3.2 Input/output specifications

3.3 Handling singular matrices

4. Observations

4.1 Data recording table

4.2 Sample calculations

4.3 Effect of pivoting on solution

5. Results

5.1 Solution accuracy

5.2 Comparison with non-pivoting method

5.3 Error analysis

6. Discussion

6.1 Advantages of partial pivoting

6.2 Limitations of the method

6.3 Applications in engineering problems

Python Implementation of Gauss Elimination with Partial Pivoting

gauss_elimination.py
import numpy as np
from math import *

n=int(input("No. of Unknowns:"))
A=np.zeros((n,n+1),dtype=float)
print("Enter the elements row-wise:")
for i in range(n):
    rowData=input(f"Row{i+1}:").split()
    if len(rowData)!=(n+1):
        raise Exception("Error in row and column")
    A[i]=np.array(rowData,dtype=float)

n=A.shape[0]
for j in range(n-1):
    k=np.argmax(np.abs(A[j:,j]))+j
    if k!=j:
        A[[j,k]]=A[[k,j]]
    
    if abs(A[j,j])<5e-8:
          raise Exception("Error in Pivoting")
          

    for i in range(j+1,n):
        A[i]=A[i]-A[i,j]/A[j,j]*A[j]

print("After Pivoting:")
print(np.round(A,2))

x=np.zeros(n,dtype=float)
for i in range(n-1,-1,-1):
    x[i]=(A[i,n]-np.sum(A[i,i+1:n]*x[i+1:n]))/A[i,i]
    
print("Solution is:=",x)
        
×

Disclaimer

The educational materials provided on this website are intended as supplementary resources to support your learning journey. These lab reports are sample documents designed to help students understand proper formatting and content organization.

We have made every effort to ensure the accuracy of the content. However, we recommend students to perform their own experiments and prepare original reports. These samples should be used as references only.

We respect intellectual property rights. If you believe any content should be credited differently or removed, please don't hesitate to contact us. We're happy to make appropriate corrections or give proper attribution.

Leave a Comment

Scroll to Top