-
Notifications
You must be signed in to change notification settings - Fork 1
/
linear_system_solver - Georgios_Koliou.py
127 lines (97 loc) · 3.03 KB
/
linear_system_solver - Georgios_Koliou.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python
# coding: utf-8
print("Author: Georgios Koliou\nContact: georgios.koliou@gmail.com\n")
D = str(input("\n\n Do you want to save this? Type Y for Yes or N for No: "))
if D == "Y":
F = str(input("\n(The file's name must be [name_file].doc -> Word file or [name_file].txt -> Text file): "))
file = open (F,"w")
else:
print("\nOk! Nothing to save!")
if D == "Y":
file.write("Author: Georgios Koliou\nContact: georgios.koliou@gmail.com\n\n")
else:
print("")
import numpy as np
R = int(input("\nGive number of rows: "))
C = int(input("\nGive number of columns: "))
if R == C:
print("\nInsert the elements of the matrix A separated by space: ")
numeri = list(map(int, input().split()))
elif D == 'Y':
file.close()
print("\n\nThe matrix is not square! It size is",R,"x",C,"\n\n")
input("Press ENTER to exit and delete the file")
import os
os.remove(F)
import sys
sys.exit("AGAIN")
else:
print("\n\nThe matrix is not square! It's siaze is",R,"x",C,"\n\n")
input("Press ENTER to exit")
import sys
sys.exit("AGAIN")
matrice = np.array(numeri).reshape(R, C)
print("\nThe matrix of the linear equations is:\n\n",matrice,)
if D == "Y":
file.write("\n\nThe matrix of the linear equations is:\n\n")
file.write(str(matrice))
else:
print("")
Rb = int(input("\nGive number of rows of column b:\n"))
if Rb == C:
print("\nInsert the elements of row b separated by space:\n")
elif D == 'Y':
file.close()
print("The number of rows of vector b must be equals with number of column of matrix A,",Rb,"is not equals to",C,)
input("Press ENTER to exit and delete the file")
import os
os.remove(F)
import sys
sys.exit("AGAIN")
else:
print("\n\nVector b has not the right size..\n\n")
input("Press ENTER to exit")
import sys
sys.exit("AGAIN")
b = list(map(int, input().split()))
bm = np.array(b).reshape(Rb,1)
print("\nVector b is equals to:\n\n",bm,)
if D == "Y":
file.write('\n\nVector b is equals to:\n\n')
file.write(str(bm))
else:
print("")
x = int(input("\nNumber of variables: "))
if x == R:
print("\nInsert variables separated by space: ")
elif D == 'Y':
file.close()
print("Number of variables is not right..")
input("Press ENTER to exit and delete the file")
import os
os.remove(F)
import sys
sys.exit("AGAIN")
else:
print("\n\nVector x has not the right size..\n\n")
input("Press ENTER to exit")
import sys
sys.exit("AGAIN")
var = list(map(str, input().split()))
var1 = np.array(var).reshape(x,1)
print("\nVector x is equals to:\n\n",var1,)
if D == "Y":
file.write('\n\nVector x is equals to:\n\n ')
file.write(str(var1))
else:
print("")
x = np.linalg.solve(matrice, bm)
sol = zip(var, x)
print("\nThe solutions of the Linear Equation System are:\n\n",list(sol),)
if D == "Y":
file.write('\n\nThe solutions of the Linear Equation System are:\n\n')
file.write(str(x))
file.close()
else:
print("")
input('\n\n\nPress ENTER to exit')