Created
February 14, 2016 14:46
-
-
Save hiagop/2623a2a0ce41957ae099 to your computer and use it in GitHub Desktop.
Simple Linear Systems solver in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import numpy as num | |
# cont = True | |
print('***Linear System solver***\n') | |
print('Insert the coeficient matrix like this:\n \ | |
|a1||b1||c1| \n \ | |
|a2||b2||c2| \n \ | |
|a3||b3||c3| \n') | |
A = num.array([list(map(float, input('Insert coeficient matrix line: ').split(' ')))]) | |
cont = True if (input('More lines? (y or n): ') == 'y') else False | |
while cont: | |
A = num.append(A, [list(map(float, input('Insert coeficient matrix line: ').split(' ')))], axis = 0) | |
cont = True if (input('More lines? (y or n): ') == 'y') else False | |
else: | |
print(A) | |
b = list(map(float, input('Insert results array: ').split(' '))) | |
x = num.linalg.solve(A, b) | |
# print(x) | |
j = 1 | |
for i in x: | |
print('x' + str(j) + ': '+ str(i) +'\n') | |
j = j + 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment