-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNM - Gausssiedel.py
28 lines (28 loc) · 960 Bytes
/
NM - Gausssiedel.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
print('General equation format : ax+by+cz=d')
a1=float(input('Enter value for a1 : '))
b1=float(input('Enter value for b1 : '))
c1=float(input('Enter value for c1 : '))
d1=float(input('Enter value for d1 : '))
a2=float(input('Enter value for a2 : '))
b2=float(input('Enter value for b2 : '))
c2=float(input('Enter value for c2 : '))
d2=float(input('Enter value for d2 : '))
a3=float(input('Enter value for a3 : '))
b3=float(input('Enter value for b3 : '))
c3=float(input('Enter value for c3 : '))
d3=float(input('Enter value for d3 : '))
prec=int(input('Enter precision : '))
x=y=z=0
xx=yy=zz=0
n=1
while True:
x=round((1/a1)*(d1-b1*y-c1*z), prec)
print('\nx', n, ' : ', x, sep='')
y=round((1/b2)*(d2-a2*x-c2*z), prec)
print('y', n, ' : ', y, sep='')
z=round((1/c3)*(d3-a3*x-b3*y), prec)
print('z', n, ' : ', z, sep='')
if ((x==xx) and (y==yy) and (z==zz)):
break
xx, yy, zz=x, y, z
n+=1