To write a program to find the solution of a matrix using Gaussian Elimination.
- Hardware โ PCs
- Anaconda โ Python 3.7 Installation / Moodle-Code Runner
Import the numpy module to use the built-in functions for calculation
Get input from the user for number of unknows as n
Making numpy array of n x n+1 size and initializing to zeroes for argumented matrix
Making numpy array of n size and initializig to zero for storing solution vector
Reading argumented matrix coefficients
Applying gauss elimination i.e., interchanging the rows and columns, multiplying them with a scalar and adding the rows with multiplied scalar
Applying back substitution
Displaying the solution
End of program
/*
Program to find the solution of a matrix using Gaussian Elimination.
Developed by: vignesh v
RegisterNumber:23002301
import numpy as np
import sys
n=int(input())
a=np.zeros((n,n+1))
x=np.zeros(n)
for i in range(n):
for j in range(n+1):
a[i][j] = float(input())
for i in range(n):
if a[i][i]==0.0:
sys.exit('Divided by zero detected')
for j in range(i+1,n):
ratio=a[j][i]/a[i][i]
for k in range(n+1):
a[j][k]=a[j][k] - ratio * a[i][k]
x[n-1]=a[n-1][n]/a[n-1][n-1]
for i in range(n-2,-1,-1):
x[i]=a[i][n]
for j in range (i+1,n):
x[i]=x[i]-a[i][j]*x[j]
x[i]=x[i]/a[i][i]
for i in range(n):
print('X%d = %0.2f' %(i,x[i]), end = ' ')
*/
![image](https://private-user-images.githubusercontent.com/110780412/290246309-523ebf54-6d83-4e0e-9f94-3fbf8c2dfb6a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjUyODI5NzIsIm5iZiI6MTcyNTI4MjY3MiwicGF0aCI6Ii8xMTA3ODA0MTIvMjkwMjQ2MzA5LTUyM2ViZjU0LTZkODMtNGUwZS05Zjk0LTNmYmY4YzJkZmI2YS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTAyJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkwMlQxMzExMTJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1iZWI2MjYwMGM4ZjYwZWRhN2E2MTg3M2Q4ODBlNDRkMzNkN2Y1MDM0NGViYzBlNTZlZTg1NTQxMmQ5OGY5NTk5JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.XTabWLlBv4yjoH-Q8NNkiKfbw3LHkeQ2hgGZmwS-v1U)
Thus the program to find the solution of a matrix using Gaussian Elimination is written and verified using python programming.