Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python gaussian elimination

import numpy as np
import sys
 
n = int(input('Enter number of unknowns: '))
a = np.zeros((n,n+1))
x = np.zeros(n)
print('Enter Augmented Matrix Coefficients:')
for i in range(n):
    for j in range(n+1):
        a[i][j] = float(input( 'a['+str(i)+']['+ str(j)+']='))
for i in range(n):
    if a[i][i] == 0.0:
        sys.exit('Divide 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]
 
print('
The solution is: ')
for i in range(n):
    print('X%d = %0.2f' %(i,x[i]), end = '	')
Comment

PREVIOUS NEXT
Code Example
Python :: how to create requirements.txt django 
Python :: python limit float to 2 decimal places 
Python :: implicit conversion in python example 
Python :: python new line command 
Python :: horizontal bar plot python 
Python :: python weekday 
Python :: move the mouse in games python 
Python :: What happens when you use the built-in function any() on a list? 
Python :: show all columns pandas jupyter notebook 
Python :: convert pandas column type 
Python :: how to read a text file from url in python 
Python :: Column names reading csv file python 
Python :: install from github 
Python :: multiple functions tkinter 
Python :: python csv 
Python :: matplotlib draw two histograms on same image 
Python :: python paramiko 
Python :: merge two df 
Python :: ipynb to py online 
Python :: How to find xpath by contained text 
Python :: how to check if a letter is lowercase in python 
Python :: how to add a cooment in python 
Python :: noninspection access to protected member 
Python :: add column in a specific position pandas 
Python :: linear congruential generator in python 
Python :: import django-on-heroku 
Python :: convert string to list python 
Python :: python yaml to dict 
Python :: How to convert simple string in to camel case in python 
Python :: check strings last letter python 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =